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 cmd
} }
#[test] mod basic {
fn can_print_simple_ascii_file() { use super::hexyl;
#[test]
fn can_print_simple_ascii_file() {
hexyl() hexyl()
.arg("ascii") .arg("ascii")
.arg("--color=never") .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\ │00000000│ 61 62 63 64 65 66 67 68 ┊ 21 3f 25 26 2f 28 29 0a │abcdefgh┊!?%&/()_│\n\
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n", └────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n",
); );
} }
#[test] #[test]
fn can_read_input_from_stdin() { fn can_read_input_from_stdin() {
hexyl() hexyl()
.arg("--color=never") .arg("--color=never")
.write_stdin("abc") .write_stdin("abc")
@@ -32,15 +35,33 @@ fn can_read_input_from_stdin() {
│00000000│ 61 62 63 ┊ │abc ┊ │\n\ │00000000│ 61 62 63 ┊ │abc ┊ │\n\
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n", └────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n",
); );
} }
#[test] #[test]
fn fails_on_non_existing_input() { fn fails_on_non_existing_input() {
hexyl().arg("non-existing").assert().failure(); 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] mod length {
fn length_restricts_output_size() { use super::hexyl;
#[test]
fn length_restricts_output_size() {
hexyl() hexyl()
.arg("hello_world_elf64") .arg("hello_world_elf64")
.arg("--color=never") .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\ │00000010│ 02 00 3e 00 01 00 00 00 ┊ 00 10 40 00 00 00 00 00 │•0>0•000┊0•@00000│\n\
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n", └────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n",
); );
} }
#[test] #[test]
fn prints_warning_on_empty_content() { fn fail_if_length_and_bytes_options_are_used_simultaneously() {
hexyl() hexyl()
.arg("empty") .arg("hello_world_elf64")
.arg("--color=never") .arg("--length=32")
.arg("--bytes=10")
.assert() .assert()
.success() .failure();
.stdout( }
"┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐\n\
│ │ No content to print │ │ │ │\n\
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n",
);
} }
#[test] mod skip {
fn prints_warning_when_skipping_past_the_end() { use super::hexyl;
#[test]
fn prints_warning_when_skipping_past_the_end() {
hexyl() hexyl()
.arg("ascii") .arg("ascii")
.arg("--color=never") .arg("--color=never")
@@ -82,20 +103,26 @@ fn prints_warning_when_skipping_past_the_end() {
│ │ No content to print │ │ │ │\n\ │ │ No content to print │ │ │ │\n\
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n", └────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n",
); );
} }
#[test] #[test]
fn can_handle_negative_skip_arguments() { fn can_handle_negative_arguments() {
hexyl() hexyl()
.arg("hello_world_elf64") .arg("ascii")
.arg("--color=never") .arg("--color=never")
.arg("--skip=-1KiB") .arg("--skip=2")
.arg("--length=4")
.assert() .assert()
.success(); .success()
} .stdout(
"┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐\n\
│00000002│ 63 64 65 66 ┊ │cdef ┊ │\n\
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n",
);
}
#[test] #[test]
fn fails_if_negative_offset_is_too_large() { fn fails_if_negative_offset_is_too_large() {
hexyl() hexyl()
.arg("hello_world_elf64") .arg("hello_world_elf64")
.arg("--color=never") .arg("--color=never")
@@ -103,20 +130,14 @@ fn fails_if_negative_offset_is_too_large() {
.assert() .assert()
.failure() .failure()
.stderr(predicates::str::contains("Failed to jump")); .stderr(predicates::str::contains("Failed to jump"));
}
} }
#[test] mod display_offset {
fn fail_if_length_and_bytes_options_are_used_simultaneously() { use super::hexyl;
hexyl()
.arg("hello_world_elf64")
.arg("--length=32")
.arg("--bytes=10")
.assert()
.failure();
}
#[test] #[test]
fn display_offset() { fn basic() {
hexyl() hexyl()
.arg("ascii") .arg("ascii")
.arg("--color=never") .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\ │00c0ffee│ 61 62 63 64 65 66 67 68 ┊ 21 3f 25 26 2f 28 29 0a │abcdefgh┊!?%&/()_│\n\
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n", └────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n",
); );
} }
#[test] #[test]
fn display_offset_and_skip() { fn display_offset_and_skip() {
hexyl() hexyl()
.arg("hello_world_elf64") .arg("hello_world_elf64")
.arg("--color=never") .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\ │00000030│ 02 00 3e 00 01 00 00 00 ┊ 00 10 40 00 00 00 00 00 │•0>0•000┊0•@00000│\n\
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n", └────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n",
); );
}
} }
#[test] mod blocksize {
fn fails_for_zero_or_negative_blocksize() { use super::hexyl;
#[test]
fn fails_for_zero_or_negative_blocksize() {
hexyl() hexyl()
.arg("ascii") .arg("ascii")
.arg("--block-size=0") .arg("--block-size=0")
@@ -160,4 +185,5 @@ fn fails_for_zero_or_negative_blocksize() {
.arg("--block-size=-16") .arg("--block-size=-16")
.assert() .assert()
.failure(); .failure();
}
} }