Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/uu/tr/src/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code coverage tool says that line 45 and line 48 are not covered by our tests. This is good as is, but if you feel up to it, it would be nice to add two more tests to the test_tr.rs file, one for each of these.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I am having problems to understand the error messages. I am glad to add tests to cover the errors, but I need your help to explain the errors. Otherwise I don't really have idea how to trigger them

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are two invocations that trigger these errors:

tr '[a*]' 'a'
tr 'a' '[a*][a*]'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
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")
}
}
}
Expand Down
32 changes: 18 additions & 14 deletions tests/by-util/test_tr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"}],
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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.
Expand All @@ -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},
Expand All @@ -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.
Expand Down