4 # Copyright (C) 2008-2019 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
22 my $normalize_strerror = "s/': .*/'/";
24 # Turn off localization of executable's output.
25 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x
3;
28 # test name, options, input, expected output, expected return code
30 ['obs-plus-c1', '+2c', 'abcd', 'bcd', 0],
31 ['obs-plus-c2', '+8c', 'abcd', '', 0],
32 ['obs-c3', '-1c', 'abcd', 'd', 0],
33 ['obs-c4', '-9c', 'abcd', 'abcd', 0],
34 ['obs-c5', '-12c', 'x' . ('y' x
12) . 'z', ('y' x
11) . 'z', 0],
36 ['obs-l1', '-1l', 'x', 'x', 0],
37 ['obs-l2', '-1l', "x\ny\n", "y\n", 0],
38 ['obs-l3', '-1l', "x\ny", "y", 0],
39 ['obs-plus-l4', '+1l', "x\ny\n", "x\ny\n", 0],
40 ['obs-plus-l5', '+2l', "x\ny\n", "y\n", 0],
42 # Same as -l tests, but without the 'l'.
43 ['obs-1', '-1', 'x', 'x', 0],
44 ['obs-2', '-1', "x\ny\n", "y\n", 0],
45 ['obs-3', '-1', "x\ny", "y", 0],
46 ['obs-plus-4', '+1', "x\ny\n", "x\ny\n", 0],
47 ['obs-plus-5', '+2', "x\ny\n", "y\n", 0],
49 # This is equivalent to +10c
50 ['obs-plus-x1', '+c', 'x' . ('y' x
10) . 'z', 'yyz', 0],
51 # This is equivalent to +10l
52 ['obs-plus-x2', '+l', "x\n" . ("y\n" x
10) . 'z', "y\ny\nz", 0],
53 # With no number, this is like -10l
54 ['obs-l', '-l', "x\n" . ("y\n" x
10) . 'z', ("y\n" x
9) . 'z', 0],
56 ['obs-b', '-b', "x\n" x
(512 * 10 / 2 + 1), "x\n" x (512 * 10 / 2), 0],
58 ['err-1', '+cl', '', '', 1,
59 "$prog: cannot open '+cl' for reading: No such file or directory\n"],
61 ['err-2', '-cl', '', '', 1,
62 "$prog: invalid number of bytes: 'l'\n", $normalize_strerror],
64 ['err-3', '+2cz', '', '', 1,
65 "$prog: cannot open '+2cz' for reading: No such file or directory\n"],
67 # This should get 'tail: invalid option -- 2'
68 ['err-4', '-2cX', '', '', 1,
69 "$prog: option used in invalid context -- 2\n"],
71 # Since the number is larger than 2^64, this should provoke
72 # the diagnostic: 'tail: 99999999999999999999: invalid number of bytes'
73 # on all systems... probably, for now, maybe.
74 ['err-5', '-c99999999999999999999', '', '', 1,
75 "$prog: invalid number of bytes: '99999999999999999999'\n",
77 ['err-6', '-c --', '', '', 1,
78 "$prog: invalid number of bytes: '-'\n", $normalize_strerror],
81 ['minus-1', '-', '', '', 0],
82 ['minus-2', '-', "x\n" . ("y\n" x
10) . 'z', ("y\n" x
9) . 'z', 0],
84 ['c-2', '-c 2', "abcd\n", "d\n", 0],
85 ['c-2-minus', '-c 2 --', "abcd\n", "d\n", 0],
86 ['c2', '-c2', "abcd\n", "d\n", 0],
87 ['c2-minus', '-c2 --', "abcd\n", "d\n", 0],
89 ['n-1', '-n 10', "x\n" . ("y\n" x
10) . 'z', ("y\n" x
9) . 'z', 0],
90 ['n-2', '-n -10', "x\n" . ("y\n" x
10) . 'z', ("y\n" x
9) . 'z', 0],
91 ['n-3', '-n +10', "x\n" . ("y\n" x
10) . 'z', "y\ny\nz", 0],
93 # Accept +0 as synonym for +1.
94 ['n-4', '-n +0', "y\n" x
5, "y\n" x
5, 0],
95 ['n-4a', '-n +1', "y\n" x
5, "y\n" x
5, 0],
97 # Note that -0 is *not* a synonym for -1.
98 ['n-5', '-n -0', "y\n" x
5, '', 0],
99 ['n-5a', '-n -1', "y\n" x
5, "y\n", 0],
100 ['n-5b', '-n 0', "y\n" x
5, '', 0],
102 # With textutils-1.22, this failed.
103 ['f-pipe-1', '-f -n 1', "a\nb\n", "b\n", 0],
106 ['zero-1', '-z -n 1', "x\0y", "y", 0],
107 ['zero-2', '-z -n 2', "x\0y", "x\0y", 0],
114 my ($test_name, $flags, $in, $exp, $ret, $err_msg, $err_sub) = @
$t;
115 my $e = [$test_name, $flags, {IN
=>$in}, {OUT
=>$exp}];
117 and push @
$e, {EXIT
=>$ret}, {ERR
=>$err_msg}, {ERR_SUBST
=>$err_sub};
119 $test_name =~ /^minus-/
120 and push @
$e, {ENV
=>'_POSIX2_VERSION=199209'};
122 $test_name =~ /^(err-6|c-2)$/
123 and push @
$e, {ENV
=>'_POSIX2_VERSION=200112'};
125 $test_name =~ /^obs-plus-/
126 and push @
$e, {ENV
=>'_POSIX2_VERSION=200809'};
128 $test_name =~ /^f-pipe-/
129 and push @
$e, {ENV
=>'POSIXLY_CORRECT=1'};
134 @Tests = triple_test \
@Tests;
136 # If you run the minus* tests with a FILE arg they'd hang.
137 # If you run the err-1 or err-3 tests with a FILE, they'd misinterpret
138 # the arg unless we are using the obsolete form.
139 @Tests = grep { $_->[0] !~ /^(minus|err-[13])/ || $_->[0] =~ /\.[rp]$/ } @Tests;
141 # Using redirection or a file would make this hang.
142 @Tests = grep { $_->[0] !~ /^f-/ || $_->[0] =~ /\.p$/ } @Tests;
144 my $save_temps = $ENV{DEBUG
};
145 my $verbose = $ENV{VERBOSE
};
147 my $fail = run_tests
($prog, $prog, \
@Tests, $save_temps, $verbose);