ad536d1168b5447dd022520ea349cd4d926a9f50
[platform/upstream/coreutils.git] / tests / fmt / basic
1 #!/bin/sh
2 # -*- perl -*-
3
4 : ${PERL=perl}
5 : ${srcdir=.}
6
7 $PERL -e 1 > /dev/null 2>&1 || {
8   echo 1>&2 "$0: configure didn't find a usable version of Perl," \
9     "so can't run this test"
10   exit 77
11 }
12
13 # Export this to avoid hassles when run in a UTF-8 locale,
14 # since we use 8-bit characters below, and those values are
15 # interpolated into strings (to perform substitution) in Coreutils.pm.
16 LC_ALL=C
17 export LC_ALL
18
19 exec $PERL -w -I$srcdir/.. -MCoreutils -- - <<\EOF
20 require 5.003;
21 use strict;
22
23 (my $program_name = $0) =~ s|.*/||;
24
25 my @Tests =
26     (
27      ['8-bit-pfx', qw (-p 'ç'),
28       {IN=> "ça\nçb\n"},
29       {OUT=>"ça b\n"}],
30      ['wide-1', '-w 32768',
31       {ERR => "fmt: invalid width: `32768'\n"}, {EXIT => 1}],
32      ['wide-2', '-w 2147483647',
33       {ERR => "fmt: invalid width: `2147483647'\n"}, {EXIT => 1}],
34      ['bad-suffix', '-72x',     {IN=> ''},
35       {ERR => "fmt: invalid width: `72x'\n"}, {EXIT => 1}],
36      ['no-file', 'no-such-file',
37       {ERR => "fmt: cannot open `no-such-file' for reading:"
38        . " No such file or directory\n"}, {EXIT => 1}],
39      ['obs-1', '-c -72',
40       {ERR => "fmt: invalid option -- 7; -WIDTH is recognized only when it"
41        . " is the first\noption; use -w N instead\n"
42        . "Try `fmt --help' for more information.\n" }, {EXIT => 1}],
43
44      # With --prefix=P, Do not remove leading on lines without the prefix.
45      ['pfx-1', qw (-p '>'),
46       {IN=>  " 1\n  2\n\t3\n\t\t4\n> quoted\n> text\n"},
47       # This is the buggy output (leading white space removed),
48       # from coreutils-5.93.
49       {OUT=> "1\n2\n3\n4\n> quoted text\n"}],
50       # FIXME: this is the desired output
51       # {OUT=> " 1\n  2\n\t3\n\t\t4\n> quoted text\n"}],
52
53      # Like the above, but when two adjacent, non-prefixed lines have
54      # the same indentation, ensure that they are formatted.
55      ['pfx-2', qw (-p '>'),
56       {IN=>  " 1\n 2\n\t3\n\t4\n"},
57       {OUT=> "1\n2\n3\n4\n"}],
58       # FIXME: this is the desired output
59       # {OUT=> " 1 2\n\t3 4\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