1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

tests: take slices in stdout_is_fixture

This commit is contained in:
Michael Debertol 2021-06-11 22:00:26 +02:00
parent 440eba628c
commit 8e7eedebe7
2 changed files with 31 additions and 103 deletions

View file

@ -33,10 +33,7 @@ fn test_without_any_options() {
scenario scenario
.args(&[test_file_path]) .args(&[test_file_path])
.succeeds() .succeeds()
.stdout_is_templated_fixture( .stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]);
expected_test_file_path,
vec![(&"{last_modified_time}".to_string(), &value)],
);
} }
#[test] #[test]
@ -48,10 +45,7 @@ fn test_with_numbering_option_with_number_width() {
scenario scenario
.args(&["-n", "2", test_file_path]) .args(&["-n", "2", test_file_path])
.succeeds() .succeeds()
.stdout_is_templated_fixture( .stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]);
expected_test_file_path,
vec![(&"{last_modified_time}".to_string(), &value)],
);
} }
#[test] #[test]
@ -66,10 +60,7 @@ fn test_with_long_header_option() {
.succeeds() .succeeds()
.stdout_is_templated_fixture( .stdout_is_templated_fixture(
expected_test_file_path, expected_test_file_path,
vec![ &[("{last_modified_time}", &value), ("{header}", header)],
(&"{last_modified_time}".to_string(), &value),
(&"{header}".to_string(), &header.to_string()),
],
); );
new_ucmd!() new_ucmd!()
@ -77,10 +68,7 @@ fn test_with_long_header_option() {
.succeeds() .succeeds()
.stdout_is_templated_fixture( .stdout_is_templated_fixture(
expected_test_file_path, expected_test_file_path,
vec![ &[("{last_modified_time}", &value), ("{header}", header)],
(&"{last_modified_time}".to_string(), &value),
(&"{header}".to_string(), &header.to_string()),
],
); );
} }
@ -93,18 +81,12 @@ fn test_with_double_space_option() {
scenario scenario
.args(&["-d", test_file_path]) .args(&["-d", test_file_path])
.succeeds() .succeeds()
.stdout_is_templated_fixture( .stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]);
expected_test_file_path,
vec![(&"{last_modified_time}".to_string(), &value)],
);
new_ucmd!() new_ucmd!()
.args(&["--double-space", test_file_path]) .args(&["--double-space", test_file_path])
.succeeds() .succeeds()
.stdout_is_templated_fixture( .stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]);
expected_test_file_path,
vec![(&"{last_modified_time}".to_string(), &value)],
);
} }
#[test] #[test]
@ -116,10 +98,7 @@ fn test_with_first_line_number_option() {
scenario scenario
.args(&["-N", "5", "-n", test_file_path]) .args(&["-N", "5", "-n", test_file_path])
.succeeds() .succeeds()
.stdout_is_templated_fixture( .stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]);
expected_test_file_path,
vec![(&"{last_modified_time}".to_string(), &value)],
);
} }
#[test] #[test]
@ -131,10 +110,7 @@ fn test_with_first_line_number_long_option() {
scenario scenario
.args(&["--first-line-number=5", "-n", test_file_path]) .args(&["--first-line-number=5", "-n", test_file_path])
.succeeds() .succeeds()
.stdout_is_templated_fixture( .stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]);
expected_test_file_path,
vec![(&"{last_modified_time}".to_string(), &value)],
);
} }
#[test] #[test]
@ -146,10 +122,7 @@ fn test_with_number_option_with_custom_separator_char() {
scenario scenario
.args(&["-nc", test_file_path]) .args(&["-nc", test_file_path])
.succeeds() .succeeds()
.stdout_is_templated_fixture( .stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]);
expected_test_file_path,
vec![(&"{last_modified_time}".to_string(), &value)],
);
} }
#[test] #[test]
@ -161,10 +134,7 @@ fn test_with_number_option_with_custom_separator_char_and_width() {
scenario scenario
.args(&["-nc1", test_file_path]) .args(&["-nc1", test_file_path])
.succeeds() .succeeds()
.stdout_is_templated_fixture( .stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]);
expected_test_file_path,
vec![(&"{last_modified_time}".to_string(), &value)],
);
} }
#[test] #[test]
@ -207,25 +177,19 @@ fn test_with_page_range() {
scenario scenario
.args(&["--pages=15", test_file_path]) .args(&["--pages=15", test_file_path])
.succeeds() .succeeds()
.stdout_is_templated_fixture( .stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]);
expected_test_file_path,
vec![(&"{last_modified_time}".to_string(), &value)],
);
new_ucmd!() new_ucmd!()
.args(&["+15", test_file_path]) .args(&["+15", test_file_path])
.succeeds() .succeeds()
.stdout_is_templated_fixture( .stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]);
expected_test_file_path,
vec![(&"{last_modified_time}".to_string(), &value)],
);
new_ucmd!() new_ucmd!()
.args(&["--pages=15:17", test_file_path]) .args(&["--pages=15:17", test_file_path])
.succeeds() .succeeds()
.stdout_is_templated_fixture( .stdout_is_templated_fixture(
expected_test_file_path1, expected_test_file_path1,
vec![(&"{last_modified_time}".to_string(), &value)], &[("{last_modified_time}", &value)],
); );
new_ucmd!() new_ucmd!()
@ -233,7 +197,7 @@ fn test_with_page_range() {
.succeeds() .succeeds()
.stdout_is_templated_fixture( .stdout_is_templated_fixture(
expected_test_file_path1, expected_test_file_path1,
vec![(&"{last_modified_time}".to_string(), &value)], &[("{last_modified_time}", &value)],
); );
} }
@ -246,10 +210,7 @@ fn test_with_no_header_trailer_option() {
scenario scenario
.args(&["-t", test_file_path]) .args(&["-t", test_file_path])
.succeeds() .succeeds()
.stdout_is_templated_fixture( .stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]);
expected_test_file_path,
vec![(&"{last_modified_time}".to_string(), &value)],
);
} }
#[test] #[test]
@ -262,10 +223,7 @@ fn test_with_page_length_option() {
scenario scenario
.args(&["--pages=2:3", "-l", "100", "-n", test_file_path]) .args(&["--pages=2:3", "-l", "100", "-n", test_file_path])
.succeeds() .succeeds()
.stdout_is_templated_fixture( .stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]);
expected_test_file_path,
vec![(&"{last_modified_time}".to_string(), &value)],
);
new_ucmd!() new_ucmd!()
.args(&["--pages=2:3", "-l", "5", "-n", test_file_path]) .args(&["--pages=2:3", "-l", "5", "-n", test_file_path])
@ -293,10 +251,7 @@ fn test_with_stdin() {
.pipe_in_fixture("stdin.log") .pipe_in_fixture("stdin.log")
.args(&["--pages=1:2", "-n", "-"]) .args(&["--pages=1:2", "-n", "-"])
.run() .run()
.stdout_is_templated_fixture( .stdout_is_templated_fixture(expected_file_path, &[("{last_modified_time}", &now)]);
expected_file_path,
vec![(&"{last_modified_time}".to_string(), &now)],
);
} }
#[test] #[test]
@ -308,18 +263,12 @@ fn test_with_column() {
scenario scenario
.args(&["--pages=3:5", "--column=3", "-n", test_file_path]) .args(&["--pages=3:5", "--column=3", "-n", test_file_path])
.succeeds() .succeeds()
.stdout_is_templated_fixture( .stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]);
expected_test_file_path,
vec![(&"{last_modified_time}".to_string(), &value)],
);
new_ucmd!() new_ucmd!()
.args(&["--pages=3:5", "-3", "-n", test_file_path]) .args(&["--pages=3:5", "-3", "-n", test_file_path])
.succeeds() .succeeds()
.stdout_is_templated_fixture( .stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]);
expected_test_file_path,
vec![(&"{last_modified_time}".to_string(), &value)],
);
} }
#[test] #[test]
@ -331,10 +280,7 @@ fn test_with_column_across_option() {
scenario scenario
.args(&["--pages=3:5", "--column=3", "-a", "-n", test_file_path]) .args(&["--pages=3:5", "--column=3", "-a", "-n", test_file_path])
.succeeds() .succeeds()
.stdout_is_templated_fixture( .stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]);
expected_test_file_path,
vec![(&"{last_modified_time}".to_string(), &value)],
);
} }
#[test] #[test]
@ -354,10 +300,7 @@ fn test_with_column_across_option_and_column_separator() {
test_file_path, test_file_path,
]) ])
.succeeds() .succeeds()
.stdout_is_templated_fixture( .stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]);
expected_test_file_path,
vec![(&"{last_modified_time}".to_string(), &value)],
);
new_ucmd!() new_ucmd!()
.args(&[ .args(&[
@ -371,7 +314,7 @@ fn test_with_column_across_option_and_column_separator() {
.succeeds() .succeeds()
.stdout_is_templated_fixture( .stdout_is_templated_fixture(
expected_test_file_path1, expected_test_file_path1,
vec![(&"{last_modified_time}".to_string(), &value)], &[("{last_modified_time}", &value)],
); );
} }
@ -386,19 +329,13 @@ fn test_with_mpr() {
new_ucmd!() new_ucmd!()
.args(&["--pages=1:2", "-m", "-n", test_file_path, test_file_path1]) .args(&["--pages=1:2", "-m", "-n", test_file_path, test_file_path1])
.succeeds() .succeeds()
.stdout_is_templated_fixture( .stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &now)]);
expected_test_file_path,
vec![(&"{last_modified_time}".to_string(), &now)],
);
let now = now_time(); let now = now_time();
new_ucmd!() new_ucmd!()
.args(&["--pages=2:4", "-m", "-n", test_file_path, test_file_path1]) .args(&["--pages=2:4", "-m", "-n", test_file_path, test_file_path1])
.succeeds() .succeeds()
.stdout_is_templated_fixture( .stdout_is_templated_fixture(expected_test_file_path1, &[("{last_modified_time}", &now)]);
expected_test_file_path1,
vec![(&"{last_modified_time}".to_string(), &now)],
);
let now = now_time(); let now = now_time();
new_ucmd!() new_ucmd!()
@ -413,10 +350,7 @@ fn test_with_mpr() {
test_file_path, test_file_path,
]) ])
.succeeds() .succeeds()
.stdout_is_templated_fixture( .stdout_is_templated_fixture(expected_test_file_path2, &[("{last_modified_time}", &now)]);
expected_test_file_path2,
vec![(&"{last_modified_time}".to_string(), &now)],
);
} }
#[test] #[test]
@ -452,10 +386,7 @@ fn test_with_offset_space_option() {
test_file_path, test_file_path,
]) ])
.succeeds() .succeeds()
.stdout_is_templated_fixture( .stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]);
expected_test_file_path,
vec![(&"{last_modified_time}".to_string(), &value)],
);
} }
#[test] #[test]
@ -497,9 +428,9 @@ fn test_with_pr_core_utils_tests() {
scenario_with_expected_status.stdout_is_templated_fixture( scenario_with_expected_status.stdout_is_templated_fixture(
test_file_path, test_file_path,
vec![ &[
(&"{last_modified_time}".to_string(), &value), ("{last_modified_time}", &value),
(&"{file_name}".to_string(), &input_file_path.to_string()), ("{file_name}", input_file_path),
], ],
); );
} }
@ -515,8 +446,5 @@ fn test_with_join_lines_option() {
scenario scenario
.args(&["+1:2", "-J", "-m", test_file_1, test_file_2]) .args(&["+1:2", "-J", "-m", test_file_1, test_file_2])
.run() .run()
.stdout_is_templated_fixture( .stdout_is_templated_fixture(expected_file_path, &[("{last_modified_time}", &now)]);
expected_file_path,
vec![(&"{last_modified_time}".to_string(), &now)],
);
} }

View file

@ -247,7 +247,7 @@ impl CmdResult {
pub fn stdout_is_templated_fixture<T: AsRef<OsStr>>( pub fn stdout_is_templated_fixture<T: AsRef<OsStr>>(
&self, &self,
file_rel_path: T, file_rel_path: T,
template_vars: Vec<(&String, &String)>, template_vars: &[(&str, &str)],
) -> &CmdResult { ) -> &CmdResult {
let mut contents = let mut contents =
String::from_utf8(read_scenario_fixture(&self.tmpd, file_rel_path)).unwrap(); String::from_utf8(read_scenario_fixture(&self.tmpd, file_rel_path)).unwrap();