From 77b701cfc46b3f3e2688afdd3ece45b62b008c78 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Fri, 14 Mar 2025 08:57:30 +0100 Subject: [PATCH 1/3] true,false: use no_output() in tests --- tests/by-util/test_false.rs | 6 +++--- tests/by-util/test_true.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/by-util/test_false.rs b/tests/by-util/test_false.rs index 01916ec62..a311a1cfc 100644 --- a/tests/by-util/test_false.rs +++ b/tests/by-util/test_false.rs @@ -8,7 +8,7 @@ use std::fs::OpenOptions; #[test] fn test_exit_code() { - new_ucmd!().fails(); + new_ucmd!().fails().no_output(); } #[test] @@ -30,7 +30,7 @@ fn test_help() { #[test] fn test_short_options() { for option in ["-h", "-V"] { - new_ucmd!().arg(option).fails().stdout_is(""); + new_ucmd!().arg(option).fails().no_output(); } } @@ -39,7 +39,7 @@ fn test_conflict() { new_ucmd!() .args(&["--help", "--version"]) .fails() - .stdout_is(""); + .no_output(); } #[test] diff --git a/tests/by-util/test_true.rs b/tests/by-util/test_true.rs index 750c60132..3238fbb34 100644 --- a/tests/by-util/test_true.rs +++ b/tests/by-util/test_true.rs @@ -8,7 +8,7 @@ use std::fs::OpenOptions; #[test] fn test_exit_code() { - new_ucmd!().succeeds(); + new_ucmd!().succeeds().no_output(); } #[test] @@ -30,7 +30,7 @@ fn test_help() { #[test] fn test_short_options() { for option in ["-h", "-V"] { - new_ucmd!().arg(option).succeeds().stdout_is(""); + new_ucmd!().arg(option).succeeds().no_output(); } } @@ -39,7 +39,7 @@ fn test_conflict() { new_ucmd!() .args(&["--help", "--version"]) .succeeds() - .stdout_is(""); + .no_output(); } #[test] From 6cf1374b60e8b277ad9c065c44a433135650fb42 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Fri, 14 Mar 2025 08:59:27 +0100 Subject: [PATCH 2/3] true,false: rename test_exit_code -> test_no_args --- tests/by-util/test_false.rs | 2 +- tests/by-util/test_true.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/by-util/test_false.rs b/tests/by-util/test_false.rs index a311a1cfc..b2bae03c0 100644 --- a/tests/by-util/test_false.rs +++ b/tests/by-util/test_false.rs @@ -7,7 +7,7 @@ use crate::common::util::TestScenario; use std::fs::OpenOptions; #[test] -fn test_exit_code() { +fn test_no_args() { new_ucmd!().fails().no_output(); } diff --git a/tests/by-util/test_true.rs b/tests/by-util/test_true.rs index 3238fbb34..a01a0df6e 100644 --- a/tests/by-util/test_true.rs +++ b/tests/by-util/test_true.rs @@ -7,7 +7,7 @@ use crate::common::util::TestScenario; use std::fs::OpenOptions; #[test] -fn test_exit_code() { +fn test_no_args() { new_ucmd!().succeeds().no_output(); } From 10fc96a78b95ce1c7bce71e9253b88e55b122bec Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Fri, 14 Mar 2025 09:21:37 +0100 Subject: [PATCH 3/3] true,false: remove newline from version string --- src/uu/false/src/false.rs | 2 +- src/uu/true/src/true.rs | 2 +- tests/by-util/test_false.rs | 10 ++++++---- tests/by-util/test_true.rs | 7 ++++++- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/uu/false/src/false.rs b/src/uu/false/src/false.rs index 3ae25e569..2b6e94549 100644 --- a/src/uu/false/src/false.rs +++ b/src/uu/false/src/false.rs @@ -28,7 +28,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let error = match e.kind() { clap::error::ErrorKind::DisplayHelp => command.print_help(), clap::error::ErrorKind::DisplayVersion => { - writeln!(std::io::stdout(), "{}", command.render_version()) + write!(std::io::stdout(), "{}", command.render_version()) } _ => Ok(()), }; diff --git a/src/uu/true/src/true.rs b/src/uu/true/src/true.rs index 637758625..98f4bcac2 100644 --- a/src/uu/true/src/true.rs +++ b/src/uu/true/src/true.rs @@ -22,7 +22,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let error = match e.kind() { clap::error::ErrorKind::DisplayHelp => command.print_help(), clap::error::ErrorKind::DisplayVersion => { - writeln!(std::io::stdout(), "{}", command.render_version()) + write!(std::io::stdout(), "{}", command.render_version()) } _ => Ok(()), }; diff --git a/tests/by-util/test_false.rs b/tests/by-util/test_false.rs index b2bae03c0..23b3e914b 100644 --- a/tests/by-util/test_false.rs +++ b/tests/by-util/test_false.rs @@ -2,7 +2,10 @@ // // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. + use crate::common::util::TestScenario; +use regex::Regex; + #[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))] use std::fs::OpenOptions; @@ -13,10 +16,9 @@ fn test_no_args() { #[test] fn test_version() { - new_ucmd!() - .args(&["--version"]) - .fails() - .stdout_contains("false"); + let re = Regex::new(r"^false .*\d+\.\d+\.\d+\n$").unwrap(); + + new_ucmd!().args(&["--version"]).fails().stdout_matches(&re); } #[test] diff --git a/tests/by-util/test_true.rs b/tests/by-util/test_true.rs index a01a0df6e..7711d9b72 100644 --- a/tests/by-util/test_true.rs +++ b/tests/by-util/test_true.rs @@ -2,7 +2,10 @@ // // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. + use crate::common::util::TestScenario; +use regex::Regex; + #[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))] use std::fs::OpenOptions; @@ -13,10 +16,12 @@ fn test_no_args() { #[test] fn test_version() { + let re = Regex::new(r"^true .*\d+\.\d+\.\d+\n$").unwrap(); + new_ucmd!() .args(&["--version"]) .succeeds() - .stdout_contains("true"); + .stdout_matches(&re); } #[test]