From b0fa702e90e83e79bdf9a2bfa837b9047e38cf96 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Tue, 22 Oct 2024 14:32:20 +0200 Subject: [PATCH 1/2] echo: remove unnecessary no_stderr() call in test --- tests/by-util/test_echo.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/by-util/test_echo.rs b/tests/by-util/test_echo.rs index 47240c7c0..136500b48 100644 --- a/tests/by-util/test_echo.rs +++ b/tests/by-util/test_echo.rs @@ -13,12 +13,7 @@ fn test_default() { #[test] fn test_no_trailing_newline() { - new_ucmd!() - .arg("-n") - .arg("hi") - .succeeds() - .no_stderr() - .stdout_only("hi"); + new_ucmd!().arg("-n").arg("hi").succeeds().stdout_only("hi"); } #[test] From 13df9e2f30dc65f827cbfd6671a68e3cc7173854 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Tue, 22 Oct 2024 15:04:16 +0200 Subject: [PATCH 2/2] echo: remove double negation --- src/uu/echo/src/echo.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/uu/echo/src/echo.rs b/src/uu/echo/src/echo.rs index 6d8c62421..746cdd7c5 100644 --- a/src/uu/echo/src/echo.rs +++ b/src/uu/echo/src/echo.rs @@ -282,7 +282,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { // "If the POSIXLY_CORRECT environment variable is set, then when echo’s first argument is not -n it outputs option-like arguments instead of treating them as options." // https://www.gnu.org/software/coreutils/manual/html_node/echo-invocation.html - let no_newline = matches.get_flag(options::NO_NEWLINE); + let trailing_newline = !matches.get_flag(options::NO_NEWLINE); let escaped = matches.get_flag(options::ENABLE_BACKSLASH_ESCAPE); let mut stdout_lock = io::stdout().lock(); @@ -291,14 +291,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { Some(arguments_after_options) => { execute( &mut stdout_lock, - no_newline, + trailing_newline, escaped, arguments_after_options, )?; } None => { // No strings to print, so just handle newline setting - if !no_newline { + if trailing_newline { stdout_lock.write_all(b"\n")?; } } @@ -350,7 +350,7 @@ pub fn uu_app() -> Command { fn execute( stdout_lock: &mut StdoutLock, - no_newline: bool, + trailing_newline: bool, escaped: bool, arguments_after_options: ValuesRef<'_, OsString>, ) -> UResult<()> { @@ -375,7 +375,7 @@ fn execute( } } - if !no_newline { + if trailing_newline { stdout_lock.write_all(b"\n")?; }