Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / misc / fold
1 #!/bin/sh
2 # -*- perl -*-
3 # Exercise fold.
4
5 # Copyright (C) 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 # Ensure that we don't run an older version of fold.
32 # Prior to 5.0.91, some of the tests below would cause fold to infloop,
33 # and since `make check' might be run even after a build failure, it'd
34 # expose just such an older version.
35 ver=`fold --version|sed 1q`
36 case $ver in
37   *" $PACKAGE_VERSION") ;;
38   *) echo 1>&2 \
39    "$0: found unexpected version of fold, \`$ver'"
40      "(expected $PACKAGE_VERSION)"
41   exit 1;;
42 esac
43
44 exec $PERL -w -I$srcdir/.. -MCoreutils -- - <<\EOF
45 #/
46 require 5.003;
47 use strict;
48
49 (my $program_name = $0) =~ s|.*/||;
50
51 # Turn off localization of executable's ouput.
52 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
53
54 my @Tests =
55   (
56    ['s1', '-w2 -s', {IN=>"a\t"}, {OUT=>"a\n\t"}],
57    ['s2', '-w4 -s', {IN=>"abcdef d\n"}, {OUT=>"abcd\nef d\n"}],
58    ['s3', '-w4 -s', {IN=>"a cd fgh\n"}, {OUT=>"a \ncd \nfgh\n"}],
59    ['s4', '-w4 -s', {IN=>"abc ef\n"}, {OUT=>"abc \nef\n"}],
60   );
61
62 my $save_temps = $ENV{DEBUG};
63 my $verbose = $ENV{VERBOSE};
64
65 my $prog = $ENV{PROG} || die "$0: \$PROG not specified in environment\n";
66 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
67 exit $fail;
68 EOF