Skip to content

Commit 59815b3

Browse files
authored
Merge pull request #8482 from sylvestre/l10n-2
sort: adjust the behavior of 'sort --output --file-with-dash' to match GNU's
2 parents 5ba99ae + d9f17cc commit 59815b3

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

src/uu/sort/src/sort.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,8 @@ pub fn uu_app() -> Command {
14801480
.value_parser(ValueParser::os_string())
14811481
.value_name("FILENAME")
14821482
.value_hint(clap::ValueHint::FilePath)
1483+
.num_args(1)
1484+
.allow_hyphen_values(true)
14831485
// To detect multiple occurrences and raise an error
14841486
.action(ArgAction::Append),
14851487
)

tests/by-util/test_sort.rs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,29 @@ fn test_multiple_output_files() {
13491349
.stderr_is("sort: multiple output files specified\n");
13501350
}
13511351

1352+
#[test]
1353+
fn test_output_file_with_leading_dash() {
1354+
let test_cases = [
1355+
(
1356+
["--output", "--dash-file"],
1357+
"banana\napple\ncherry\n",
1358+
"apple\nbanana\ncherry\n",
1359+
),
1360+
(
1361+
["-o", "--another-dash-file"],
1362+
"zebra\nxray\nyak\n",
1363+
"xray\nyak\nzebra\n",
1364+
),
1365+
];
1366+
1367+
for (args, input, expected) in test_cases {
1368+
let (at, mut ucmd) = at_and_ucmd!();
1369+
ucmd.args(&args).pipe_in(input).succeeds().no_stdout();
1370+
1371+
assert_eq!(at.read(args[1]), expected);
1372+
}
1373+
}
1374+
13521375
#[test]
13531376
// Test for GNU tests/sort/sort-files0-from.pl "f-extra-arg"
13541377
fn test_files0_from_extra_arg() {
@@ -1698,26 +1721,4 @@ fn test_clap_localization_invalid_value() {
16981721
}
16991722
}
17001723

1701-
#[test]
1702-
fn test_clap_localization_tip_for_value_with_dash() {
1703-
let test_cases = vec![
1704-
("en_US.UTF-8", vec!["tip:", "-- --file-with-dash"]),
1705-
("fr_FR.UTF-8", vec!["tip:", "-- --file-with-dash"]), // TODO: fix French translation
1706-
];
1707-
1708-
for (locale, expected_strings) in test_cases {
1709-
let result = new_ucmd!()
1710-
.env("LANG", locale)
1711-
.env("LC_ALL", locale)
1712-
.arg("--output")
1713-
.arg("--file-with-dash")
1714-
.fails();
1715-
1716-
let stderr = result.stderr_str();
1717-
for expected in expected_strings {
1718-
assert!(stderr.contains(expected));
1719-
}
1720-
}
1721-
}
1722-
17231724
/* spell-checker: enable */

0 commit comments

Comments
 (0)