Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wc: pass GNU test wc-files0-from.pl #5582

Merged
merged 2 commits into from Nov 27, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/uu/wc/src/wc.rs
Expand Up @@ -167,7 +167,9 @@ impl<'a> Inputs<'a> {
None => Ok(Self::Files0From(input)),
}
}
(Some(_), Some(_)) => Err(WcError::FilesDisabled.into()),
(Some(mut files), Some(_)) => {
Err(WcError::files_disabled(files.next().unwrap()).into())
}
}
}

Expand Down Expand Up @@ -342,8 +344,8 @@ impl TotalWhen {

#[derive(Debug, Error)]
enum WcError {
#[error("file operands cannot be combined with --files0-from")]
FilesDisabled,
#[error("extra operand '{extra}'\nfile operands cannot be combined with --files0-from")]
FilesDisabled { extra: Cow<'static, str> },
#[error("when reading file names from stdin, no file name of '-' allowed")]
StdinReprNotAllowed,
#[error("invalid zero-length file name")]
Expand All @@ -365,11 +367,15 @@ impl WcError {
None => Self::ZeroLengthFileName,
}
}
fn files_disabled(first_extra: &OsString) -> Self {
let extra = first_extra.to_string_lossy().into_owned().into();
Self::FilesDisabled { extra }
}
}

impl UError for WcError {
fn usage(&self) -> bool {
matches!(self, Self::FilesDisabled)
matches!(self, Self::FilesDisabled { .. })
}
}

Expand Down
3 changes: 2 additions & 1 deletion tests/by-util/test_wc.rs
Expand Up @@ -423,7 +423,8 @@ fn test_files_from_pseudo_filesystem() {

#[test]
fn test_files0_disabled_files_argument() {
const MSG: &str = "file operands cannot be combined with --files0-from";
const MSG: &str =
"extra operand 'lorem_ipsum.txt'\nfile operands cannot be combined with --files0-from";
new_ucmd!()
.args(&["--files0-from=files0_list.txt"])
.arg("lorem_ipsum.txt")
Expand Down