Skip to content
Open
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
7 changes: 5 additions & 2 deletions src/uu/split/src/strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,10 @@ impl Strategy {
if n > 0 {
Ok(strategy(n))
} else {
Err(error(ParseSizeError::ParseFailure(s.to_owned()), origin()))
Err(error(
ParseSizeError::ParseFailure(s.quote().to_string()),
origin(),
))
}
}
// Check that the user is not specifying more than one strategy.
Expand All @@ -288,7 +291,7 @@ impl Strategy {
Ok(Self::Lines(v))
} else {
Err(StrategyError::Lines(
ParseSizeError::ParseFailure(v.to_string()),
ParseSizeError::ParseFailure(v.to_string().quote().to_string()),
None,
))
}
Expand Down
30 changes: 25 additions & 5 deletions tests/by-util/test_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,12 +428,12 @@ fn test_split_lines_number() {
.ucmd()
.args(&["--lines", "0", "file"])
.fails_with_code(1)
.stderr_only("split: invalid number of lines: 0\n");
.stderr_only("split: invalid number of lines: '0'\n");
scene
.ucmd()
.args(&["-0", "file"])
.fails_with_code(1)
.stderr_only("split: invalid number of lines: 0\n");
.stderr_only("split: invalid number of lines: '0'\n");
scene
.ucmd()
.args(&["--lines", "2fb", "file"])
Expand Down Expand Up @@ -1704,6 +1704,26 @@ fn test_round_robin_limited_file_descriptors() {
.succeeds();
}

/// A zero SIZE is quoted like any other rejected SIZE, as GNU does.
#[test]
fn test_split_zero_size_is_quoted() {
let scene = TestScenario::new(util_name!());
scene.fixtures.touch("file");

for (option, message) in [
("--lines", "invalid number of lines"),
("--bytes", "invalid number of bytes"),
("--line-bytes", "invalid number of bytes"),
] {
scene
.ucmd()
.args(&[option, "0", "file"])
.fails_with_code(1)
.no_stdout()
.stderr_contains(format!("split: {message}: '0'\n"));
}
}
Comment on lines +1708 to +1725

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This test is more or less a duplicate of test_split_invalid_input but with long options. So I would combine them.


#[test]
fn test_split_invalid_input() {
// Test if stdout/stderr for '--lines' option is correct
Expand All @@ -1716,19 +1736,19 @@ fn test_split_invalid_input() {
.args(&["--lines", "0", "file"])
.fails()
.no_stdout()
.stderr_contains("split: invalid number of lines: 0");
.stderr_contains("split: invalid number of lines: '0'");
scene
.ucmd()
.args(&["-C", "0", "file"])
.fails()
.no_stdout()
.stderr_contains("split: invalid number of bytes: 0");
.stderr_contains("split: invalid number of bytes: '0'");
scene
.ucmd()
.args(&["-b", "0", "file"])
.fails()
.no_stdout()
.stderr_contains("split: invalid number of bytes: 0");
.stderr_contains("split: invalid number of bytes: '0'");
scene
.ucmd()
.args(&["-n", "0", "file"])
Expand Down
Loading