tests: fix false failure with disabled SELinux support
[coreutils.git] / tests / misc / tail.pl
blobbc6e6d4af0867516f31699a8452b53a39c1e0076
1 #!/usr/bin/perl
2 # Test tail.
4 # Copyright (C) 2008-2013 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 <http://www.gnu.org/licenses/>.
19 use strict;
21 my $prog = 'tail';
22 my $normalize_filename = {ERR_SUBST => 's/^$prog: .*?:/$prog: -:/'};
24 # Turn off localization of executable's output.
25 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
27 my @tv = (
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: l: invalid number of bytes\n"],
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: 99999999999999999999: invalid number of bytes\n"],
76 ['err-6', '-c --', '', '', 1,
77 "$prog: -: invalid number of bytes\n", $normalize_filename],
79 # Same as -n 10
80 ['minus-1', '-', '', '', 0],
81 ['minus-2', '-', "x\n" . ("y\n" x 10) . 'z', ("y\n" x 9) . 'z', 0],
83 ['c-2', '-c 2', "abcd\n", "d\n", 0],
84 ['c-2-minus', '-c 2 --', "abcd\n", "d\n", 0],
85 ['c2', '-c2', "abcd\n", "d\n", 0],
86 ['c2-minus', '-c2 --', "abcd\n", "d\n", 0],
88 ['n-1', '-n 10', "x\n" . ("y\n" x 10) . 'z', ("y\n" x 9) . 'z', 0],
89 ['n-2', '-n -10', "x\n" . ("y\n" x 10) . 'z', ("y\n" x 9) . 'z', 0],
90 ['n-3', '-n +10', "x\n" . ("y\n" x 10) . 'z', "y\ny\nz", 0],
92 # Accept +0 as synonym for +1.
93 ['n-4', '-n +0', "y\n" x 5, "y\n" x 5, 0],
94 ['n-4a', '-n +1', "y\n" x 5, "y\n" x 5, 0],
96 # Note that -0 is *not* a synonym for -1.
97 ['n-5', '-n -0', "y\n" x 5, '', 0],
98 ['n-5a', '-n -1', "y\n" x 5, "y\n", 0],
99 ['n-5b', '-n 0', "y\n" x 5, '', 0],
101 # With textutils-1.22, this failed.
102 ['f-pipe-1', '-f -n 1', "a\nb\n", "b\n", 0],
105 my @Tests;
107 foreach my $t (@tv)
109 my ($test_name, $flags, $in, $exp, $ret, $err_msg) = @$t;
110 my $e = [$test_name, $flags, {IN=>$in}, {OUT=>$exp}];
111 $ret
112 and push @$e, {EXIT=>$ret}, {ERR=>$err_msg};
114 $test_name =~ /^(obs-plus-|minus-)/
115 and push @$e, {ENV=>'_POSIX2_VERSION=199209'};
117 $test_name =~ /^(err-6|c-2)$/
118 and push @$e, {ENV=>'_POSIX2_VERSION=200112'};
120 $test_name =~ /^f-pipe-/
121 and push @$e, {ENV=>'POSIXLY_CORRECT=1'};
123 push @Tests, $e;
126 @Tests = triple_test \@Tests;
128 # If you run the minus* tests with a FILE arg they'd hang.
129 # If you run the err-1 or err-3 tests with a FILE, they'd misinterpret
130 # the arg unless we are using the obsolete form.
131 @Tests = grep { $_->[0] !~ /^(minus|err-[13])/ || $_->[0] =~ /\.[rp]$/ } @Tests;
133 # Using redirection or a file would make this hang.
134 @Tests = grep { $_->[0] !~ /^f-/ || $_->[0] =~ /\.p$/ } @Tests;
136 my $save_temps = $ENV{DEBUG};
137 my $verbose = $ENV{VERBOSE};
139 my $fail = run_tests ($prog, $prog, \@Tests, $save_temps, $verbose);
140 exit $fail;