3 # Basic tests for "fmt".
5 # Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Free Software
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 $PERL -e 1 > /dev/null 2>&1 || {
27 echo 1>&2 "$0: configure didn't find a usable version of Perl," \
28 "so can't run this test"
32 # Export this to avoid hassles when run in a UTF-8 locale,
33 # since we use 8-bit characters below, and those values are
34 # interpolated into strings (to perform substitution) in Coreutils.pm.
38 exec $PERL -w -I$srcdir/.. -MCoreutils -- - <<\EOF
42 (my $program_name = $0) =~ s|.*/||;
46 ['8-bit-pfx', qw (-p 'ç'),
49 ['wide-1', '-w 32768',
50 {ERR => "fmt: invalid width: `32768'\n"}, {EXIT => 1}],
51 ['wide-2', '-w 2147483647',
52 {ERR => "fmt: invalid width: `2147483647'\n"}, {EXIT => 1}],
53 ['bad-suffix', '-72x', {IN=> ''},
54 {ERR => "fmt: invalid width: `72x'\n"}, {EXIT => 1}],
55 ['no-file', 'no-such-file',
56 {ERR => "fmt: cannot open `no-such-file' for reading:"
57 . " No such file or directory\n"}, {EXIT => 1}],
59 {ERR => "fmt: invalid option -- 7; -WIDTH is recognized only when it"
60 . " is the first\noption; use -w N instead\n"
61 . "Try `fmt --help' for more information.\n" }, {EXIT => 1}],
63 # With --prefix=P, Do not remove leading on lines without the prefix.
64 ['pfx-1', qw (-p '>'),
65 {IN=> " 1\n 2\n\t3\n\t\t4\n> quoted\n> text\n"},
66 # This is the buggy output (leading white space removed),
67 # from coreutils-5.93.
68 {OUT=> "1\n2\n3\n4\n> quoted text\n"}],
69 # FIXME: this is the desired output
70 # {OUT=> " 1\n 2\n\t3\n\t\t4\n> quoted text\n"}],
72 # Like the above, but when two adjacent, non-prefixed lines have
73 # the same indentation, ensure that they are formatted.
74 ['pfx-2', qw (-p '>'),
75 {IN=> " 1\n 2\n\t3\n\t4\n"},
76 {OUT=> "1\n2\n3\n4\n"}],
77 # FIXME: this is the desired output
78 # {OUT=> " 1 2\n\t3 4\n"}],
81 my $save_temps = $ENV{DEBUG};
82 my $verbose = $ENV{VERBOSE};
84 my $prog = $ENV{PROG} || die "$0: \$PROG not specified in environment\n";
85 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);