Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / tail / Test.pm
1 # Test "tail".
2
3 # Copyright (C) 1997, 1998, 2002, 2004, 2005, 2006 Free Software
4 # Foundation, Inc.
5
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 2 of the License, or
9 # (at your option) any later version.
10
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.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 # 02110-1301, USA.
20
21 package Test;
22 require 5.002;
23 use strict;
24
25 my @tv = (
26 # test name, options, input, expected output, expected return code
27 #
28 ['obs-plus-c1', '+2c', 'abcd', 'bcd', 0],
29 ['obs-plus-c2', '+8c', 'abcd', '', 0],
30 ['obs-c3', '-1c', 'abcd', 'd', 0],
31 ['obs-c4', '-9c', 'abcd', 'abcd', 0],
32 ['obs-c5', '-12c', 'x' . ('y' x 12) . 'z', ('y' x 11) . 'z', 0],
33
34
35 ['obs-l1', '-1l', 'x', 'x', 0],
36 ['obs-l2', '-1l', "x\ny\n", "y\n", 0],
37 ['obs-l3', '-1l', "x\ny", "y", 0],
38 ['obs-plus-l4', '+1l', "x\ny\n", "x\ny\n", 0],
39 ['obs-plus-l5', '+2l', "x\ny\n", "y\n", 0],
40
41 # Same as -l tests, but without the `l'.
42 ['obs-1', '-1', 'x', 'x', 0],
43 ['obs-2', '-1', "x\ny\n", "y\n", 0],
44 ['obs-3', '-1', "x\ny", "y", 0],
45 ['obs-plus-4', '+1', "x\ny\n", "x\ny\n", 0],
46 ['obs-plus-5', '+2', "x\ny\n", "y\n", 0],
47
48 # This is equivalent to +10c
49 ['obs-plus-x1', '+c', 'x' . ('y' x 10) . 'z', 'yyz', 0],
50 # This is equivalent to +10l
51 ['obs-plus-x2', '+l', "x\n" . ("y\n" x 10) . 'z', "y\ny\nz", 0],
52 # With no number, this is like -10l
53 ['obs-l', '-l', "x\n" . ("y\n" x 10) . 'z', ("y\n" x 9) . 'z', 0],
54
55 ['obs-b', '-b', "x\n" x (512 * 10 / 2 + 1), "x\n" x (512 * 10 / 2), 0],
56
57 # This should get
58 # `tail: cannot open `+cl' for reading: No such file or directory'
59 ['err-1', '+cl', '', '', 1],
60
61 # This should get `tail: l: invalid number of bytes'
62 ['err-2', '-cl', '', '', 1],
63
64 # This should get
65 # `tail: cannot open `+2cz' for reading: No such file or directory'
66 ['err-3', '+2cz', '', '', 1],
67
68 # This should get `tail: invalid option -- 2'
69 ['err-4', '-2cX', '', '', 1],
70
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 ['err-6', '-c', '', '', 1],
76
77 # Same as -n 10
78 ['minus-1', '-', '', '', 0],
79 ['minus-2', '-', "x\n" . ("y\n" x 10) . 'z', ("y\n" x 9) . 'z', 0],
80
81 ['c-2', '-c 2', "abcd\n", "d\n", 0],
82 ['c-2-minus', '-c 2 --', "abcd\n", "d\n", 0],
83 ['c2', '-c2', "abcd\n", "d\n", 0],
84 ['c2-minus', '-c2 --', "abcd\n", "d\n", 0],
85
86 ['n-1', '-n 10', "x\n" . ("y\n" x 10) . 'z', ("y\n" x 9) . 'z', 0],
87 ['n-2', '-n -10', "x\n" . ("y\n" x 10) . 'z', ("y\n" x 9) . 'z', 0],
88 ['n-3', '-n +10', "x\n" . ("y\n" x 10) . 'z', "y\ny\nz", 0],
89
90 # Accept +0 as synonym for +1.
91 ['n-4',  '-n +0', "y\n" x 5, "y\n" x 5, 0],
92 ['n-4a', '-n +1', "y\n" x 5, "y\n" x 5, 0],
93
94 # Note that -0 is *not* a synonym for -1.
95 ['n-5',  '-n -0', "y\n" x 5, '', 0],
96 ['n-5a', '-n -1', "y\n" x 5, "y\n", 0],
97 ['n-5b', '-n  0', "y\n" x 5, '', 0],
98
99 # With textutils-1.22, this failed.
100 ['f-pipe-1', '-f -n 1', "a\nb\n", "b\n", 0],
101 );
102
103 sub test_vector
104 {
105   my $t;
106   foreach $t (@tv)
107     {
108       my ($test_name, $flags, $in, $exp, $ret) = @$t;
109
110       if ($test_name =~ /^(obs-plus-|minus-)/)
111         {
112           $Test::env{$test_name} = ['_POSIX2_VERSION=199209'];
113         }
114       if ($test_name =~ /^(err-6|c-2)$/)
115         {
116           $Test::env{$test_name} = ['_POSIX2_VERSION=200112'];
117         }
118       if ($test_name =~ /^f-pipe-/)
119         {
120           $Test::env{$test_name} = ['POSIXLY_CORRECT=1'];
121         }
122
123       # If you run the minus* tests with a FILE arg they'd hang.
124       # If you run the err-1 or err-3 tests with a FILE, they'd misinterpret
125       # the arg unless we are using the obsolete form.
126       if ($test_name =~ /^(minus|err-[13])/)
127         {
128           $Test::input_via{$test_name} = {REDIR => 0, PIPE => 0};
129         }
130       elsif ($test_name =~ /^f-/)
131         {
132           # Using redirection or a file would make this hang.
133           $Test::input_via{$test_name} = {PIPE => 0};
134         }
135       else
136         {
137           $Test::input_via{$test_name} = {REDIR => 0, FILE => 0, PIPE => 0}
138         }
139     }
140
141   return @tv;
142 }
143
144 1;