Skip to content

Commit 44fa2e9

Browse files
committed
csplit: correctly handle repeated arguments
1 parent dcb53b6 commit 44fa2e9

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/uu/csplit/src/csplit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ pub fn uu_app() -> Command {
585585
.version(crate_version!())
586586
.about(ABOUT)
587587
.override_usage(format_usage(USAGE))
588+
.args_override_self(true)
588589
.infer_long_args(true)
589590
.arg(
590591
Arg::new(options::SUFFIX_FORMAT)

tests/by-util/test_csplit.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,3 +1376,39 @@ fn no_such_file() {
13761376
.fails()
13771377
.stderr_contains("cannot access 'in': No such file or directory");
13781378
}
1379+
1380+
#[test]
1381+
fn repeat_everything() {
1382+
let (at, mut ucmd) = at_and_ucmd!();
1383+
ucmd.args(&[
1384+
"numbers50.txt",
1385+
"--suppress-matched",
1386+
"--suppress-matched",
1387+
"-kzsn", // spell-checker:disable-line
1388+
"2",
1389+
"-szkn3", // spell-checker:disable-line
1390+
"-b",
1391+
"%03d",
1392+
"-b%03x",
1393+
"-f",
1394+
"xxy_",
1395+
"-fxxz_", // spell-checker:disable-line
1396+
"/13/",
1397+
"9",
1398+
"{5}",
1399+
])
1400+
.fails()
1401+
.no_stdout()
1402+
.code_is(1)
1403+
.stderr_only("csplit: '9': line number out of range on repetition 5\n");
1404+
let count = glob(&at.plus_as_string("xx*"))
1405+
.expect("there should be some splits created")
1406+
.count();
1407+
assert_eq!(count, 6);
1408+
assert_eq!(at.read("xxz_000"), generate(1, 12 + 1));
1409+
assert_eq!(at.read("xxz_001"), generate(14, 17 + 1)); // FIXME: GNU starts at 15
1410+
assert_eq!(at.read("xxz_002"), generate(19, 26 + 1));
1411+
assert_eq!(at.read("xxz_003"), generate(28, 35 + 1));
1412+
assert_eq!(at.read("xxz_004"), generate(37, 44 + 1));
1413+
assert_eq!(at.read("xxz_005"), generate(46, 50 + 1));
1414+
}

0 commit comments

Comments
 (0)