85ec38462e4a28b6d02eeb66341bc246906569f7
[platform/upstream/coreutils.git] / tests / seq / basic
1 #!/bin/sh
2 # -*- perl -*-
3
4 : ${PERL=perl}
5 : ${srcdir=.}
6
7 $PERL -e 1 > /dev/null 2>&1 || {
8   echo 1>&2 "$0: configure didn't find a usable version of Perl," \
9     "so can't run this test"
10   exit 77
11 }
12
13 d=$srcdir/..
14 exec $PERL -w -I$d -MCoreutils -- - << \EOF
15 require 5.003;
16 use strict;
17
18 (my $program_name = $0) =~ s|.*/||;
19
20 # Turn off localisation of executable's ouput.
21 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
22
23 my $prog = $ENV{PROG} || die "$0: \$PROG not specified in environment\n";
24
25 my @Tests =
26   (
27    ['onearg-1', qw(10),         {OUT => [(1..10)]}],
28    ['onearg-2', qw(-1)],
29    ['neg-1',    qw(-10 10 10),  {OUT => [qw(-10 0 10)]}],
30    ['neg-2',    qw(-.1 .1 .1),  {OUT => [qw(-0.1 0.0 0.1)]}],
31    ['neg-3',    qw(1 -1 0),     {OUT => [qw(1 0)]}],
32    ['neg-4',    qw(1 -1 -1),    {OUT => [qw(1 0 -1)]}],
33
34    ['eq-wid-1', qw(-w 1 -1 -1), {OUT => [qw(01 00 -1)]}],
35
36    # Prior to 2.0g, this test would fail on e.g., HPUX systems
37    # because it'd end up using %3.1f as the format instead of %4.1f.
38    ['eq-wid-2', qw(-w -.1 .1 .1),{OUT => [qw(-0.1 00.0 00.1)]}],
39
40    # Prior to coreutils-4.5.11, some of these were not accepted.
41    ['fmt-1',    qw(-f %2.1f 1.5 .5 2),{OUT => [qw(1.5 2.0)]}],
42    ['fmt-2',    qw(-f %0.1f 1.5 .5 2),{OUT => [qw(1.5 2.0)]}],
43    ['fmt-3',    qw(-f %.1f  1.5 .5 2),{OUT => [qw(1.5 2.0)]}],
44
45    ['fmt-4',    qw(-f %3.0f 1 2),     {OUT => ['  1', '  2']}],
46    ['fmt-5',    qw(-f %-3.0f 1 2),    {OUT => ['1  ', '2  ']}],
47    ['fmt-6',    qw(-f %+3.0f 1 2),    {OUT => [' +1', ' +2']}],
48    ['fmt-7',    qw(-f %0+3.0f 1 2),   {OUT => [qw(+01 +02)]}],
49    ['fmt-8',    qw(-f %0+.0f 1 2),    {OUT => [qw(+1 +2)]}],
50    ['fmt-9',    '-f "% -3.0f"', qw(-1 0), {OUT => ['-1 ', ' 0 ']}],
51    ['fmt-a',    '-f "% -.0f"',qw(-1 0), {OUT => ['-1', ' 0']}],
52   );
53
54 # Append a newline to each entry in the OUT array.
55 my $t;
56 foreach $t (@Tests)
57   {
58     my $e;
59     foreach $e (@$t)
60       {
61         $e->{OUT} = join ("\n", @{$e->{OUT}}) . "\n"
62           if ref $e eq 'HASH' and exists $e->{OUT};
63       }
64   }
65
66 my $save_temps = $ENV{SAVE_TEMPS};
67 my $verbose = $ENV{VERBOSE};
68
69 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
70 exit $fail;
71 EOF