1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-01 13:37:48 +00:00

sort: correctly inherit global flags for keys (#2302)

Closes #2254. We should only inherit global settings for keys when there
are absolutely no options attached to the key.

The default key (matching the whole line) is implicitly added only if no
keys are supplied.

Improved some error messages by including more context.
This commit is contained in:
Michael Debertol 2021-05-29 23:25:56 +02:00 committed by GitHub
parent d821719c67
commit dc63133f14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 331 additions and 129 deletions

View file

@ -471,7 +471,7 @@ fn test_keys_invalid_field() {
new_ucmd!()
.args(&["-k", "1."])
.fails()
.stderr_only("sort: failed to parse character index for key `1.`: cannot parse integer from empty string");
.stderr_only("sort: failed to parse key `1.`: failed to parse character index ``: cannot parse integer from empty string");
}
#[test]
@ -479,7 +479,7 @@ fn test_keys_invalid_field_option() {
new_ucmd!()
.args(&["-k", "1.1x"])
.fails()
.stderr_only("sort: invalid option for key: `x`");
.stderr_only("sort: failed to parse key `1.1x`: invalid option: `x`");
}
#[test]
@ -487,7 +487,7 @@ fn test_keys_invalid_field_zero() {
new_ucmd!()
.args(&["-k", "0.1"])
.fails()
.stderr_only("sort: field index was 0");
.stderr_only("sort: failed to parse key `0.1`: field index can not be 0");
}
#[test]
@ -495,7 +495,7 @@ fn test_keys_invalid_char_zero() {
new_ucmd!()
.args(&["-k", "1.0"])
.fails()
.stderr_only("sort: invalid character index 0 in `1.0` for the start position of a field");
.stderr_only("sort: failed to parse key `1.0`: invalid character index 0 for the start position of a field");
}
#[test]
@ -586,6 +586,47 @@ fn test_keys_negative_size_match() {
test_helper("keys_negative_size", &["-k 3,1"]);
}
#[test]
fn test_keys_ignore_flag() {
test_helper("keys_ignore_flag", &["-k 1n -b"])
}
#[test]
fn test_doesnt_inherit_key_settings() {
let input = " 1
2
10
";
new_ucmd!()
.args(&["-k", "1b", "-n"])
.pipe_in(input)
.succeeds()
.stdout_only(
" 1
10
2
",
);
}
#[test]
fn test_inherits_key_settings() {
let input = " 1
2
10
";
new_ucmd!()
.args(&["-k", "1", "-n"])
.pipe_in(input)
.succeeds()
.stdout_only(
" 1
2
10
",
);
}
#[test]
fn test_zero_terminated() {
test_helper("zero-terminated", &["-z"]);
@ -707,10 +748,9 @@ fn test_dictionary_and_nonprinting_conflicts() {
.succeeds();
}
for conflicting_arg in &conflicting_args {
// FIXME: this should ideally fail.
new_ucmd!()
.args(&["-k", &format!("1{},1{}", restricted_arg, conflicting_arg)])
.succeeds();
.fails();
}
}
}
@ -737,3 +777,8 @@ fn test_nonexistent_file() {
"sort: cannot read: \"nonexistent.txt\": The system cannot find the file specified. (os error 2)",
);
}
#[test]
fn test_blanks() {
test_helper("blanks", &["-b", "--ignore-blanks"]);
}

5
tests/fixtures/sort/blanks.expected vendored Normal file
View file

@ -0,0 +1,5 @@
a
b
x
x
z

View file

@ -0,0 +1,15 @@
a
_
___
b
_
_
x
_
__________
x
_
___
z
_
__

5
tests/fixtures/sort/blanks.txt vendored Normal file
View file

@ -0,0 +1,5 @@
b
a
z
x
x

View file

@ -0,0 +1,2 @@
1a
1A

View file

@ -0,0 +1,6 @@
1a
_
___
1A
_
__

View file

@ -0,0 +1,2 @@
1a
1A