1eb167737594493010e75d863878b7e3123b138a
[platform/upstream/coreutils.git] / tests / head / Test.pm
1 package Test;
2 require 5.002;
3 use strict;
4
5 my @tv = (
6 # test name, options, input, expected output, expected return code
7 #
8 ['idem-0', '', "", "", 0],
9 ['idem-1', '', "a", "a", 0],
10 ['idem-2', '', "\n", "\n", 0],
11 ['idem-3', '', "a\n", "a\n", 0],
12
13 ['basic-0-10', '',
14  "1\n2\n3\n4\n5\n6\n7\n8\n9\n0\n",
15  "1\n2\n3\n4\n5\n6\n7\n8\n9\n0\n", 0],
16
17 ['basic-0-09', '',
18  "1\n2\n3\n4\n5\n6\n7\n8\n9\n",
19  "1\n2\n3\n4\n5\n6\n7\n8\n9\n", 0],
20
21 ['basic-0-11', '',
22  "1\n2\n3\n4\n5\n6\n7\n8\n9\n0\nb\n",
23  "1\n2\n3\n4\n5\n6\n7\n8\n9\n0\n", 0],
24
25 ['obs-0', '-1', "1\n2\n", "1\n", 0],
26 ['obs-1', '-1c', "", "", 0],
27 ['obs-2', '-1c', "12", "1", 0],
28 ['obs-3', '-14c', "1234567890abcdefg", "1234567890abcd", 0],
29 ['obs-4', '-2b', [\'in'], [\'in-1024'], 0],
30 ['obs-5', '-1k', [\'in'], [\'in-1024'], 0],
31
32 # This test fails for textutils-1.22, because head let 4096m overflow to 0
33 # and did not fail.  Now head fails with a diagnostic.
34
35 # Disable this test because it fails on systems with 64-bit longs.
36 # ['fail-0', '-n 4096m', "a\n", "", 1],
37
38 # In spite of its name, this test passes -- just to contrast with the above.
39 ['fail-1', '-n 2048m', "a\n", "a\n", 0],
40
41 # Make sure we don't break like AIX 4.3.1 on files with \0 in them.
42 ['null-1', '', "a\0a\n", "a\0a\n", 0],
43
44 # Make sure counts are interpreted as decimal.
45 # Before 2.0f, these would have been interpreted as octal
46 ['no-oct-1', '-08',  "\n"x12, "\n"x8, 0],
47 ['no-oct-2', '-010', "\n"x12, "\n"x10, 0],
48 ['no-oct-3', '-n 08', "\n"x12, "\n"x8, 0],
49 ['no-oct-4', '-c 08', "\n"x12, "\n"x8, 0],
50
51 );
52
53 sub test_vector
54 {
55   my @derived_tests;
56   foreach my $t (@tv)
57     {
58       my ($test_name, $flags, $in, $exp, $ret) = @$t;
59
60       # Derive equivalent, posix-style tests from the obsolescent ones.
61       next if $test_name !~ /^obs-/;
62
63       $test_name =~ s/^obs-/posix-/;
64       if ($flags =~ /-(\d+)$/)
65         {
66           $flags = "-n $1";
67         }
68       elsif ($flags =~ /-(\d+)([cbk])$/)
69         {
70           my $suffix = $2;
71           $suffix = '' if $suffix eq 'c';
72           $flags = "-c $1$suffix";
73         }
74       else
75         {
76           $flags = "-l $`";
77         }
78       push (@derived_tests, [$test_name, $flags, $in, $exp, $ret]);
79     }
80
81   foreach my $t (@tv, @derived_tests)
82     {
83       my ($test_name) = @$t;
84       $Test::input_via{$test_name} = {REDIR => 0, FILE => 0, PIPE => 0}
85     }
86
87   return (@tv, @derived_tests);
88 }
89
90 1;