d070d4586c80292b19e6a2cec781989a2642b781
[platform/upstream/coreutils.git] / tests / misc / fold
1 #!/bin/sh
2 # -*- perl -*-
3 # Exercise fold.
4
5 : ${PERL=perl}
6 : ${srcdir=.}
7
8 $PERL -e 1 > /dev/null 2>&1 || {
9   echo 1>&2 "$0: configure didn't find a usable version of Perl," \
10     "so can't run this test"
11   exit 77
12 }
13
14 # Ensure that we don't run an older version of fold.
15 # Prior to 5.0.91, some of the tests below would cause fold to infloop,
16 # and since `make check' might be run even after a build failure, it'd
17 # expose just such an older version.
18 ver=`fold --version|sed 1q`
19 case $ver in
20   *" $PACKAGE_VERSION") ;;
21   *) echo 1>&2 \
22    "$0: found unexpected version of fold, \`$ver'"
23      "(expected $PACKAGE_VERSION)"
24   exit 1;;
25 esac
26
27 exec $PERL -w -I$srcdir/.. -MCoreutils -- - <<\EOF
28 #/
29 require 5.003;
30 use strict;
31
32 (my $program_name = $0) =~ s|.*/||;
33
34 # Turn off localization of executable's ouput.
35 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
36
37 my @Tests =
38   (
39    ['s1', '-w2 -s', {IN=>"a\t"}, {OUT=>"a\n\t"}],
40    ['s2', '-w4 -s', {IN=>"abcdef d\n"}, {OUT=>"abcd\nef d\n"}],
41    ['s3', '-w4 -s', {IN=>"a cd fgh\n"}, {OUT=>"a \ncd \nfgh\n"}],
42    ['s4', '-w4 -s', {IN=>"abc ef\n"}, {OUT=>"abc \nef\n"}],
43   );
44
45 my $save_temps = $ENV{DEBUG};
46 my $verbose = $ENV{VERBOSE};
47
48 my $prog = $ENV{PROG} || die "$0: \$PROG not specified in environment\n";
49 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
50 exit $fail;
51 EOF