summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2008-05-09 08:04:59 +0200
committerJim Meyering <meyering@redhat.com>2008-05-09 08:11:12 +0200
commit15b0d75930187b5f9416160dd1b1df1a5fb567d8 (patch)
treef6c2baaf905f4bc296a66494c3cbe975396660fa /tests
parentf0ad302ca9b8ec6b22bb3015aebdd4a1fd449ccf (diff)
downloadcoreutils-15b0d75930187b5f9416160dd1b1df1a5fb567d8.tar.xz
tests: remove directory, tests/sort/
* configure.ac (AC_CONFIG_FILES): Remove tests/sort/Makefile. * tests/Makefile.am (SUBDIRS): Remove sort. * tests/misc/sort: New file, with tests from... * tests/sort/Test.pm: ...here. Remove file.
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am3
-rwxr-xr-xtests/misc/sort348
-rw-r--r--tests/sort/Test.pm303
3 files changed, 350 insertions, 304 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e2cfa27a2..caeb554c8 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -23,7 +23,7 @@ EXTRA_DIST = \
## N O T E :: Do not add more names to this list.
## N O T E :: Even these are expected to go away.
-SUBDIRS = join pr sort tail
+SUBDIRS = join pr tail
root_tests = \
chown/basic \
@@ -191,6 +191,7 @@ TESTS = \
misc/shred-exact \
misc/shred-remove \
misc/shuf \
+ misc/sort \
misc/sort-compress \
misc/sort-merge \
misc/sort-rand \
diff --git a/tests/misc/sort b/tests/misc/sort
new file mode 100755
index 000000000..ff278b9b9
--- /dev/null
+++ b/tests/misc/sort
@@ -0,0 +1,348 @@
+#!/bin/sh
+# -*- perl -*-
+
+# Copyright (C) 2008 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+: ${top_srcdir=../..}
+. $top_srcdir/tests/require-perl
+
+me=`echo $0|sed 's,.*/,,'`
+exec $PERL -w -I$top_srcdir/tests -MCoreutils -M"CuTmpdir qw($me)" -- - <<\EOF
+require 5.003;
+use strict;
+
+my $prog = 'sort';
+
+# Turn off localization of executable's output.
+@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
+
+# Since each test is run with a file name and with redirected stdin,
+# the name in the diagnostic is either the file name or "-".
+# Normalize each diagnostic to use '-'.
+my $normalize_filename = {ERR_SUBST => 's/^$prog: .*?:/$prog: -:/'};
+
+my $no_file = "$prog: open failed: no-file: No such file or directory\n";
+
+my @Tests =
+(
+["n1", '-n', {IN=>".01\n0\n"}, {OUT=>"0\n.01\n"}],
+["n2", '-n', {IN=>".02\n.01\n"}, {OUT=>".01\n.02\n"}],
+["n3", '-n', {IN=>".02\n.00\n"}, {OUT=>".00\n.02\n"}],
+["n4", '-n', {IN=>".02\n.000\n"}, {OUT=>".000\n.02\n"}],
+["n5", '-n', {IN=>".021\n.029\n"}, {OUT=>".021\n.029\n"}],
+
+["n6", '-n', {IN=>".02\n.0*\n"}, {OUT=>".0*\n.02\n"}],
+["n7", '-n', {IN=>".02\n.*\n"}, {OUT=>".*\n.02\n"}],
+["n8a", '-s -n -k1,1', {IN=>".0a\n.0b\n"}, {OUT=>".0a\n.0b\n"}],
+["n8b", '-s -n -k1,1', {IN=>".0b\n.0a\n"}, {OUT=>".0b\n.0a\n"}],
+["n9a", '-s -n -k1,1', {IN=>".000a\n.000b\n"}, {OUT=>".000a\n.000b\n"}],
+["n9b", '-s -n -k1,1', {IN=>".000b\n.000a\n"}, {OUT=>".000b\n.000a\n"}],
+["n10a", '-s -n -k1,1', {IN=>".00a\n.000b\n"}, {OUT=>".00a\n.000b\n"}],
+["n10b", '-s -n -k1,1', {IN=>".00b\n.000a\n"}, {OUT=>".00b\n.000a\n"}],
+["n11a", '-s -n -k1,1', {IN=>".01a\n.010\n"}, {OUT=>".01a\n.010\n"}],
+["n11b", '-s -n -k1,1', {IN=>".010\n.01a\n"}, {OUT=>".010\n.01a\n"}],
+
+["01a", '', {IN=>"A\nB\nC\n"}, {OUT=>"A\nB\nC\n"}],
+#
+["02a", '-c', {IN=>"A\nB\nC\n"}, {OUT=>''}],
+["02b", '-c', {IN=>"A\nC\nB\n"}, {OUT=>''}, {EXIT=>1},
+ {ERR=>"$prog: -:3: disorder: B\n"}, $normalize_filename],
+["02c", qw(-c -k1,1), {IN=>"a\na b\n"}, {OUT=>''}],
+["02d", '-C', {IN=>"A\nB\nC\n"}, {OUT=>''}],
+["02e", '-C', {IN=>"A\nC\nB\n"}, {OUT=>''}, {EXIT=>1}],
+# This should fail because there are duplicate keys
+["02m", '-cu', {IN=>"A\nA\n"}, {OUT=>''}, {EXIT=>1},
+ {ERR=>"$prog: -:2: disorder: A\n"}, $normalize_filename],
+["02n", '-cu', {IN=>"A\nB\n"}, {OUT=>''}],
+["02o", '-cu', {IN=>"A\nB\nB\n"}, {OUT=>''}, {EXIT=>1},
+ {ERR=>"$prog: -:3: disorder: B\n"}, $normalize_filename],
+["02p", '-cu', {IN=>"B\nA\nB\n"}, {OUT=>''}, {EXIT=>1},
+ {ERR=>"$prog: -:2: disorder: A\n"}, $normalize_filename],
+#
+["03a", '-k1', {IN=>"B\nA\n"}, {OUT=>"A\nB\n"}],
+["03b", '-k1,1', {IN=>"B\nA\n"}, {OUT=>"A\nB\n"}],
+["03c", qw(-k1 -k2), {IN=>"A b\nA a\n"}, {OUT=>"A a\nA b\n"}],
+# Fail with a diagnostic when -k specifies field == 0.
+["03d", '-k0', {EXIT=>2},
+ {ERR=>"$prog: -: invalid field specification `0'\n"},
+ $normalize_filename],
+# Fail with a diagnostic when -k specifies character == 0.
+["03e", '-k1.0', {EXIT=>2},
+ {ERR=>"$prog: character offset is zero: invalid field specification `1.0'\n"}],
+["03f", '-k1.1,-k0', {EXIT=>2},
+ {ERR=>"$prog: invalid number after `,': invalid count at start of `-k0'\n"}],
+# This is ok.
+["03g", '-k1.1,1.0'],
+# This is equivalent to 3f.
+["03h", '-k1.1,1'],
+# This too, is equivalent to 3f.
+["03i", '-k1,1'],
+#
+["04a", '-nc', {IN=>"2\n11\n"}],
+["04b", '-n', {IN=>"11\n2\n"}, {OUT=>"2\n11\n"}],
+["04c", '-k1n', {IN=>"11\n2\n"}, {OUT=>"2\n11\n"}],
+["04d", '-k1', {IN=>"11\n2\n"}, {OUT=>"11\n2\n"}],
+["04e", '-k2', {IN=>"ignored B\nz-ig A\n"}, {OUT=>"z-ig A\nignored B\n"}],
+#
+["05a", '-k1,2', {IN=>"A B\nA A\n"}, {OUT=>"A A\nA B\n"}],
+["05b", '-k1,2', {IN=>"A B A\nA A Z\n"}, {OUT=>"A A Z\nA B A\n"}],
+["05c", qw(-k1 -k2), {IN=>"A B A\nA A Z\n"}, {OUT=>"A A Z\nA B A\n"}],
+["05d", '-k2,2', {IN=>"A B A\nA A Z\n"}, {OUT=>"A A Z\nA B A\n"}],
+["05e", '-k2,2', {IN=>"A B Z\nA A A\n"}, {OUT=>"A A A\nA B Z\n"}],
+["05f", '-k2,2', {IN=>"A B A\nA A Z\n"}, {OUT=>"A A Z\nA B A\n"}],
+#
+["06a", qw(-k 1,2), {IN=>"A B\nA A\n"}, {OUT=>"A A\nA B\n"}],
+["06b", qw(-k 1,2), {IN=>"A B A\nA A Z\n"}, {OUT=>"A A Z\nA B A\n"}],
+["06c", qw(-k 1 -k 2), {IN=>"A B A\nA A Z\n"}, {OUT=>"A A Z\nA B A\n"}],
+["06d", qw(-k 2,2), {IN=>"A B A\nA A Z\n"}, {OUT=>"A A Z\nA B A\n"}],
+["06e", qw(-k 2,2), {IN=>"A B Z\nA A A\n"}, {OUT=>"A A A\nA B Z\n"}],
+["06f", qw(-k 2,2), {IN=>"A B A\nA A Z\n"}, {OUT=>"A A Z\nA B A\n"}],
+#
+["07a", qw(-k 2,3), {IN=>"9 a b\n7 a a\n"}, {OUT=>"7 a a\n9 a b\n"}],
+["07b", qw(-k 2,3), {IN=>"a a b\nz a a\n"}, {OUT=>"z a a\na a b\n"}],
+["07c", qw(-k 2,3), {IN=>"y k b\nz k a\n"}, {OUT=>"z k a\ny k b\n"}],
+["07d", qw(+1 -3), {IN=>"y k b\nz k a\n"}, {OUT=>"z k a\ny k b\n"}],
+#
+# report an error for `.' without following char spec
+["08a", qw(-k 2.,3), {EXIT=>2},
+ {ERR=>"$prog: invalid number after `.': invalid count at start of `,3'\n"}],
+# report an error for `,' without following POS2
+["08b", qw(-k 2,), {EXIT=>2},
+ {ERR=>"$prog: invalid number after `,': invalid count at start of `'\n"}],
+#
+# Test new -g option.
+["09a", '-g', {IN=>"1e2\n2e1\n"}, {OUT=>"2e1\n1e2\n"}],
+# Make sure -n works how we expect.
+["09b", '-n', {IN=>"1e2\n2e1\n"}, {OUT=>"1e2\n2e1\n"}],
+["09c", '-n', {IN=>"2e1\n1e2\n"}, {OUT=>"1e2\n2e1\n"}],
+["09d", '-k2g', {IN=>"a 1e2\nb 2e1\n"}, {OUT=>"b 2e1\na 1e2\n"}],
+#
+# Bug reported by Roger Peel <R.Peel@ee.surrey.ac.uk>
+["10a", qw(-t : -k 2.2,2.2), {IN=>":ba\n:ab\n"}, {OUT=>":ba\n:ab\n"}],
+# Equivalent to above, but using obsolescent `+pos -pos' option syntax.
+["10b", qw(-t : +1.1 -1.2), {IN=>":ba\n:ab\n"}, {OUT=>":ba\n:ab\n"}],
+#
+# The same as the preceding two, but with input lines reversed.
+["10c", qw(-t : -k 2.2,2.2), {IN=>":ab\n:ba\n"}, {OUT=>":ba\n:ab\n"}],
+# Equivalent to above, but using obsolescent `+pos -pos' option syntax.
+["10d", qw(-t : +1.1 -1.2), {IN=>":ab\n:ba\n"}, {OUT=>":ba\n:ab\n"}],
+# Try without -t...
+# But note that we have to count the delimiting space at the beginning
+# of each field that has it.
+["10a0", qw(-k 2.3,2.3), {IN=>"z ba\nz ab\n"}, {OUT=>"z ba\nz ab\n"}],
+["10a1", qw(-k 1.2,1.2), {IN=>"ba\nab\n"}, {OUT=>"ba\nab\n"}],
+["10a2", qw(-b -k 2.2,2.2), {IN=>"z ba\nz ab\n"}, {OUT=>"z ba\nz ab\n"}],
+#
+# An even simpler example demonstrating the bug.
+["10e", qw(-k 1.2,1.2), {IN=>"ab\nba\n"}, {OUT=>"ba\nab\n"}],
+#
+# The way sort works on these inputs (10f and 10g) seems wrong to me.
+# See http://git.sv.gnu.org/gitweb/?p=coreutils.git;a=commitdiff;h=3c467c0d223
+# POSIX doesn't seem to say one way or the other, but that's the way all
+# other sort implementations work.
+["10f", qw(-t : -k 1.3,1.3), {IN=>":ab\n:ba\n"}, {OUT=>":ba\n:ab\n"}],
+["10g", qw(-k 1.4,1.4), {IN=>"a ab\nb ba\n"}, {OUT=>"b ba\na ab\n"}],
+#
+# Exercise bug re using -b to skip trailing blanks.
+["11a", qw(-t: -k1,1b -k2,2), {IN=>"a\t:a\na :b\n"}, {OUT=>"a\t:a\na :b\n"}],
+["11b", qw(-t: -k1,1b -k2,2), {IN=>"a :b\na\t:a\n"}, {OUT=>"a\t:a\na :b\n"}],
+["11c", qw(-t: -k2,2b -k3,3), {IN=>"z:a\t:a\na :b\n"}, {OUT=>"z:a\t:a\na :b\n"}],
+# Before 1.22m, the first key comparison reported equality.
+# With 1.22m, they compare different: "a" sorts before "a\n",
+# and the second key spec isn't even used.
+["11d", qw(-t: -k2,2b -k3,3), {IN=>"z:a :b\na\t:a\n"}, {OUT=>"a\t:a\nz:a :b\n"}],
+#
+# Exercise bug re comparing `-' and integers.
+["12a", qw(-n -t: +1), {IN=>"a:1\nb:-\n"}, {OUT=>"b:-\na:1\n"}],
+["12b", qw(-n -t: +1), {IN=>"b:-\na:1\n"}, {OUT=>"b:-\na:1\n"}],
+# Try some other (e.g. `X') invalid character.
+["12c", qw(-n -t: +1), {IN=>"a:1\nb:X\n"}, {OUT=>"b:X\na:1\n"}],
+["12d", qw(-n -t: +1), {IN=>"b:X\na:1\n"}, {OUT=>"b:X\na:1\n"}],
+# From Karl Heuer
+["13a", '+0.1n', {IN=>"axx\nb-1\n"}, {OUT=>"b-1\naxx\n"}],
+["13b", '+0.1n', {IN=>"b-1\naxx\n"}, {OUT=>"b-1\naxx\n"}],
+#
+# From Carl Johnson <carlj@cjlinux.home.org>
+["14a", qw(-d -u), {IN=>"mal\nmal-\nmala\n"}, {OUT=>"mal\nmala\n"}],
+# Be sure to fix the (translate && ignore) case in keycompare.
+["14b", qw(-f -d -u), {IN=>"mal\nmal-\nmala\n"}, {OUT=>"mal\nmala\n"}],
+#
+# Experiment with -i.
+["15a", qw(-i -u), {IN=>"a\na\1\n"}, {OUT=>"a\n"}],
+["15b", qw(-i -u), {IN=>"a\n\1a\n"}, {OUT=>"a\n"}],
+["15c", qw(-i -u), {IN=>"a\1\na\n"}, {OUT=>"a\1\n"}],
+["15d", qw(-i -u), {IN=>"\1a\na\n"}, {OUT=>"\1a\n"}],
+["15e", qw(-i -u), {IN=>"a\n\1\1\1\1\1a\1\1\1\1\n"}, {OUT=>"a\n"}],
+
+# From Erick Branderhorst -- fixed around 1.19e
+["16a", '-f',
+ {IN=>"éminence\nüberhaupt\n's-Gravenhage\naëroclub\nAag\naagtappels\n"},
+ {OUT=>"'s-Gravenhage\nAag\naagtappels\naëroclub\néminence\nüberhaupt\n"}],
+
+# This provokes a one-byte memory overrun of a malloc'd block for versions
+# of sort from textutils-1.19p and before.
+["17", '-c', {IN=>"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"}],
+
+# POSIX says -n no longer implies -b, so here we're comparing ` 9' and `10'.
+["18a", '-k1.1,1.2n', {IN=>" 901\n100\n"}, {OUT=>" 901\n100\n"}],
+
+# Just like above, because the global `-b' has no effect on the
+# key specifier when a key-specific option (`n' in this case) is used.
+["18b", qw(-b -k1.1,1.2n), {IN=>" 901\n100\n"}, {OUT=>" 901\n100\n"}],
+
+# Here we're comparing ` 90' and `10', because the `b' on the key-end specifier
+# makes sort ignore leading blanks when determining that key's *end*.
+["18c", '-k1.1,1.2nb', {IN=>" 901\n100\n"}, {OUT=>"100\n 901\n"}],
+
+# Here we're comparing `9' and `10', because the `b' on the key-start specifier
+# makes sort ignore leading blanks when determining that key's *start*.
+["18d", '-k1.1b,1.2n', {IN=>" 901\n100\n"}, {OUT=>" 901\n100\n"}],
+
+# This compares `90' and `10', as it ignores leading blanks for both
+# key start and key end.
+["18e", qw(-nb -k1.1,1.2), {IN=>" 901\n100\n"}, {OUT=>"100\n 901\n"}],
+
+# This looks odd, but works properly -- 2nd keyspec is never
+# used because all lines are different.
+["19a", qw(+0 +1nr), {IN=>"b 2\nb 1\nb 3\n"}, {OUT=>"b 1\nb 2\nb 3\n"}],
+
+# The test *intended* by the author of the above, but using the
+# more-intuitive POSIX-style -k options.
+["19b", qw(-k1,1 -k2nr), {IN=>"b 2\nb 1\nb 3\n"}, {OUT=>"b 3\nb 2\nb 1\n"}],
+
+# This test failed when sort-1.22 was compiled on a Next x86 system
+# without optimization. Without optimization gcc uses the buggy version
+# of memcmp in the Next C library. With optimization, gcc uses its
+# (working) builtin version. Test case form William Lewis.
+["20a", '',
+ {IN=>"_________U__free\n_________U__malloc\n_________U__abort\n_________U__memcpy\n_________U__memset\n_________U_dyld_stub_binding_helper\n_________U__malloc\n_________U___iob\n_________U__abort\n_________U__fprintf\n"},
+ {OUT=>"_________U___iob\n_________U__abort\n_________U__abort\n_________U__fprintf\n_________U__free\n_________U__malloc\n_________U__malloc\n_________U__memcpy\n_________U__memset\n_________U_dyld_stub_binding_helper\n"}],
+
+# Demonstrate that folding changes the ordering of e.g. A, a, and _
+# because while they normally (in the C locale) collate like A, _, a,
+# when using -f, `a' is compared as if it were `A'.
+["21a", '', {IN=>"A\na\n_\n"}, {OUT=>"A\n_\na\n"}],
+["21b", '-f', {IN=>"A\na\n_\n"}, {OUT=>"A\na\n_\n"}],
+["21c", '-f', {IN=>"a\nA\n_\n"}, {OUT=>"A\na\n_\n"}],
+["21d", '-f', {IN=>"_\na\nA\n"}, {OUT=>"A\na\n_\n"}],
+["21e", '-f', {IN=>"a\n_\nA\n"}, {OUT=>"A\na\n_\n"}],
+["21f", '-fs', {IN=>"A\na\n_\n"}, {OUT=>"A\na\n_\n"}],
+["21g", '-fu', {IN=>"a\n_\n"}, {OUT=>"a\n_\n"}],
+
+# This test failed until 1.22f. From Zvi Har'El.
+["22a", qw(-k 2,2fd -k 1,1r), {IN=>"3 b\n4 B\n"}, {OUT=>"4 B\n3 b\n"}],
+["22b", qw(-k 2,2d -k 1,1r), {IN=>"3 b\n4 b\n"}, {OUT=>"4 b\n3 b\n"}],
+
+["no-file1", 'no-file', {EXIT=>2}, {ERR=>$no_file}],
+# This test failed until 1.22f. Sort didn't give an error.
+# From Will Edgington.
+["o-no-file1", qw(-o no-file no-file), {EXIT=>2}, {ERR=>$no_file}],
+
+["create-empty", qw(-o no/such/file /dev/null), {EXIT=>2},
+ {ERR=>"$prog: open failed: no/such/file: No such file or directory\n"}],
+
+# From Paul Eggert. This was fixed in textutils-1.22k.
+["neg-nls", '-n', {IN=>"-1\n-9\n"}, {OUT=>"-9\n-1\n"}],
+
+# From Paul Eggert. This was fixed in textutils-1.22m.
+# The bug was visible only when using the internationalized sorting code
+# (i.e., not when configured with --disable-nls).
+["nul-nls", '', {IN=>"\0b\n\0a\n"}, {OUT=>"\0a\n\0b\n"}],
+
+# Paul Eggert wrote:
+# I tested the revised `sort' against Solaris `sort', and found a
+# discrepancy that turns out to be a longstanding bug in GNU sort.
+# POSIX.2 specifies that a newline is part of the input line, and should
+# be significant during comparison; but with GNU sort the newline is
+# insignificant. Here is an example of the bug:
+#
+# $ od -c t
+# 0000000 \n \t \n
+# 0000003
+# $ sort t | od -c
+# 0000000 \n \t \n
+# 0000003
+#
+# The correct output of the latter command should be
+#
+# 0000000 \t \n \n
+# 0000003
+#
+# because \t comes before \n in the collating sequence, and the trailing
+# \n's are part of the input line.
+["use-nl", '', {IN=>"\n\t\n"}, {OUT=>"\n\t\n"}],
+
+# Specifying two -o options should evoke a failure
+["o2", qw(-o x -o y), {EXIT=>2},
+ {ERR=>"foo\n"}, {ERR_SUBST => 's/^$prog: .*/foo/'}],
+
+# Specifying incompatible options should evoke a failure.
+["incompat1", '-in', {EXIT=>2},
+ {ERR=>"$prog: options `-in' are incompatible\n"}],
+["incompat2", '-fR', {EXIT=>2},
+ {ERR=>"$prog: options `-fR' are incompatible\n"}],
+["incompat3", '-dfgiMnR', {EXIT=>2},
+ {ERR=>"$prog: options `-dfgMnR' are incompatible\n"}],
+["incompat4", qw(-c -o /dev/null), {EXIT=>2},
+ {ERR=>"$prog: options `-co' are incompatible\n"}],
+["incompat5", qw(-C -o /dev/null), {EXIT=>2},
+ {ERR=>"$prog: options `-Co' are incompatible\n"}],
+["incompat6", '-cC', {EXIT=>2},
+ {ERR=>"$prog: options `-cC' are incompatible\n"}],
+["incompat7", qw(--sort=random -n), {EXIT=>2},
+ {ERR=>"$prog: options `-nR' are incompatible\n"}],
+
+# -t '\0' is accepted, as of coreutils-5.0.91
+['nul-tab', "-k2,2 -t '\\0'",
+ {IN=>"a\0z\01\nb\0y\02\n"}, {OUT=>"b\0y\02\na\0z\01\n"}],
+
+["bigfield", qw(-k 340282366920938463463374607431768211456),
+ {IN=>"2\n1\n"}, {OUT=>"1\n2\n"}],
+
+# Using an old-style key-specifying option like +1 with an invalid
+# ordering-option character would cause sort to try to free an invalid
+# (non-malloc'd) pointer. This bug affects coreutils-6.5 through 6.9.
+['obs-inval', '+1x', {EXIT=>2},
+ {ERR=>"foo\n"}, {ERR_SUBST => 's/^$prog: .*/foo/'}],
+
+# Exercise the code that enlarges the line buffer. See the thread here:
+# http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/11006
+['realloc-buf', '-S1', {IN=>'a'x4000 ."\n"}, {OUT=>'a'x4000 ."\n"}],
+
+["sort-numeric", '--sort=numeric', {IN=>".01\n0\n"}, {OUT=>"0\n.01\n"}],
+["sort-gennum", '--sort=general-numeric',
+ {IN=>"1e2\n2e1\n"}, {OUT=>"2e1\n1e2\n"}],
+);
+
+# Add _POSIX2_VERSION=199209 to the environment of each test
+# that uses an old-style option like +1.
+foreach my $t (@Tests)
+ {
+ foreach my $e (@$t)
+ {
+ !ref $e && $e =~ /\+\d/
+ and push (@$t, {ENV=>'_POSIX2_VERSION=199209'}), last;
+ }
+ }
+
+@Tests = triple_test \@Tests;
+
+my $save_temps = $ENV{DEBUG};
+my $verbose = $ENV{VERBOSE};
+
+my $fail = run_tests ($prog, $prog, \@Tests, $save_temps, $verbose);
+exit $fail;
+EOF
diff --git a/tests/sort/Test.pm b/tests/sort/Test.pm
deleted file mode 100644
index 0462973c0..000000000
--- a/tests/sort/Test.pm
+++ /dev/null
@@ -1,303 +0,0 @@
-# -*-perl-*-
-# Test "sort".
-
-# Copyright (C) 1996-1999, 2001-2008 Free Software Foundation, Inc.
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-package Test;
-require 5.002;
-use strict;
-
-# Tell sort to accept old-style options like `+1'.
-$Test::env_default = ['_POSIX2_VERSION=199209'];
-
-my @tv = (
-#test options input expected-output expected-return-code
-#
-["n1", '-n', ".01\n0\n", "0\n.01\n", 0],
-["n2", '-n', ".02\n.01\n", ".01\n.02\n", 0],
-["n3", '-n', ".02\n.00\n", ".00\n.02\n", 0],
-["n4", '-n', ".02\n.000\n", ".000\n.02\n", 0],
-["n5", '-n', ".021\n.029\n", ".021\n.029\n", 0],
-
-["n6", '-n', ".02\n.0*\n", ".0*\n.02\n", 0],
-["n7", '-n', ".02\n.*\n", ".*\n.02\n", 0],
-["n8a", '-s -n -k1,1', ".0a\n.0b\n", ".0a\n.0b\n", 0],
-["n8b", '-s -n -k1,1', ".0b\n.0a\n", ".0b\n.0a\n", 0],
-["n9a", '-s -n -k1,1', ".000a\n.000b\n", ".000a\n.000b\n", 0],
-["n9b", '-s -n -k1,1', ".000b\n.000a\n", ".000b\n.000a\n", 0],
-["n10a", '-s -n -k1,1', ".00a\n.000b\n", ".00a\n.000b\n", 0],
-["n10b", '-s -n -k1,1', ".00b\n.000a\n", ".00b\n.000a\n", 0],
-["n11a", '-s -n -k1,1', ".01a\n.010\n", ".01a\n.010\n", 0],
-["n11b", '-s -n -k1,1', ".010\n.01a\n", ".010\n.01a\n", 0],
-
-["01a", '', "A\nB\nC\n", "A\nB\nC\n", 0],
-#
-["02a", '-c', "A\nB\nC\n", '', 0],
-["02b", '-c', "A\nC\nB\n", '', 1],
-["02c", '-c -k1,1', "a\na b\n", '', 0],
-["02d", '-C', "A\nB\nC\n", '', 0],
-["02e", '-C', "A\nC\nB\n", '', 1],
-# This should fail because there are duplicate keys
-["02m", '-cu', "A\nA\n", '', 1],
-["02n", '-cu', "A\nB\n", '', 0],
-["02o", '-cu', "A\nB\nB\n", '', 1],
-["02p", '-cu', "B\nA\nB\n", '', 1],
-#
-["03a", '-k1', "B\nA\n", "A\nB\n", 0],
-["03b", '-k1,1', "B\nA\n", "A\nB\n", 0],
-["03c", '-k1 -k2', "A b\nA a\n", "A a\nA b\n", 0],
-# Fail with a diagnostic when -k specifies field == 0.
-["03d", '-k0', "", "", 2],
-# Fail with a diagnostic when -k specifies character == 0.
-["03e", '-k1.0', "", "", 2],
-["03f", '-k1.1,-k0', "", "", 2],
-# This is ok.
-["03g", '-k1.1,1.0', "", "", 0],
-# This is equivalent to 3f.
-["03h", '-k1.1,1', "", "", 0],
-# This too, is equivalent to 3f.
-["03i", '-k1,1', "", "", 0],
-#
-["04a", '-nc', "2\n11\n", "", 0],
-["04b", '-n', "11\n2\n", "2\n11\n", 0],
-["04c", '-k1n', "11\n2\n", "2\n11\n", 0],
-["04d", '-k1', "11\n2\n", "11\n2\n", 0],
-["04e", '-k2', "ignored B\nz-ig A\n", "z-ig A\nignored B\n", 0],
-#
-["05a", '-k1,2', "A B\nA A\n", "A A\nA B\n", 0],
-["05b", '-k1,2', "A B A\nA A Z\n", "A A Z\nA B A\n", 0],
-["05c", '-k1 -k2', "A B A\nA A Z\n", "A A Z\nA B A\n", 0],
-["05d", '-k2,2', "A B A\nA A Z\n", "A A Z\nA B A\n", 0],
-["05e", '-k2,2', "A B Z\nA A A\n", "A A A\nA B Z\n", 0],
-["05f", '-k2,2', "A B A\nA A Z\n", "A A Z\nA B A\n", 0],
-#
-["06a", '-k 1,2', "A B\nA A\n", "A A\nA B\n", 0],
-["06b", '-k 1,2', "A B A\nA A Z\n", "A A Z\nA B A\n", 0],
-["06c", '-k 1 -k 2', "A B A\nA A Z\n", "A A Z\nA B A\n", 0],
-["06d", '-k 2,2', "A B A\nA A Z\n", "A A Z\nA B A\n", 0],
-["06e", '-k 2,2', "A B Z\nA A A\n", "A A A\nA B Z\n", 0],
-["06f", '-k 2,2', "A B A\nA A Z\n", "A A Z\nA B A\n", 0],
-#
-["07a", '-k 2,3', "9 a b\n7 a a\n", "7 a a\n9 a b\n", 0],
-["07b", '-k 2,3', "a a b\nz a a\n", "z a a\na a b\n", 0],
-["07c", '-k 2,3', "y k b\nz k a\n", "z k a\ny k b\n", 0],
-["07d", '+1 -3', "y k b\nz k a\n", "z k a\ny k b\n", 0],
-#
-# report an error for `.' without following char spec
-["08a", '-k 2.,3', "", "", 2],
-# report an error for `,' without following POS2
-["08b", '-k 2,', "", "", 2],
-#
-# Test new -g option.
-["09a", '-g', "1e2\n2e1\n", "2e1\n1e2\n", 0],
-# Make sure -n works how we expect.
-["09b", '-n', "1e2\n2e1\n", "1e2\n2e1\n", 0],
-["09c", '-n', "2e1\n1e2\n", "1e2\n2e1\n", 0],
-["09d", '-k2g', "a 1e2\nb 2e1\n", "b 2e1\na 1e2\n", 0],
-#
-# Bug reported by Roger Peel <R.Peel@ee.surrey.ac.uk>
-["10a", '-t : -k 2.2,2.2', ":ba\n:ab\n", ":ba\n:ab\n", 0],
-# Equivalent to above, but using obsolescent `+pos -pos' option syntax.
-["10b", '-t : +1.1 -1.2', ":ba\n:ab\n", ":ba\n:ab\n", 0],
-#
-# The same as the preceding two, but with input lines reversed.
-["10c", '-t : -k 2.2,2.2', ":ab\n:ba\n", ":ba\n:ab\n", 0],
-# Equivalent to above, but using obsolescent `+pos -pos' option syntax.
-["10d", '-t : +1.1 -1.2', ":ab\n:ba\n", ":ba\n:ab\n", 0],
-# Try without -t...
-# But note that we have to count the delimiting space at the beginning
-# of each field that has it.
-["10a0", '-k 2.3,2.3', "z ba\nz ab\n", "z ba\nz ab\n", 0],
-["10a1", '-k 1.2,1.2', "ba\nab\n", "ba\nab\n", 0],
-["10a2", '-b -k 2.2,2.2', "z ba\nz ab\n", "z ba\nz ab\n", 0],
-#
-# An even simpler example demonstrating the bug.
-["10e", '-k 1.2,1.2', "ab\nba\n", "ba\nab\n", 0],
-#
-# The way sort works on these inputs (10f and 10g) seems wrong to me.
-# See http://git.sv.gnu.org/gitweb/?p=coreutils.git;a=commitdiff;h=3c467c0d223
-# POSIX doesn't seem to say one way or the other, but that's the way all
-# other sort implementations work.
-["10f", '-t : -k 1.3,1.3', ":ab\n:ba\n", ":ba\n:ab\n", 0],
-["10g", '-k 1.4,1.4', "a ab\nb ba\n", "b ba\na ab\n", 0],
-#
-# Exercise bug re using -b to skip trailing blanks.
-["11a", '-t: -k1,1b -k2,2', "a\t:a\na :b\n", "a\t:a\na :b\n", 0],
-["11b", '-t: -k1,1b -k2,2', "a :b\na\t:a\n", "a\t:a\na :b\n", 0],
-["11c", '-t: -k2,2b -k3,3', "z:a\t:a\na :b\n", "z:a\t:a\na :b\n", 0],
-# Before 1.22m, the first key comparison reported equality.
-# With 1.22m, they compare different: "a" sorts before "a\n",
-# and the second key spec isn't even used.
-["11d", '-t: -k2,2b -k3,3', "z:a :b\na\t:a\n", "a\t:a\nz:a :b\n", 0],
-#
-# Exercise bug re comparing `-' and integers.
-["12a", '-n -t: +1', "a:1\nb:-\n", "b:-\na:1\n", 0],
-["12b", '-n -t: +1', "b:-\na:1\n", "b:-\na:1\n", 0],
-# Try some other (e.g. `X') invalid character.
-["12c", '-n -t: +1', "a:1\nb:X\n", "b:X\na:1\n", 0],
-["12d", '-n -t: +1', "b:X\na:1\n", "b:X\na:1\n", 0],
-# From Karl Heuer
-["13a", '+0.1n', "axx\nb-1\n", "b-1\naxx\n", 0],
-["13b", '+0.1n', "b-1\naxx\n", "b-1\naxx\n", 0],
-#
-# From Carl Johnson <carlj@cjlinux.home.org>
-["14a", '-d -u', "mal\nmal-\nmala\n", "mal\nmala\n", 0],
-# Be sure to fix the (translate && ignore) case in keycompare.
-["14b", '-f -d -u', "mal\nmal-\nmala\n", "mal\nmala\n", 0],
-#
-# Experiment with -i.
-["15a", '-i -u', "a\na\1\n", "a\n", 0],
-["15b", '-i -u', "a\n\1a\n", "a\n", 0],
-["15c", '-i -u', "a\1\na\n", "a\1\n", 0],
-["15d", '-i -u', "\1a\na\n", "\1a\n", 0],
-["15e", '-i -u', "a\n\1\1\1\1\1a\1\1\1\1\n", "a\n", 0],
-
-# From Erick Branderhorst -- fixed around 1.19e
-["16a", '-f',
- "éminence\nüberhaupt\n's-Gravenhage\naëroclub\nAag\naagtappels\n",
- "'s-Gravenhage\nAag\naagtappels\naëroclub\néminence\nüberhaupt\n",
- 0],
-
-# This provokes a one-byte memory overrun of a malloc'd block for versions
-# of sort from textutils-1.19p and before.
-["17", '-c', "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n", "", 0],
-
-# POSIX says -n no longer implies -b, so here we're comparing ` 9' and `10'.
-["18a", '-k1.1,1.2n', " 901\n100\n", " 901\n100\n", 0],
-
-# Just like above, because the global `-b' has no effect on the
-# key specifier when a key-specific option (`n' in this case) is used.
-["18b", '-b -k1.1,1.2n', " 901\n100\n", " 901\n100\n", 0],
-
-# Here we're comparing ` 90' and `10', because the `b' on the key-end specifier
-# makes sort ignore leading blanks when determining that key's *end*.
-["18c", '-k1.1,1.2nb', " 901\n100\n", "100\n 901\n", 0],
-
-# Here we're comparing `9' and `10', because the `b' on the key-start specifier
-# makes sort ignore leading blanks when determining that key's *start*.
-["18d", '-k1.1b,1.2n', " 901\n100\n", " 901\n100\n", 0],
-
-# This compares `90' and `10', as it ignores leading blanks for both
-# key start and key end.
-["18e", '-nb -k1.1,1.2', " 901\n100\n", "100\n 901\n", 0],
-
-# This looks odd, but works properly -- 2nd keyspec is never
-# used because all lines are different.
-["19a", '+0 +1nr', "b 2\nb 1\nb 3\n", "b 1\nb 2\nb 3\n", 0],
-
-# The test *intended* by the author of the above, but using the
-# more-intuitive POSIX-style -k options.
-["19b", '-k1,1 -k2nr', "b 2\nb 1\nb 3\n", "b 3\nb 2\nb 1\n", 0],
-
-# This test failed when sort-1.22 was compiled on a Next x86 system
-# without optimization. Without optimization gcc uses the buggy version
-# of memcmp in the Next C library. With optimization, gcc uses its
-# (working) builtin version. Test case form William Lewis.
-["20a", '',
- "_________U__free\n_________U__malloc\n_________U__abort\n_________U__memcpy\n_________U__memset\n_________U_dyld_stub_binding_helper\n_________U__malloc\n_________U___iob\n_________U__abort\n_________U__fprintf\n",
- "_________U___iob\n_________U__abort\n_________U__abort\n_________U__fprintf\n_________U__free\n_________U__malloc\n_________U__malloc\n_________U__memcpy\n_________U__memset\n_________U_dyld_stub_binding_helper\n",
- 0],
-
-# Demonstrate that folding changes the ordering of e.g. A, a, and _
-# because while they normally (in the C locale) collate like A, _, a,
-# when using -f, `a' is compared as if it were `A'.
-["21a", '', "A\na\n_\n", "A\n_\na\n", 0],
-["21b", '-f', "A\na\n_\n", "A\na\n_\n", 0],
-["21c", '-f', "a\nA\n_\n", "A\na\n_\n", 0],
-["21d", '-f', "_\na\nA\n", "A\na\n_\n", 0],
-["21e", '-f', "a\n_\nA\n", "A\na\n_\n", 0],
-["21f", '-fs', "A\na\n_\n", "A\na\n_\n", 0],
-["21g", '-fu', "a\n_\n", "a\n_\n", 0],
-
-# This test failed until 1.22f. From Zvi Har'El.
-["22a", '-k 2,2fd -k 1,1r', "3 b\n4 B\n", "4 B\n3 b\n", 0],
-["22b", '-k 2,2d -k 1,1r', "3 b\n4 b\n", "4 b\n3 b\n", 0],
-
-["no-file1", 'no-file', {}, '', 2],
-# This test failed until 1.22f. Sort didn't give an error.
-# From Will Edgington.
-["o-no-file1", '-o no-such-file no-such-file', {}, '', 2],
-
-["create-empty", '-o no/such/file /dev/null', {}, '', 2],
-
-# From Paul Eggert. This was fixed in textutils-1.22k.
-["neg-nls", '-n', "-1\n-9\n", "-9\n-1\n", 0],
-
-# From Paul Eggert. This was fixed in textutils-1.22m.
-# The bug was visible only when using the internationalized sorting code
-# (i.e., not when configured with --disable-nls).
-["nul-nls", '', "\0b\n\0a\n", "\0a\n\0b\n", 0],
-
-# Paul Eggert wrote:
-# I tested the revised `sort' against Solaris `sort', and found a
-# discrepancy that turns out to be a longstanding bug in GNU sort.
-# POSIX.2 specifies that a newline is part of the input line, and should
-# be significant during comparison; but with GNU sort the newline is
-# insignificant. Here is an example of the bug:
-#
-# $ od -c t
-# 0000000 \n \t \n
-# 0000003
-# $ sort t | od -c
-# 0000000 \n \t \n
-# 0000003
-#
-# The correct output of the latter command should be
-#
-# 0000000 \t \n \n
-# 0000003
-#
-# because \t comes before \n in the collating sequence, and the trailing
-# \n's are part of the input line.
-["use-nl", '', "\n\t\n", "\n\t\n", 0],
-
-# Specifying two -o options should evoke a failure
-["o2", '-o x -o y', '', '', 2],
-
-# Specifying incompatible options should evoke a failure.
-["incompat1", '-in', '', '', 2],
-["incompat2", '-fR', '', '', 2],
-["incompat3", '-dfgiMnR', '', '', 2],
-["incompat4", '-c -o /dev/null', '', '', 2],
-["incompat5", '-C -o /dev/null', '', '', 2],
-["incompat6", '-cC', '', '', 2],
-["incompat7", '--sort=random -n', '', '', 2],
-
-# -t '\0' is accepted, as of coreutils-5.0.91
-['nul-tab', "-k2,2 -t '\\0'", "a\0z\01\nb\0y\02\n", "b\0y\02\na\0z\01\n", 0],
-
-["bigfield", '-k 340282366920938463463374607431768211456',
- "2\n1\n", "1\n2\n", 0],
-
-# Using an old-style key-specifying option like +1 with an invalid
-# ordering-option character would cause sort to try to free an invalid
-# (non-malloc'd) pointer. This bug affects coreutils-6.5 through 6.9.
-['obs-inval', '+1x', '', '', 2],
-
-# Exercise the code that enlarges the line buffer. See the thread here:
-# http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/11006
-['realloc-buf', '-S1', 'a'x4000 ."\n", 'a'x4000 ."\n", 0],
-
-["sort-numeric", '--sort=numeric', ".01\n0\n", "0\n.01\n", 0],
-["sort-gennum", '--sort=general-numeric', "1e2\n2e1\n", "2e1\n1e2\n", 0],
-);
-
-sub test_vector
-{
- return @tv;
-}
-
-1;