From 2f82853bfa3d16c1497927c26432a4853fadbfd3 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Wed, 18 Dec 2024 14:42:18 +0100 Subject: [PATCH 1/4] cut: move two tests to better places within file --- tests/by-util/test_cut.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/by-util/test_cut.rs b/tests/by-util/test_cut.rs index 7d6009a30eb..fe20b5de679 100644 --- a/tests/by-util/test_cut.rs +++ b/tests/by-util/test_cut.rs @@ -46,6 +46,13 @@ static COMPLEX_SEQUENCE: &TestedSequence = &TestedSequence { sequence: "9-,6-7,-2,4", }; +#[test] +fn test_no_argument() { + new_ucmd!().fails().stderr_is( + "cut: invalid usage: expects one of --fields (-f), --chars (-c) or --bytes (-b)\n", + ); +} + #[test] fn test_invalid_arg() { new_ucmd!().arg("--definitely-invalid").fails().code_is(1); @@ -275,6 +282,15 @@ fn test_equal_as_delimiter3() { .stdout_only_bytes("abZcd\n"); } +#[test] +fn test_newline_delimited() { + new_ucmd!() + .args(&["-f", "1", "-d", "\n"]) + .pipe_in("a:1\nb:") + .succeeds() + .stdout_only_bytes("a:1\nb:\n"); +} + #[test] fn test_multiple() { let result = new_ucmd!() @@ -285,15 +301,6 @@ fn test_multiple() { assert_eq!(result.stderr_str(), ""); } -#[test] -fn test_newline_delimited() { - new_ucmd!() - .args(&["-f", "1", "-d", "\n"]) - .pipe_in("a:1\nb:") - .succeeds() - .stdout_only_bytes("a:1\nb:\n"); -} - #[test] fn test_multiple_mode_args() { for args in [ @@ -312,13 +319,6 @@ fn test_multiple_mode_args() { } } -#[test] -fn test_no_argument() { - new_ucmd!().fails().stderr_is( - "cut: invalid usage: expects one of --fields (-f), --chars (-c) or --bytes (-b)\n", - ); -} - #[test] #[cfg(unix)] fn test_8bit_non_utf8_delimiter() { From 9aca24365faef34214d78bd242493b3442a26a41 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Wed, 18 Dec 2024 14:44:12 +0100 Subject: [PATCH 2/4] cut: simplify test by removing assert_eq! calls --- tests/by-util/test_cut.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/by-util/test_cut.rs b/tests/by-util/test_cut.rs index fe20b5de679..e4c93cd75c3 100644 --- a/tests/by-util/test_cut.rs +++ b/tests/by-util/test_cut.rs @@ -293,12 +293,11 @@ fn test_newline_delimited() { #[test] fn test_multiple() { - let result = new_ucmd!() + new_ucmd!() .args(&["-f2", "-d:", "-d="]) .pipe_in("a=b\n") - .succeeds(); - assert_eq!(result.stdout_str(), "b\n"); - assert_eq!(result.stderr_str(), ""); + .succeeds() + .stdout_only("b\n"); } #[test] From 5ea4903632859e27e7d9947816a1e3fd30f90de8 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Wed, 18 Dec 2024 14:52:04 +0100 Subject: [PATCH 3/4] cut: rename some tests --- tests/by-util/test_cut.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/by-util/test_cut.rs b/tests/by-util/test_cut.rs index e4c93cd75c3..267eedf4541 100644 --- a/tests/by-util/test_cut.rs +++ b/tests/by-util/test_cut.rs @@ -47,7 +47,7 @@ static COMPLEX_SEQUENCE: &TestedSequence = &TestedSequence { }; #[test] -fn test_no_argument() { +fn test_no_args() { new_ucmd!().fails().stderr_is( "cut: invalid usage: expects one of --fields (-f), --chars (-c) or --bytes (-b)\n", ); @@ -256,7 +256,7 @@ fn test_no_such_file() { } #[test] -fn test_equal_as_delimiter1() { +fn test_equal_as_delimiter() { new_ucmd!() .args(&["-f", "2", "-d="]) .pipe_in("--dir=./out/lib") @@ -265,7 +265,7 @@ fn test_equal_as_delimiter1() { } #[test] -fn test_equal_as_delimiter2() { +fn test_empty_string_as_delimiter() { new_ucmd!() .args(&["-f2", "--delimiter="]) .pipe_in("a=b\n") @@ -274,7 +274,7 @@ fn test_equal_as_delimiter2() { } #[test] -fn test_equal_as_delimiter3() { +fn test_empty_string_as_delimiter_with_output_delimiter() { new_ucmd!() .args(&["-f", "1,2", "-d", "''", "--output-delimiter=Z"]) .pipe_in("ab\0cd\n") @@ -283,7 +283,7 @@ fn test_equal_as_delimiter3() { } #[test] -fn test_newline_delimited() { +fn test_newline_as_delimiter() { new_ucmd!() .args(&["-f", "1", "-d", "\n"]) .pipe_in("a:1\nb:") @@ -292,7 +292,7 @@ fn test_newline_delimited() { } #[test] -fn test_multiple() { +fn test_multiple_delimiters() { new_ucmd!() .args(&["-f2", "-d:", "-d="]) .pipe_in("a=b\n") From 6224c374ae490596e2d7e7429d219b82c66471bb Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Wed, 18 Dec 2024 16:15:48 +0100 Subject: [PATCH 4/4] cut: use short and long args in two tests --- tests/by-util/test_cut.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/tests/by-util/test_cut.rs b/tests/by-util/test_cut.rs index 267eedf4541..6c6914a122a 100644 --- a/tests/by-util/test_cut.rs +++ b/tests/by-util/test_cut.rs @@ -257,20 +257,24 @@ fn test_no_such_file() { #[test] fn test_equal_as_delimiter() { - new_ucmd!() - .args(&["-f", "2", "-d="]) - .pipe_in("--dir=./out/lib") - .succeeds() - .stdout_only("./out/lib\n"); + for arg in ["-d=", "--delimiter=="] { + new_ucmd!() + .args(&["-f2", arg]) + .pipe_in("--dir=./out/lib") + .succeeds() + .stdout_only("./out/lib\n"); + } } #[test] fn test_empty_string_as_delimiter() { - new_ucmd!() - .args(&["-f2", "--delimiter="]) - .pipe_in("a=b\n") - .succeeds() - .stdout_only("a=b\n"); + for arg in ["-d''", "--delimiter=", "--delimiter=''"] { + new_ucmd!() + .args(&["-f2", arg]) + .pipe_in("a\0b\n") + .succeeds() + .stdout_only("b\n"); + } } #[test]