Skip to content

Commit

Permalink
Add test for --length, fix #105
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkdp committed Oct 30, 2020
1 parent 09c22e0 commit bb6a3c0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/bin/hexyl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ fn run() -> Result<(), AnyhowError> {
.long("bytes")
.takes_value(true)
.value_name("N")
.conflicts_with("length")
.help("An alias for -n/--length"),
)
.arg(
Expand Down
Binary file added tests/examples/hello_world_elf64
Binary file not shown.
26 changes: 26 additions & 0 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,32 @@ fn fails_on_non_existing_input() {
hexyl().arg("non-existing").assert().failure();
}

#[test]
fn length_restricts_output_size() {
hexyl()
.arg("hello_world_elf64")
.arg("--color=never")
.arg("--length=32")
.assert()
.success()
.stdout(
"┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐\n\
│00000000│ 7f 45 4c 46 02 01 01 00 ┊ 00 00 00 00 00 00 00 00 │•ELF•••0┊00000000│\n\
│00000010│ 02 00 3e 00 01 00 00 00 ┊ 00 10 40 00 00 00 00 00 │•0>0•000┊0•@00000│\n\
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n",
);
}

#[test]
fn fail_if_length_and_bytes_options_are_used_simultaneously() {
hexyl()
.arg("hello_world_elf64")
.arg("--length=32")
.arg("--bytes=10")
.assert()
.failure();
}

#[test]
fn display_offset() {
hexyl()
Expand Down

0 comments on commit bb6a3c0

Please sign in to comment.