Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / unexpand / basic-1
1 #!/bin/sh
2 # Test "unexpand".
3
4 # Copyright (C) 2000, 2003, 2004, 2005, 2006 Free Software Foundation,
5 # 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 exec $PERL -w -I$srcdir/.. -MCoreutils -- - <<\EOF
32 require 5.003;
33 use strict;
34
35 (my $program_name = $0) =~ s|.*/||;
36
37 # Turn off localisation of executable's ouput.
38 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
39
40 my $prog = $ENV{PROG} || die "$0: \$PROG not specified in environment\n";
41
42 my @Tests =
43     (
44      ['a1', {IN=> ' 'x 1 ."y\n"}, {OUT=> ' 'x 1 ."y\n"}],
45      ['a2', {IN=> ' 'x 2 ."y\n"}, {OUT=> ' 'x 2 ."y\n"}],
46      ['a3', {IN=> ' 'x 3 ."y\n"}, {OUT=> ' 'x 3 ."y\n"}],
47      ['a4', {IN=> ' 'x 4 ."y\n"}, {OUT=> ' 'x 4 ."y\n"}],
48      ['a5', {IN=> ' 'x 5 ."y\n"}, {OUT=> ' 'x 5 ."y\n"}],
49      ['a6', {IN=> ' 'x 6 ."y\n"}, {OUT=> ' 'x 6 ."y\n"}],
50      ['a7', {IN=> ' 'x 7 ."y\n"}, {OUT=> ' 'x 7 ."y\n"}],
51      ['a8', {IN=> ' 'x 8 ."y\n"}, {OUT=> "\ty\n"}],
52
53      ['aa-1', '-a', {IN=> 'w'.' 'x 1 ."y\n"}, {OUT=> 'w'.' 'x 1 ."y\n"}],
54      ['aa-2', '-a', {IN=> 'w'.' 'x 2 ."y\n"}, {OUT=> 'w'.' 'x 2 ."y\n"}],
55      ['aa-3', '-a', {IN=> 'w'.' 'x 3 ."y\n"}, {OUT=> 'w'.' 'x 3 ."y\n"}],
56      ['aa-4', '-a', {IN=> 'w'.' 'x 4 ."y\n"}, {OUT=> 'w'.' 'x 4 ."y\n"}],
57      ['aa-5', '-a', {IN=> 'w'.' 'x 5 ."y\n"}, {OUT=> 'w'.' 'x 5 ."y\n"}],
58      ['aa-6', '-a', {IN=> 'w'.' 'x 6 ."y\n"}, {OUT=> 'w'.' 'x 6 ."y\n"}],
59      ['aa-7', '-a', {IN=> 'w'.' 'x 7 ."y\n"}, {OUT=> "w\ty\n"}],
60      ['aa-8', '-a', {IN=> 'w'.' 'x 8 ."y\n"}, {OUT=> "w\t y\n"}],
61
62      ['b-1', '-t', '2,4', {IN=> "      ."}, {OUT=>"\t\t  ."}],
63      # These would infloop prior to textutils-2.0d.
64
65      ['infloop-1', '-t', '1,2', {IN=> " \t\t .\n"}, {OUT=>"\t\t\t .\n"}],
66      ['infloop-2', '-t', '4,5', {IN=> ' 'x4 . "\t\t \n"}, {OUT=>"\t\t\t \n"}],
67      ['infloop-3', '-t', '2,3', {IN=> "x \t\t \n"}, {OUT=>"x \t\t \n"}],
68      ['infloop-4', '-t', '1,2', {IN=> " \t\t   \n"}, {OUT=>"\t\t\t   \n"}],
69      ['c-1', '-t', '1,2', {IN=> "x\t\t .\n"}, {OUT=>"x\t\t .\n"}],
70
71      # -t implies -a
72      # Feature addition (--first-only) prompted by a report from Jie Xu.
73      ['tabs-1', qw(-t 3),              {IN=> "   a  b\n"}, {OUT=>"\ta\tb\n"}],
74      ['tabs-2', qw(-t 3 --first-only), {IN=> "   a  b\n"}, {OUT=>"\ta  b\n"}],
75
76      # blanks
77      ['blanks-1', qw(-t 1), {IN=> " b  c   d\n"}, {OUT=> "\tb\t\tc\t\t\td\n"}],
78      ['blanks-2', qw(-t 1), {IN=> "a \n"}, {OUT=> "a \n"}],
79      ['blanks-3', qw(-t 1), {IN=> "a  \n"}, {OUT=> "a\t\t\n"}],
80      ['blanks-4', qw(-t 1), {IN=> "a   \n"}, {OUT=> "a\t\t\t\n"}],
81      ['blanks-5', qw(-t 1), {IN=> "a "}, {OUT=> "a "}],
82      ['blanks-6', qw(-t 1), {IN=> "a  "}, {OUT=> "a\t\t"}],
83      ['blanks-7', qw(-t 1), {IN=> "a   "}, {OUT=> "a\t\t\t"}],
84      ['blanks-8', qw(-t 1), {IN=> " a a  a\n"}, {OUT=> "\ta a\t\ta\n"}],
85      ['blanks-9', qw(-t 2), {IN=> "   a  a  a\n"}, {OUT=> "\t a\ta  a\n"}],
86      ['blanks-10', '-t', '3,4', {IN=> "0 2 4 6\t8\n"}, {OUT=> "0 2 4 6\t8\n"}],
87      ['blanks-11', '-t', '3,4', {IN=> "    4\n"}, {OUT=> "\t\t4\n"}],
88      ['blanks-12', '-t', '3,4', {IN=> "01  4\n"}, {OUT=> "01\t\t4\n"}],
89      ['blanks-13', '-t', '3,4', {IN=> "0   4\n"}, {OUT=> "0\t\t4\n"}],
90
91      # It is debatable whether this test should require an environment
92      # setting of e.g., _POSIX2_VERSION=1.
93      ['obs-ovflo', '-18446744073709551617', {IN=>''}, {OUT=>''},
94       {EXIT => 1}, {ERR => "$prog: tab stop value is too large\n"}],
95     );
96
97 my $save_temps = $ENV{DEBUG};
98 my $verbose = $ENV{VERBOSE};
99
100 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
101 exit $fail;
102 EOF