seq: improve error handling for invalid -f values

Improve the error message produced by `seq` when given invalid format
specifiers for the `-f` option. Before this commit:

    $ seq -f "%" 1
    seq: %: invalid conversion specification
    $ seq -f "%g%" 1
    seq: %: invalid conversion specification

After this commit:

    $ seq -f "%" 1
    seq: format '%' ends in %
    $ seq -f "%g%" 1
    seq: format '%g%' has too many % directives

This matches the behavior of GNU `seq`.
This commit is contained in:
Jeffrey Finkelstein
2024-12-30 12:30:26 -05:00
parent 00d1866060
commit cccab35337
2 changed files with 25 additions and 4 deletions
+10
View File
@@ -787,6 +787,16 @@ fn test_invalid_format() {
.fails()
.no_stdout()
.stderr_contains("format '%g%g' has too many % directives");
new_ucmd!()
.args(&["-f", "%g%", "1"])
.fails()
.no_stdout()
.stderr_contains("format '%g%' has too many % directives");
new_ucmd!()
.args(&["-f", "%", "1"])
.fails()
.no_stdout()
.stderr_contains("format '%' ends in %");
}
#[test]