.
[coreutils.git] / tests / tail / Test.pm
blob8deb9eb7ab81dd721c001cfe5b621664b617a42e
1 package Test;
2 require 5.002;
3 use strict;
5 my @tv = (
6 # test name, options, input, expected output, expected return code
8 ['obs-c1', '+2c', 'abcd', 'bcd', 0],
9 ['obs-c2', '+8c', 'abcd', '', 0],
10 ['obs-c3', '-1c', 'abcd', 'd', 0],
11 ['obs-c4', '-9c', 'abcd', 'abcd', 0],
12 ['obs-c5', '-12c', 'x' . ('y' x 12) . 'z', ('y' x 11) . 'z', 0],
15 ['obs-l1', '-1l', 'x', 'x', 0],
16 ['obs-l2', '-1l', "x\ny\n", "y\n", 0],
17 ['obs-l3', '-1l', "x\ny", "y", 0],
18 ['obs-l4', '+1l', "x\ny\n", "x\ny\n", 0],
19 ['obs-l5', '+2l', "x\ny\n", "y\n", 0],
21 # Same as -l tests, but without the `l'.
22 ['obs-1', '-1', 'x', 'x', 0],
23 ['obs-2', '-1', "x\ny\n", "y\n", 0],
24 ['obs-3', '-1', "x\ny", "y", 0],
25 ['obs-4', '+1', "x\ny\n", "x\ny\n", 0],
26 ['obs-5', '+2', "x\ny\n", "y\n", 0],
28 # This is equivalent to +10c
29 ['obsx-1', '+c', 'x' . ('y' x 10) . 'z', 'yyz', 0],
30 # This is equivalent to +10l
31 ['obsx-2', '+l', "x\n" . ("y\n" x 10) . 'z', "y\ny\nz", 0],
32 # With no number, this is like -10l
33 ['obs-l', '-l', "x\n" . ("y\n" x 10) . 'z', ("y\n" x 9) . 'z', 0],
35 ['obs-b', '-b', "x\n" x (512 * 10 / 2 + 1), "x\n" x (512 * 10 / 2), 0],
37 # This should get
38 # `tail: cannot open `+cl' for reading: No such file or directory'
39 ['err-1', '+cl', '', '', 1],
41 # This should get `tail: l: invalid number of bytes'
42 ['err-2', '-cl', '', '', 1],
44 # This should get
45 # `tail: cannot open `+2cz' for reading: No such file or directory'
46 ['err-3', '+2cz', '', '', 1],
48 # This should get `tail: invalid option -- 2'
49 ['err-4', '-2cX', '', '', 1],
51 # Since the number is larger than 2^64, this should provoke
52 # the diagnostic: `tail: 99999999999999999999: invalid number of bytes'
53 # on all systems... probably, for now, maybe.
54 ['err-5', '-c99999999999999999999', '', '', 1],
55 ['err-6', '-c', '', '', 1],
57 # Same as -n 10
58 ['minus-1', '-', '', '', 0],
59 ['minus-2', '-', "x\n" . ("y\n" x 10) . 'z', ("y\n" x 9) . 'z', 0],
61 ['n-1', '-n 10', "x\n" . ("y\n" x 10) . 'z', ("y\n" x 9) . 'z', 0],
62 ['n-2', '-n -10', "x\n" . ("y\n" x 10) . 'z', ("y\n" x 9) . 'z', 0],
63 ['n-3', '-n +10', "x\n" . ("y\n" x 10) . 'z', "y\ny\nz", 0],
65 # Accept +0 as synonym for +1.
66 ['n-4', '-n +0', "y\n" x 5, "y\n" x 5, 0],
67 ['n-4a', '-n +1', "y\n" x 5, "y\n" x 5, 0],
69 # Note that -0 is *not* a synonym for -1.
70 ['n-5', '-n -0', "y\n" x 5, '', 0],
71 ['n-5a', '-n -1', "y\n" x 5, "y\n", 0],
72 ['n-5b', '-n 0', "y\n" x 5, '', 0],
74 # With textutils-1.22, this failed.
75 ['f-1', '-f -n 1', "a\nb\n", "b\n", 0],
76 #['f-2', '-f -n 1 -', "a\nb\n", "b\n", 0],
79 sub test_vector
81 # With _POSIX2_VERSION=199209, `tail -c' succeeds, but err-6 expects
82 # a failure, so set _POSIX2_VERSION to ensure it fails.
83 $Test::env{'err-6'} = ['_POSIX2_VERSION=200112'];
85 my $t;
86 foreach $t (@tv)
88 my ($test_name, $flags, $in, $exp, $ret) = @$t;
90 $test_name =~ /^(obs|minus-)/
91 and $Test::env{$test_name} = ['_POSIX2_VERSION=199209'];
93 # If you run the minus* tests with a FILE arg they'd hang.
94 # If you run the err-1 or err-3 tests with a FILE, they'd misinterpret
95 # the arg unless we are using the obsolete form.
96 if ($test_name =~ /^(minus|err-[13])/)
98 $Test::input_via{$test_name} = {REDIR => 0, PIPE => 0};
100 elsif ($test_name =~ /^f-/)
102 # Using redirection or a file would make this hang.
103 $Test::input_via{$test_name} = {PIPE => 0};
105 else
107 $Test::input_via{$test_name} = {REDIR => 0, FILE => 0, PIPE => 0}
111 return @tv;