tests: remove ugly /bin/sh wrapper around each perl-based test script
[coreutils.git] / tests / misc / factor
blobd44bdacb10068ed282ec11abdc4b30a47fba3b75
1 #!/usr/bin/perl
2 # Basic tests for "factor".
4 # Copyright (C) 1998, 1999, 2000, 2003, 2004, 2005, 2007-2008 Free Software
5 # Foundation, Inc.
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 use strict;
22 (my $program_name = $0) =~ s|.*/||;
23 my $prog = 'factor';
25 # Turn off localization of executable's output.
26 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
28 my @Tests =
30 ['1', '9', {OUT => '3 3'}],
31 ['1a', '7', {OUT => '7'}],
32 ['2', '4294967291', {OUT => '4294967291'}],
33 ['3', '4294967292', {OUT => '2 2 3 3 7 11 31 151 331'}],
34 ['4', '4294967293', {OUT => '9241 464773'}],
36 ['a', '4294966201', {OUT => '12197 352133'}],
37 ['b', '4294966339', {OUT => '13187 325697'}],
38 ['c', '4294966631', {OUT => '13729 312839'}],
39 ['d', '4294966457', {OUT => '14891 288427'}],
40 ['e', '4294966759', {OUT => '21649 198391'}],
41 ['f', '4294966573', {OUT => '23071 186163'}],
42 ['g', '4294967101', {OUT => '23603 181967'}],
43 ['h', '4294966519', {OUT => '34583 124193'}],
44 ['i', '4294966561', {OUT => '36067 119083'}],
45 ['j', '4294966901', {OUT => '37747 113783'}],
46 ['k', '4294966691', {OUT => '39241 109451'}],
47 ['l', '4294966969', {OUT => '44201 97169'}],
48 ['m', '4294967099', {OUT => '44483 96553'}],
49 ['n', '4294966271', {OUT => '44617 96263'}],
50 ['o', '4294966789', {OUT => '50411 85199'}],
51 ['p', '4294966189', {OUT => '53197 80737'}],
52 ['q', '4294967213', {OUT => '57139 75167'}],
53 ['s', '4294967071', {OUT => '65521 65551'}],
54 ['t', '4294966194', {OUT => '2 3 3 3 3 3 3 3 53 97 191'}],
55 ['u', '4294966272', {OUT => '2 2 2 2 2 2 2 2 2 2 3 23 89 683'}],
56 ['v', '4294966400', {OUT => '2 2 2 2 2 2 2 5 5 1342177'}],
57 ['w', '4294966464', {OUT => '2 2 2 2 2 2 3 3 3 2485513'}],
58 ['x', '4294966896', {OUT => '2 2 2 2 3 3 3 11 607 1489'}],
59 ['y', '4294966998', {OUT => '2 3 7 3917 26107'}],
60 ['z', '-1',
61 {ERR_SUBST => q!s/'1'/1/!}, # map newer glibc diagnostic to expected.
62 {ERR => "$prog: invalid option -- 1\n"
63 . "Try `$prog --help' for more information.\n"},
64 {EXIT => 1}],
65 ['cont', 'a 4',
66 {OUT => "4: 2 2\n"},
67 {ERR => "$prog: `a' is not a valid positive integer\n"},
68 {EXIT => 1}],
71 # Prepend the command line argument and append a newline to end
72 # of each expected `OUT' string.
73 my $t;
75 Test:
76 foreach $t (@Tests)
78 my $arg1 = $t->[1];
80 # Don't fiddle with expected OUT string if there's a nonzero exit status.
81 foreach my $e (@$t)
83 ref $e eq 'HASH' && exists $e->{EXIT} && $e->{EXIT}
84 and next Test;
87 foreach my $e (@$t)
89 ref $e eq 'HASH' && exists $e->{OUT}
90 and $e->{OUT} = "$arg1: $e->{OUT}\n"
94 my $save_temps = $ENV{SAVE_TEMPS};
95 my $verbose = $ENV{VERBOSE};
97 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
98 exit $fail;