Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / head / Test.pm
1 # Test "head".
2
3 # Copyright (C) 1997, 1998, 1999, 2000, 2002, 2003, 2005 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 ['idem-0', '', "", "", 0],
29 ['idem-1', '', "a", "a", 0],
30 ['idem-2', '', "\n", "\n", 0],
31 ['idem-3', '', "a\n", "a\n", 0],
32
33 ['basic-0-10', '',
34  "1\n2\n3\n4\n5\n6\n7\n8\n9\n0\n",
35  "1\n2\n3\n4\n5\n6\n7\n8\n9\n0\n", 0],
36
37 ['basic-0-09', '',
38  "1\n2\n3\n4\n5\n6\n7\n8\n9\n",
39  "1\n2\n3\n4\n5\n6\n7\n8\n9\n", 0],
40
41 ['basic-0-11', '',
42  "1\n2\n3\n4\n5\n6\n7\n8\n9\n0\nb\n",
43  "1\n2\n3\n4\n5\n6\n7\n8\n9\n0\n", 0],
44
45 ['obs-0', '-1', "1\n2\n", "1\n", 0],
46 ['obs-1', '-1c', "", "", 0],
47 ['obs-2', '-1c', "12", "1", 0],
48 ['obs-3', '-14c', "1234567890abcdefg", "1234567890abcd", 0],
49 ['obs-4', '-2b', [\'in'], [\'in-1024'], 0],
50 ['obs-5', '-1k', [\'in'], [\'in-1024'], 0],
51
52 # This test fails for textutils-1.22, because head let 4096m overflow to 0
53 # and did not fail.  Now head fails with a diagnostic.
54
55 # Disable this test because it fails on systems with 64-bit longs.
56 # ['fail-0', '-n 4096m', "a\n", "", 1],
57
58 # In spite of its name, this test passes -- just to contrast with the above.
59 ['fail-1', '-n 2048m', "a\n", "a\n", 0],
60
61 # Make sure we don't break like AIX 4.3.1 on files with \0 in them.
62 ['null-1', '', "a\0a\n", "a\0a\n", 0],
63
64 # Make sure counts are interpreted as decimal.
65 # Before 2.0f, these would have been interpreted as octal
66 ['no-oct-1', '-08',  "\n"x12, "\n"x8, 0],
67 ['no-oct-2', '-010', "\n"x12, "\n"x10, 0],
68 ['no-oct-3', '-n 08', "\n"x12, "\n"x8, 0],
69 ['no-oct-4', '-c 08', "\n"x12, "\n"x8, 0],
70
71 );
72
73 sub test_vector
74 {
75   my @derived_tests;
76   foreach my $t (@tv)
77     {
78       my ($test_name, $flags, $in, $exp, $ret) = @$t;
79
80       # Derive equivalent, posix-style tests from the obsolescent ones.
81       next if $test_name !~ /^obs-/;
82
83       $test_name =~ s/^obs-/posix-/;
84       if ($flags =~ /-(\d+)$/)
85         {
86           $flags = "-n $1";
87         }
88       elsif ($flags =~ /-(\d+)([cbk])$/)
89         {
90           my $suffix = $2;
91           $suffix = '' if $suffix eq 'c';
92           $flags = "-c $1$suffix";
93         }
94       else
95         {
96           $flags = "-l $`";
97         }
98       push (@derived_tests, [$test_name, $flags, $in, $exp, $ret]);
99     }
100
101   foreach my $t (@tv, @derived_tests)
102     {
103       my ($test_name) = @$t;
104       $Test::input_via{$test_name} = {REDIR => 0, FILE => 0, PIPE => 0}
105     }
106
107   return (@tv, @derived_tests);
108 }
109
110 1;