all: update gnulib submodule to latest
[coreutils.git] / tests / fmt / base.pl
blob49c48ca907ecdb3939464ad224ffc0b96d6b90f8
1 #!/usr/bin/perl
2 # Basic tests for "fmt".
4 # Copyright (C) 2001-2017 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 use strict;
21 (my $program_name = $0) =~ s|.*/||;
22 my $normalize_strerror = "s/': .*/'/";
24 my @Tests =
26 ['8-bit-pfx', qw (-p 'ç'),
27 {IN=> "ça\nçb\n"},
28 {OUT=>"ça b\n"}],
29 ['wide-1', '-w 32768',
30 {ERR => "fmt: invalid width: '32768'\n"}, {EXIT => 1},
31 {ERR_SUBST => $normalize_strerror}],
32 ['wide-2', '-w 2147483647',
33 {ERR => "fmt: invalid width: '2147483647'\n"}, {EXIT => 1},
34 {ERR_SUBST => $normalize_strerror}],
35 ['bad-suffix', '-72x', {IN=> ''},
36 {ERR => "fmt: invalid width: '72x'\n"}, {EXIT => 1}],
37 ['no-file', 'no-such-file',
38 {ERR => "fmt: cannot open 'no-such-file' for reading:"
39 . " No such file or directory\n"}, {EXIT => 1}],
40 ['obs-1', '-c -72',
41 {ERR => "fmt: invalid option -- 7; -WIDTH is recognized only when it"
42 . " is the first\noption; use -w N instead\n"
43 . "Try 'fmt --help' for more information.\n" }, {EXIT => 1}],
45 # With --prefix=P, do not remove leading space on lines without the prefix.
46 ['pfx-1', qw (-p '>'),
47 {IN=> " 1\n 2\n\t3\n\t\t4\n> quoted\n> text\n"},
48 {OUT=> " 1\n 2\n\t3\n\t\t4\n> quoted text\n"}],
50 # Don't remove prefix from a prefix-only line.
51 ['pfx-only', qw (-p '>'),
52 {IN=> ">\n"},
53 {OUT=> ">\n"}],
55 # With a multi-byte prefix, say, "foo", don't empty a line that
56 # starts with a strict prefix (e.g. "fo") of that prefix.
57 # With fmt from coreutils-6.7, it would mistakenly output an empty line.
58 ['pfx-of-pfx', qw (-p 'foo'),
59 {IN=> "fo\n"},
60 {OUT=> "fo\n"}],
63 my $save_temps = $ENV{DEBUG};
64 my $verbose = $ENV{VERBOSE};
65 my $prog = 'fmt';
66 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
67 exit $fail;