Organize integration tests into modules

This commit is contained in:
sharkdp authored and David Peter committed 2020-11-01 22:56:59 +01:00
1 parent 8c3f2230c6
commit 1db77094da
1 file changed
+74 -48
+74 -48
View File
@@ -6,8 +6,11 @@ fn hexyl() -> Command {
cmd
}
#[test]
fn can_print_simple_ascii_file() {
mod basic {
use super::hexyl;
#[test]
fn can_print_simple_ascii_file() {
hexyl()
.arg("ascii")
.arg("--color=never")
@@ -18,10 +21,10 @@ fn can_print_simple_ascii_file() {
│00000000│ 61 62 63 64 65 66 67 68 ┊ 21 3f 25 26 2f 28 29 0a │abcdefgh┊!?%&/()_│\n\
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n",
);
}
}
#[test]
fn can_read_input_from_stdin() {
#[test]
fn can_read_input_from_stdin() {
hexyl()
.arg("--color=never")
.write_stdin("abc")
@@ -32,15 +35,33 @@ fn can_read_input_from_stdin() {
│00000000│ 61 62 63 ┊ │abc ┊ │\n\
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n",
);
}
}
#[test]
fn fails_on_non_existing_input() {
#[test]
fn fails_on_non_existing_input() {
hexyl().arg("non-existing").assert().failure();
}
#[test]
fn prints_warning_on_empty_content() {
hexyl()
.arg("empty")
.arg("--color=never")
.assert()
.success()
.stdout(
"┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐\n\
│ │ No content to print │ │ │ │\n\
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n",
);
}
}
#[test]
fn length_restricts_output_size() {
mod length {
use super::hexyl;
#[test]
fn length_restricts_output_size() {
hexyl()
.arg("hello_world_elf64")
.arg("--color=never")
@@ -53,24 +74,24 @@ fn length_restricts_output_size() {
│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 prints_warning_on_empty_content() {
#[test]
fn fail_if_length_and_bytes_options_are_used_simultaneously() {
hexyl()
.arg("empty")
.arg("--color=never")
.arg("hello_world_elf64")
.arg("--length=32")
.arg("--bytes=10")
.assert()
.success()
.stdout(
"┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐\n\
│ │ No content to print │ │ │ │\n\
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n",
);
.failure();
}
}
#[test]
fn prints_warning_when_skipping_past_the_end() {
mod skip {
use super::hexyl;
#[test]
fn prints_warning_when_skipping_past_the_end() {
hexyl()
.arg("ascii")
.arg("--color=never")
@@ -82,20 +103,26 @@ fn prints_warning_when_skipping_past_the_end() {
│ │ No content to print │ │ │ │\n\
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n",
);
}
}
#[test]
fn can_handle_negative_skip_arguments() {
#[test]
fn can_handle_negative_arguments() {
hexyl()
.arg("hello_world_elf64")
.arg("ascii")
.arg("--color=never")
.arg("--skip=-1KiB")
.arg("--skip=2")
.arg("--length=4")
.assert()
.success();
}
.success()
.stdout(
"┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐\n\
│00000002│ 63 64 65 66 ┊ │cdef ┊ │\n\
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n",
);
}
#[test]
fn fails_if_negative_offset_is_too_large() {
#[test]
fn fails_if_negative_offset_is_too_large() {
hexyl()
.arg("hello_world_elf64")
.arg("--color=never")
@@ -103,20 +130,14 @@ fn fails_if_negative_offset_is_too_large() {
.assert()
.failure()
.stderr(predicates::str::contains("Failed to jump"));
}
}
#[test]
fn fail_if_length_and_bytes_options_are_used_simultaneously() {
hexyl()
.arg("hello_world_elf64")
.arg("--length=32")
.arg("--bytes=10")
.assert()
.failure();
}
mod display_offset {
use super::hexyl;
#[test]
fn display_offset() {
#[test]
fn basic() {
hexyl()
.arg("ascii")
.arg("--color=never")
@@ -128,10 +149,10 @@ fn display_offset() {
│00c0ffee│ 61 62 63 64 65 66 67 68 ┊ 21 3f 25 26 2f 28 29 0a │abcdefgh┊!?%&/()_│\n\
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n",
);
}
}
#[test]
fn display_offset_and_skip() {
#[test]
fn display_offset_and_skip() {
hexyl()
.arg("hello_world_elf64")
.arg("--color=never")
@@ -145,10 +166,14 @@ fn display_offset_and_skip() {
│00000030│ 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 fails_for_zero_or_negative_blocksize() {
mod blocksize {
use super::hexyl;
#[test]
fn fails_for_zero_or_negative_blocksize() {
hexyl()
.arg("ascii")
.arg("--block-size=0")
@@ -160,4 +185,5 @@ fn fails_for_zero_or_negative_blocksize() {
.arg("--block-size=-16")
.assert()
.failure();
}
}