[PATCH 03/10] tests: sort: check long lines survive an external sort
From:
Pádraig Brady
Subject:
[PATCH 03/10] tests: sort: check long lines survive an external sort
Date:
Sat, 24 Oct 2026 16:15:31 +0100
From: Sylvestre Ledru <sylvestre@debian.org>
* tests/sort/sort.pl (@long_lines): New variable.
(@Tests): Add a test case sorting lines much longer than the buffer
with a small -S, so they go through temporary files.
https://github.com/uutils/coreutils/pull/15645
Link: https://github.com/coreutils/coreutils/pull/388
---
tests/sort/sort.pl | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/tests/sort/sort.pl b/tests/sort/sort.pl
index 09b7844a6..6cf0a5454 100755
--- a/tests/sort/sort.pl
+++ b/tests/sort/sort.pl
@@ -35,6 +35,12 @@ my $normalize_filename = {ERR_SUBST => 's/^$prog:
.*?:/$prog: -:/'};
my $no_file = "$prog: cannot read: no-file: No such file or directory\n";
+# Lines much longer than the buffer, in an unsorted order, so that
+# an external sort writes them to temporary files and merges them back.
+my @long_lines = map { sprintf ("%04d", $_ * 7 % 24) . 'x' x 19996 } 0..23;
+my $long_in = join ('', map { "$_\n" } @long_lines);
+my $long_out = join ('', map { "$_\n" } sort @long_lines);
+
my @Tests =
(
["n1", '-n', {IN=>".01\n0\n"}, {OUT=>"0\n.01\n"}],
@@ -391,6 +397,7 @@ my @Tests =
# Exercise the code that enlarges the line buffer.
['realloc-buf', '-S1', {IN=>'a'x4000 ."\n"}, {OUT=>'a'x4000 ."\n"}],
['realloc-buf-2', '-S1', {IN=>'a'x5 ."\n"}, {OUT=>'a'x5 ."\n"}],
+['long-lines-ext', '-S1K', {IN=>$long_in}, {OUT=>$long_out}],
["sort-numeric", '--sort=numeric', {IN=>".01\n0\n"}, {OUT=>"0\n.01\n"}],
["sort-gennum", '--sort=general-numeric',
--
2.55.0