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

pr: reduce test flakiness

Since some tests run multiple commands, we have to re-calculate the
expected result for every run.
This is because the expected results depend on file timestamps, but the
files are re-created for every new TestScenario.
This commit is contained in:
Michael Debertol 2021-08-12 17:03:06 +02:00
parent 3a6769f74b
commit 1725bf6a36

View file

@ -68,41 +68,36 @@ fn test_with_numbering_option_with_number_width() {
fn test_with_long_header_option() { fn test_with_long_header_option() {
let test_file_path = "test_one_page.log"; let test_file_path = "test_one_page.log";
let expected_test_file_path = "test_one_page_header.log.expected"; let expected_test_file_path = "test_one_page_header.log.expected";
let mut scenario = new_ucmd!();
let value = file_last_modified_time(&scenario, test_file_path);
let header = "new file"; let header = "new file";
scenario for args in &[&["-h", header][..], &["--header=new file"][..]] {
.args(&["--header=new file", test_file_path]) let mut scenario = new_ucmd!();
.succeeds() let value = file_last_modified_time(&scenario, test_file_path);
.stdout_is_templated_fixture( scenario
expected_test_file_path, .args(args)
&[("{last_modified_time}", &value), ("{header}", header)], .arg(test_file_path)
); .succeeds()
.stdout_is_templated_fixture(
new_ucmd!() expected_test_file_path,
.args(&["-h", header, test_file_path]) &[("{last_modified_time}", &value), ("{header}", header)],
.succeeds() );
.stdout_is_templated_fixture( }
expected_test_file_path,
&[("{last_modified_time}", &value), ("{header}", header)],
);
} }
#[test] #[test]
fn test_with_double_space_option() { fn test_with_double_space_option() {
let test_file_path = "test_one_page.log"; let test_file_path = "test_one_page.log";
let expected_test_file_path = "test_one_page_double_line.log.expected"; let expected_test_file_path = "test_one_page_double_line.log.expected";
let mut scenario = new_ucmd!(); for &arg in &["-d", "--double-space"] {
let value = file_last_modified_time(&scenario, test_file_path); let mut scenario = new_ucmd!();
scenario let value = file_last_modified_time(&scenario, test_file_path);
.args(&["-d", test_file_path]) scenario
.succeeds() .args(&[arg, test_file_path])
.stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]); .succeeds()
.stdout_is_templated_fixture(
new_ucmd!() expected_test_file_path,
.args(&["--double-space", test_file_path]) &[("{last_modified_time}", &value)],
.succeeds() );
.stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]); }
} }
#[test] #[test]
@ -188,33 +183,28 @@ fn test_with_page_range() {
let test_file_path = "test.log"; let test_file_path = "test.log";
let expected_test_file_path = "test_page_range_1.log.expected"; let expected_test_file_path = "test_page_range_1.log.expected";
let expected_test_file_path1 = "test_page_range_2.log.expected"; let expected_test_file_path1 = "test_page_range_2.log.expected";
let mut scenario = new_ucmd!(); for &arg in &["--pages=15", "+15"] {
let value = file_last_modified_time(&scenario, test_file_path); let mut scenario = new_ucmd!();
scenario let value = file_last_modified_time(&scenario, test_file_path);
.args(&["--pages=15", test_file_path]) scenario
.succeeds() .args(&[arg, test_file_path])
.stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]); .succeeds()
.stdout_is_templated_fixture(
new_ucmd!() expected_test_file_path,
.args(&["+15", test_file_path]) &[("{last_modified_time}", &value)],
.succeeds() );
.stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]); }
for &arg in &["--pages=15:17", "+15:17"] {
new_ucmd!() let mut scenario = new_ucmd!();
.args(&["--pages=15:17", test_file_path]) let value = file_last_modified_time(&scenario, test_file_path);
.succeeds() scenario
.stdout_is_templated_fixture( .args(&[arg, test_file_path])
expected_test_file_path1, .succeeds()
&[("{last_modified_time}", &value)], .stdout_is_templated_fixture(
); expected_test_file_path1,
&[("{last_modified_time}", &value)],
new_ucmd!() );
.args(&["+15:17", test_file_path]) }
.succeeds()
.stdout_is_templated_fixture(
expected_test_file_path1,
&[("{last_modified_time}", &value)],
);
} }
#[test] #[test]
@ -232,19 +222,17 @@ fn test_with_no_header_trailer_option() {
#[test] #[test]
fn test_with_page_length_option() { fn test_with_page_length_option() {
let test_file_path = "test.log"; let test_file_path = "test.log";
let expected_test_file_path = "test_page_length.log.expected"; for (arg, expected) in &[
let expected_test_file_path1 = "test_page_length1.log.expected"; ("100", "test_page_length.log.expected"),
let mut scenario = new_ucmd!(); ("5", "test_page_length1.log.expected"),
let value = file_last_modified_time(&scenario, test_file_path); ] {
scenario let mut scenario = new_ucmd!();
.args(&["--pages=2:3", "-l", "100", "-n", test_file_path]) let value = file_last_modified_time(&scenario, test_file_path);
.succeeds() scenario
.stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]); .args(&["--pages=2:3", "-l", arg, "-n", test_file_path])
.succeeds()
new_ucmd!() .stdout_is_templated_fixture(expected, &[("{last_modified_time}", &value)]);
.args(&["--pages=2:3", "-l", "5", "-n", test_file_path]) }
.succeeds()
.stdout_is_fixture(expected_test_file_path1);
} }
#[test] #[test]
@ -277,17 +265,17 @@ fn test_with_stdin() {
fn test_with_column() { fn test_with_column() {
let test_file_path = "column.log"; let test_file_path = "column.log";
let expected_test_file_path = "column.log.expected"; let expected_test_file_path = "column.log.expected";
let mut scenario = new_ucmd!(); for arg in &["-3", "--column=3"] {
let value = file_last_modified_time(&scenario, test_file_path); let mut scenario = new_ucmd!();
scenario let value = file_last_modified_time(&scenario, test_file_path);
.args(&["--pages=3:5", "--column=3", "-n", test_file_path]) scenario
.succeeds() .args(&["--pages=3:5", arg, "-n", test_file_path])
.stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]); .succeeds()
.stdout_is_templated_fixture(
new_ucmd!() expected_test_file_path,
.args(&["--pages=3:5", "-3", "-n", test_file_path]) &[("{last_modified_time}", &value)],
.succeeds() );
.stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]); }
} }
#[test] #[test]
@ -305,36 +293,17 @@ fn test_with_column_across_option() {
#[test] #[test]
fn test_with_column_across_option_and_column_separator() { fn test_with_column_across_option_and_column_separator() {
let test_file_path = "column.log"; let test_file_path = "column.log";
let expected_test_file_path = "column_across_sep.log.expected"; for (arg, expected) in &[
let expected_test_file_path1 = "column_across_sep1.log.expected"; ("-s|", "column_across_sep.log.expected"),
let mut scenario = new_ucmd!(); ("-Sdivide", "column_across_sep1.log.expected"),
let value = file_last_modified_time(&scenario, test_file_path); ] {
scenario let mut scenario = new_ucmd!();
.args(&[ let value = file_last_modified_time(&scenario, test_file_path);
"--pages=3:5", scenario
"--column=3", .args(&["--pages=3:5", "--column=3", arg, "-a", "-n", test_file_path])
"-s|", .succeeds()
"-a", .stdout_is_templated_fixture(expected, &[("{last_modified_time}", &value)]);
"-n", }
test_file_path,
])
.succeeds()
.stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]);
new_ucmd!()
.args(&[
"--pages=3:5",
"--column=3",
"-Sdivide",
"-a",
"-n",
test_file_path,
])
.succeeds()
.stdout_is_templated_fixture(
expected_test_file_path1,
&[("{last_modified_time}", &value)],
);
} }
#[test] #[test]