1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

fmt: allow negative widths as first argument

Also fix error messages for consistency with GNU fmt
This commit is contained in:
Joseph Jon Booker 2024-03-22 21:30:03 -05:00
parent 6f07bf10a1
commit 7b928f792c
3 changed files with 199 additions and 25 deletions

View file

@ -37,6 +37,14 @@ fn test_fmt_width() {
}
}
#[test]
fn test_fmt_positional_width() {
new_ucmd!()
.args(&["-10", "one-word-per-line.txt"])
.succeeds()
.stdout_is("this is a\nfile with\none word\nper line\n");
}
#[test]
fn test_small_width() {
for width in ["0", "1", "2", "3"] {
@ -71,6 +79,24 @@ fn test_fmt_invalid_width() {
}
}
#[test]
fn test_fmt_positional_width_not_first() {
new_ucmd!()
.args(&["one-word-per-line.txt", "-10"])
.fails()
.code_is(1)
.stderr_contains("fmt: invalid option -- 1; -WIDTH is recognized only when it is the first\noption; use -w N instead");
}
#[test]
fn test_fmt_width_not_valid_number() {
new_ucmd!()
.args(&["-25x", "one-word-per-line.txt"])
.fails()
.code_is(1)
.stderr_contains("fmt: invalid width: '25x'");
}
#[ignore]
#[test]
fn test_fmt_goal() {
@ -104,6 +130,15 @@ fn test_fmt_goal_bigger_than_default_width_of_75() {
}
}
#[test]
fn test_fmt_non_existent_file() {
new_ucmd!()
.args(&["non-existing"])
.fails()
.code_is(1)
.stderr_is("fmt: cannot open 'non-existing' for reading: No such file or directory\n");
}
#[test]
fn test_fmt_invalid_goal() {
for param in ["-g", "--goal"] {