tests: fmt: check a last line lacking the -p prefix keeps no newline

* tests/fmt/base.pl (@Tests): Add test cases for a last line without
a trailing newline, with and without the prefix.
https://github.com/uutils/coreutils/pull/15554

Link: https://github.com/coreutils/coreutils/pull/389
This commit is contained in:
Sylvestre Ledru authored and Pádraig Brady committed 2026-10-24 16:15:03 +01:00
1 parent eac02dd7a2
commit 16ef11d2bd
1 file changed
+15
+15
View File
@@ -58,6 +58,21 @@ my @Tests =
['pfx-of-pfx', qw (-p 'foo'),
{IN=> "fo\n"},
{OUT=> "fo\n"}],
# With --prefix=P, a last line lacking the prefix is copied as is,
# without adding a missing newline.
['pfx-no-nl-1', "-p '#'", {IN=> "x"}, {OUT=> "x"}],
['pfx-no-nl-2', "-p '#'", {IN=> " x"}, {OUT=> " x"}],
['pfx-no-nl-3', "-p '#'", {IN=> "a\nmixed"}, {OUT=> "a\nmixed"}],
['pfx-no-nl-4', "-s -p '#'", {IN=> "a\nmixed"}, {OUT=> "a\nmixed"}],
# A last line with the prefix is reformatted and gets a newline.
['pfx-no-nl-5', "-p '#'", {IN=> "# hi"}, {OUT=> "# hi\n"}],
['pfx-no-nl-6', "-p '#'", {IN=> "x\n# hi"}, {OUT=> "x\n# hi\n"}],
['pfx-no-nl-7', "-p '#'", {IN=> "x\n#"}, {OUT=> "x\n#\n"}],
# So with several files, that line runs into the next file.
['pfx-no-nl-8', "-p '#'",
{IN=> {f1=> "a\nmixed"}}, {IN=> {f2=> "hello\n"}},
{OUT=> "a\nmixedhello\n"}],
);
my $save_temps = $ENV{DEBUG};