Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / fmt / basic
1 #!/bin/sh
2 # -*- perl -*-
3 # Basic tests for "fmt".
4
5 # Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software
6 # Foundation, Inc.
7
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.
12
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.
17
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
21 # 02110-1301, USA.
22
23 : ${PERL=perl}
24 : ${srcdir=.}
25
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"
29   exit 77
30 }
31
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.
35 LC_ALL=C
36 export LC_ALL
37
38 exec $PERL -w -I$srcdir/.. -MCoreutils -- - <<\EOF
39 require 5.003;
40 use strict;
41
42 (my $program_name = $0) =~ s|.*/||;
43
44 my @Tests =
45     (
46      ['8-bit-pfx', qw (-p 'ç'),
47       {IN=> "ça\nçb\n"},
48       {OUT=>"ça b\n"}],
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}],
58      ['obs-1', '-c -72',
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}],
62
63      # With --prefix=P, do not remove leading space 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       {OUT=> " 1\n  2\n\t3\n\t\t4\n> quoted text\n"}],
67
68      # Don't remove prefix from a prefix-only line.
69      ['pfx-only', qw (-p '>'),
70       {IN=>  ">\n"},
71       {OUT=> ">\n"}],
72
73      # With a multi-byte prefix, say, "foo", don't empty a line that
74      # starts with a strict prefix (e.g. "fo") of that prefix.
75      # With fmt from coreutils-6.7, it would mistakenly output an empty line.
76      ['pfx-of-pfx', qw (-p 'foo'),
77       {IN=>  "fo\n"},
78       {OUT=> "fo\n"}],
79 );
80
81 my $save_temps = $ENV{DEBUG};
82 my $verbose = $ENV{VERBOSE};
83
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);
86 exit $fail;
87 EOF