2bb6f24a5acf8c0cf7001a60f52cc6a6470644e1
[platform/upstream/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 3 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, see <http://www.gnu.org/licenses/>.
19
20 : ${PERL=perl}
21 : ${srcdir=.}
22
23 $PERL -e 1 > /dev/null 2>&1 || {
24   echo 1>&2 "$0: configure didn't find a usable version of Perl," \
25     "so can't run this test"
26   exit 77
27 }
28
29 # Ensure that we don't run an older version of fold.
30 # Prior to 5.0.91, some of the tests below would cause fold to infloop,
31 # and since `make check' might be run even after a build failure, it'd
32 # expose just such an older version.
33 ver=`fold --version|sed 1q`
34 case $ver in
35   *" $PACKAGE_VERSION") ;;
36   *) echo 1>&2 \
37    "$0: found unexpected version of fold, \`$ver'"
38      "(expected $PACKAGE_VERSION)"
39   exit 1;;
40 esac
41
42 me=`echo $0|sed 's,.*/,,'`
43 exec $PERL -w -I$srcdir/.. -MCoreutils -M"CuTmpdir qw($me)" -- - <<\EOF
44 #/
45 require 5.003;
46 use strict;
47
48 (my $program_name = $0) =~ s|.*/||;
49
50 # Turn off localization of executable's ouput.
51 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
52
53 my @Tests =
54   (
55    ['s1', '-w2 -s', {IN=>"a\t"}, {OUT=>"a\n\t"}],
56    ['s2', '-w4 -s', {IN=>"abcdef d\n"}, {OUT=>"abcd\nef d\n"}],
57    ['s3', '-w4 -s', {IN=>"a cd fgh\n"}, {OUT=>"a \ncd \nfgh\n"}],
58    ['s4', '-w4 -s', {IN=>"abc ef\n"}, {OUT=>"abc \nef\n"}],
59   );
60
61 my $save_temps = $ENV{DEBUG};
62 my $verbose = $ENV{VERBOSE};
63
64 my $prog = $ENV{PROG} || die "$0: \$PROG not specified in environment\n";
65 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
66 exit $fail;
67 EOF