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

Merge pull request #6810 from cakebaker/echo_remove_double_negation

echo: remove double negation
This commit is contained in:
Terts Diepraam 2024-10-23 10:24:26 +02:00 committed by GitHub
commit 6850be2539
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 11 deletions

View file

@ -282,7 +282,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
// "If the POSIXLY_CORRECT environment variable is set, then when echos first argument is not -n it outputs option-like arguments instead of treating them as options." // "If the POSIXLY_CORRECT environment variable is set, then when echos 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 // 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 escaped = matches.get_flag(options::ENABLE_BACKSLASH_ESCAPE);
let mut stdout_lock = io::stdout().lock(); let mut stdout_lock = io::stdout().lock();
@ -291,14 +291,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
Some(arguments_after_options) => { Some(arguments_after_options) => {
execute( execute(
&mut stdout_lock, &mut stdout_lock,
no_newline, trailing_newline,
escaped, escaped,
arguments_after_options, arguments_after_options,
)?; )?;
} }
None => { None => {
// No strings to print, so just handle newline setting // No strings to print, so just handle newline setting
if !no_newline { if trailing_newline {
stdout_lock.write_all(b"\n")?; stdout_lock.write_all(b"\n")?;
} }
} }
@ -350,7 +350,7 @@ pub fn uu_app() -> Command {
fn execute( fn execute(
stdout_lock: &mut StdoutLock, stdout_lock: &mut StdoutLock,
no_newline: bool, trailing_newline: bool,
escaped: bool, escaped: bool,
arguments_after_options: ValuesRef<'_, OsString>, arguments_after_options: ValuesRef<'_, OsString>,
) -> UResult<()> { ) -> UResult<()> {
@ -375,7 +375,7 @@ fn execute(
} }
} }
if !no_newline { if trailing_newline {
stdout_lock.write_all(b"\n")?; stdout_lock.write_all(b"\n")?;
} }

View file

@ -13,12 +13,7 @@ fn test_default() {
#[test] #[test]
fn test_no_trailing_newline() { fn test_no_trailing_newline() {
new_ucmd!() new_ucmd!().arg("-n").arg("hi").succeeds().stdout_only("hi");
.arg("-n")
.arg("hi")
.succeeds()
.no_stderr()
.stdout_only("hi");
} }
#[test] #[test]