doc: stat: clarify that %t and %T expand to the file system type
[coreutils/ericb.git] / tests / misc / comm
blobddfe4cc492bfc9ed07d855c6a2e4827098eb825c
1 #!/usr/bin/perl
2 # -*- perl -*-
3 # Test comm
5 # Copyright (C) 2008-2011 Free Software Foundation, Inc.
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 require 5.003;
21 use strict;
23 (my $program_name = $0) =~ s|.*/||;
25 my $prog = 'comm';
27 # Turn off localization of executable's ouput.
28 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
30 my @inputs = ({IN=>{a=>"1\n3"}}, {IN=>{b=>"2\n3"}});
32 my @Tests =
34 # basic operation
35 ['basic', @inputs, {OUT=>"1\n\t2\n\t\t3\n"} ],
37 # supress lines unique to file 1
38 ['opt-1', '-1', @inputs, {OUT=>"2\n\t3\n"} ],
40 # supress lines unique to file 2
41 ['opt-2', '-2', @inputs, {OUT=>"1\n\t3\n"} ],
43 # supress lines that appear in both files
44 ['opt-3', '-3', @inputs, {OUT=>"1\n\t2\n"} ],
46 # supress lines unique to file 1 and lines unique to file 2
47 ['opt-12', '-1', '-2', @inputs, {OUT=>"3\n"} ],
49 # supress lines unique to file 1 and those that appear in both files
50 ['opt-13', '-1', '-3', @inputs, {OUT=>"2\n"} ],
52 # supress lines unique to file 2 and those that appear in both files
53 ['opt-23', '-2', '-3', @inputs, {OUT=>"1\n"} ],
55 # supress all output (really?)
56 ['opt-123', '-1', '-2', '-3', @inputs, {OUT=>""} ],
58 # invalid missing command line argument (1)
59 ['missing-arg1', $inputs[0], {EXIT=>1},
60 {ERR => "$prog: missing operand after `a'\n"
61 . "Try `$prog --help' for more information.\n"}],
63 # invalid missing command line argument (both)
64 ['missing-arg2', {EXIT=>1},
65 {ERR => "$prog: missing operand\n"
66 . "Try `$prog --help' for more information.\n"}],
68 # invalid extra command line argument
69 ['extra-arg', @inputs, 'no-such', {EXIT=>1},
70 {ERR => "$prog: extra operand `no-such'\n"
71 . "Try `$prog --help' for more information.\n"}],
73 # out-of-order input
74 ['ooo', {IN=>{a=>"1\n3"}}, {IN=>{b=>"3\n2"}}, {EXIT=>1},
75 {OUT => "1\n\t\t3\n\t2\n"},
76 {ERR => "$prog: file 2 is not in sorted order\n"}],
78 # out-of-order input, fatal
79 ['ooo2', '--check-order', {IN=>{a=>"1\n3"}}, {IN=>{b=>"3\n2"}}, {EXIT=>1},
80 {OUT => "1\n\t\t3\n"},
81 {ERR => "$prog: file 2 is not in sorted order\n"}],
83 # out-of-order input, ignored
84 ['ooo3', '--nocheck-order', {IN=>{a=>"1\n3"}}, {IN=>{b=>"3\n2"}},
85 {OUT => "1\n\t\t3\n\t2\n"}],
87 # both inputs out-of-order
88 ['ooo4', {IN=>{a=>"3\n1\n0"}}, {IN=>{b=>"3\n2\n0"}}, {EXIT=>1},
89 {OUT => "\t\t3\n1\n0\n\t2\n\t0\n"},
90 {ERR => "$prog: file 1 is not in sorted order\n".
91 "$prog: file 2 is not in sorted order\n" }],
93 # both inputs out-of-order on last pair
94 ['ooo5', {IN=>{a=>"3\n1"}}, {IN=>{b=>"3\n2"}}, {EXIT=>1},
95 {OUT => "\t\t3\n1\n\t2\n"},
96 {ERR => "$prog: file 1 is not in sorted order\n".
97 "$prog: file 2 is not in sorted order\n" }],
99 # first input out-of-order extended
100 ['ooo5b', {IN=>{a=>"0\n3\n1"}}, {IN=>{b=>"2\n3"}}, {EXIT=>1},
101 {OUT => "0\n\t2\n\t\t3\n1\n"},
102 {ERR => "$prog: file 1 is not in sorted order\n"}],
104 # second input out-of-order extended
105 ['ooo5c', {IN=>{a=>"0\n3"}}, {IN=>{b=>"2\n3\n1"}}, {EXIT=>1},
106 {OUT => "0\n\t2\n\t\t3\n\t1\n"},
107 {ERR => "$prog: file 2 is not in sorted order\n"}],
109 # both inputs out-of-order, but fully pairable
110 ['ooo6', {IN=>{a=>"2\n1\n0"}}, {IN=>{b=>"2\n1\n0"}}, {EXIT=>0},
111 {OUT => "\t\t2\n\t\t1\n\t\t0\n"}],
113 # both inputs out-of-order, fully pairable, but forced to fail
114 ['ooo7', '--check-order', {IN=>{a=>"2\n1\n0"}}, {IN=>{b=>"2\n1\n0"}},
115 {EXIT=>1},
116 {OUT => "\t\t2\n"},
117 {ERR => "$prog: file 1 is not in sorted order\n"}],
119 # out-of-order, line 2 is a prefix of line 1
120 # until coreutils-7.2, this test would fail -- no disorder detected
121 ['ooo-prefix', '--check-order', {IN=>{a=>"Xa\nX\n"}}, {IN=>{b=>""}},
122 {EXIT=>1},
123 {OUT => "Xa\n"},
124 {ERR => "$prog: file 1 is not in sorted order\n"}],
126 # alternate delimiter: ','
127 ['delim-comma', '--output-delimiter=,', @inputs,
128 {OUT=>"1\n,2\n,,3\n"} ],
130 # two-character alternate delimiter: '++'
131 ['delim-2char', '--output-delimiter=++', @inputs,
132 {OUT=>"1\n++2\n++++3\n"} ],
134 # invalid empty delimiter
135 ['delim-empty', '--output-delimiter=', @inputs, {EXIT=>1},
136 {ERR => "$prog: empty `--output-delimiter' not allowed\n"}],
138 # invalid dual delimiter
139 ['delim-dual', '--output-delimiter=,', '--output-delimiter=+',
140 @inputs, {EXIT=>1}, {ERR => "$prog: multiple delimiters specified\n"}],
142 # valid dual delimiter specification
143 ['delim-dual2', '--output-delimiter=,', '--output-delimiter=,', @inputs,
144 {OUT=>"1\n,2\n,,3\n"} ],
148 my $save_temps = $ENV{DEBUG};
149 my $verbose = $ENV{VERBOSE};
151 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
152 exit $fail;