Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / seq / basic
1 #!/bin/sh
2 # -*- perl -*-
3 # Test "seq".
4
5 # Copyright (C) 1999, 2000, 2003, 2005, 2006 Free Software Foundation, Inc.
6
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 2 of the License, or
10 # (at your option) any later version.
11
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.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 # 02110-1301, USA.
21
22 : ${PERL=perl}
23 : ${srcdir=.}
24
25 $PERL -e 1 > /dev/null 2>&1 || {
26   echo 1>&2 "$0: configure didn't find a usable version of Perl," \
27     "so can't run this test"
28   exit 77
29 }
30
31 d=$srcdir/..
32 exec $PERL -w -I$d -MCoreutils -- - << \EOF
33 require 5.003;
34 use strict;
35
36 (my $program_name = $0) =~ s|.*/||;
37
38 # Turn off localisation of executable's ouput.
39 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
40
41 my $prog = $ENV{PROG} || die "$0: \$PROG not specified in environment\n";
42
43 my @Tests =
44   (
45    ['onearg-1', qw(10),         {OUT => [(1..10)]}],
46    ['onearg-2', qw(-1)],
47    ['neg-1',    qw(-10 10 10),  {OUT => [qw(-10 0 10)]}],
48    # ['neg-2',  qw(-.1 .1 .11), {OUT => [qw(-0.1 0.0 0.1)]}],
49    ['neg-3',    qw(1 -1 0),     {OUT => [qw(1 0)]}],
50    ['neg-4',    qw(1 -1 -1),    {OUT => [qw(1 0 -1)]}],
51
52    ['eq-wid-1', qw(-w 1 -1 -1), {OUT => [qw(01 00 -1)]}],
53
54    # Prior to 2.0g, this test would fail on e.g., HPUX systems
55    # because it'd end up using %3.1f as the format instead of %4.1f.
56    # ['eq-wid-2',       qw(-w -.1 .1 .11),{OUT => [qw(-0.1 00.0 00.1)]}],
57    # ['eq-wid-3',       qw(-w 1 3.0),  {OUT => [qw(1 2 3)]}],
58
59    # Prior to coreutils-4.5.11, some of these were not accepted.
60    ['fmt-1',    qw(-f %2.1f 1.5 .5 2),{OUT => [qw(1.5 2.0)]}],
61    ['fmt-2',    qw(-f %0.1f 1.5 .5 2),{OUT => [qw(1.5 2.0)]}],
62    ['fmt-3',    qw(-f %.1f  1.5 .5 2),{OUT => [qw(1.5 2.0)]}],
63
64    ['fmt-4',    qw(-f %3.0f 1 2),     {OUT => ['  1', '  2']}],
65    ['fmt-5',    qw(-f %-3.0f 1 2),    {OUT => ['1  ', '2  ']}],
66    ['fmt-6',    qw(-f %+3.0f 1 2),    {OUT => [' +1', ' +2']}],
67    ['fmt-7',    qw(-f %0+3.0f 1 2),   {OUT => [qw(+01 +02)]}],
68    ['fmt-8',    qw(-f %0+.0f 1 2),    {OUT => [qw(+1 +2)]}],
69    ['fmt-9',    '-f "% -3.0f"', qw(-1 0), {OUT => ['-1 ', ' 0 ']}],
70    ['fmt-a',    '-f "% -.0f"',qw(-1 0), {OUT => ['-1', ' 0']}],
71   );
72
73 # Append a newline to each entry in the OUT array.
74 my $t;
75 foreach $t (@Tests)
76   {
77     my $e;
78     foreach $e (@$t)
79       {
80         $e->{OUT} = join ("\n", @{$e->{OUT}}) . "\n"
81           if ref $e eq 'HASH' and exists $e->{OUT};
82       }
83   }
84
85 my $save_temps = $ENV{SAVE_TEMPS};
86 my $verbose = $ENV{VERBOSE};
87
88 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
89 exit $fail;
90 EOF