From ec81a23afcc4c6fba0673c6141f328817fa661bd Mon Sep 17 00:00:00 2001 From: Yang Hau Date: Fri, 10 Feb 2023 22:16:07 +0800 Subject: [PATCH] tr: Remove the extra newline in stderr closes #4301 --- src/uu/tr/src/operation.rs | 12 ++++++------ tests/by-util/test_tr.rs | 32 ++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/uu/tr/src/operation.rs b/src/uu/tr/src/operation.rs index 03cea92e7..f27ccc0b9 100644 --- a/src/uu/tr/src/operation.rs +++ b/src/uu/tr/src/operation.rs @@ -37,21 +37,21 @@ pub enum BadSequence { impl Display for BadSequence { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Self::MissingCharClassName => writeln!(f, "missing character class name '[::]'"), + Self::MissingCharClassName => write!(f, "missing character class name '[::]'"), Self::MissingEquivalentClassChar => { - writeln!(f, "missing equivalence class character '[==]'") + write!(f, "missing equivalence class character '[==]'") } Self::MultipleCharRepeatInSet2 => { - writeln!(f, "only one [c*] repeat construct may appear in string2") + write!(f, "only one [c*] repeat construct may appear in string2") } Self::CharRepeatInSet1 => { - writeln!(f, "the [c*] repeat construct may not appear in string1") + write!(f, "the [c*] repeat construct may not appear in string1") } Self::InvalidRepeatCount(count) => { - writeln!(f, "invalid repeat count '{count}' in [c*n] construct") + write!(f, "invalid repeat count '{count}' in [c*n] construct") } Self::EmptySet2WhenNotTruncatingSet1 => { - writeln!(f, "when not truncating set1, string2 must be non-empty") + write!(f, "when not truncating set1, string2 must be non-empty") } } } diff --git a/tests/by-util/test_tr.rs b/tests/by-util/test_tr.rs index 0a098801b..e6daa9c48 100644 --- a/tests/by-util/test_tr.rs +++ b/tests/by-util/test_tr.rs @@ -777,10 +777,7 @@ fn check_against_gnu_tr_tests_range_a_a() { .stdout_is("zbc"); } -// FIXME: Since pr https://github.com/uutils/coreutils/pull/4261: -// stderr ends with 2 newlines but expected is only 1. #[test] -#[cfg(disabled_until_fixed)] fn check_against_gnu_tr_tests_null() { // ['null', qw(a ''), {IN=>''}, {OUT=>''}, {EXIT=>1}, // {ERR=>"$prog: when not truncating set1, string2 must be non-empty\n"}], @@ -855,10 +852,7 @@ fn check_against_gnu_tr_tests_rep_3() { .stdout_is("1x2"); } -// FIXME: Since pr https://github.com/uutils/coreutils/pull/4261: -// stderr ends with 2 newlines but expected is only 1. #[test] -#[cfg(disabled_until_fixed)] fn check_against_gnu_tr_tests_o_rep_1() { // # Another couple octal repeat count tests. // ['o-rep-1', qw('[b*08]' '[x*]'), {IN=>''}, {OUT=>''}, {EXIT=>1}, @@ -1032,10 +1026,6 @@ fn check_against_gnu_tr_tests_ross_6() { .stdout_is(""); } -// FIXME: Since pr https://github.com/uutils/coreutils/pull/4261: -// stderr ends with 2 newlines but expected is only 1. -#[test] -#[cfg(disabled_until_fixed)] #[test] fn check_against_gnu_tr_tests_empty_eq() { // # Ensure that these fail. @@ -1049,10 +1039,6 @@ fn check_against_gnu_tr_tests_empty_eq() { .stderr_is("tr: missing equivalence class character '[==]'\n"); } -// FIXME: Since pr https://github.com/uutils/coreutils/pull/4261: -// stderr ends with 2 newlines but expected is only 1. -#[test] -#[cfg(disabled_until_fixed)] #[test] fn check_against_gnu_tr_tests_empty_cc() { // ['empty-cc', qw('[::]' x), {IN=>''}, {OUT=>''}, {EXIT=>1}, @@ -1064,6 +1050,24 @@ fn check_against_gnu_tr_tests_empty_cc() { .stderr_is("tr: missing character class name '[::]'\n"); } +#[test] +fn check_against_gnu_tr_tests_repeat_set1() { + new_ucmd!() + .args(&["[a*]", "a"]) + .pipe_in("") + .fails() + .stderr_is("tr: the [c*] repeat construct may not appear in string1\n"); +} + +#[test] +fn check_against_gnu_tr_tests_repeat_set2() { + new_ucmd!() + .args(&["a", "[a*][a*]"]) + .pipe_in("") + .fails() + .stderr_is("tr: only one [c*] repeat construct may appear in string2\n"); +} + #[test] fn check_against_gnu_tr_tests_repeat_bs_9() { // # Weird repeat counts.