62711bda01bdadcdc526c774d1ec6186eca9b97f
[platform/upstream/coreutils.git] / tests / misc / comm.pl
1 #!/usr/bin/perl
2 # -*- perl -*-
3 # Test comm
4
5 # Copyright (C) 2008-2013 Free Software Foundation, Inc.
6
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.
11
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.
16
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/>.
19
20 require 5.003;
21 use strict;
22
23 (my $program_name = $0) =~ s|.*/||;
24
25 my $prog = 'comm';
26
27 # Turn off localization of executable's ouput.
28 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
29
30 my @inputs = ({IN=>{a=>"1\n3"}}, {IN=>{b=>"2\n3"}});
31
32 my @Tests =
33   (
34    # basic operation
35    ['basic', @inputs, {OUT=>"1\n\t2\n\t\t3\n"} ],
36
37    # suppress lines unique to file 1
38    ['opt-1', '-1', @inputs, {OUT=>"2\n\t3\n"} ],
39
40    # suppress lines unique to file 2
41    ['opt-2', '-2', @inputs, {OUT=>"1\n\t3\n"} ],
42
43    # suppress lines that appear in both files
44    ['opt-3', '-3', @inputs, {OUT=>"1\n\t2\n"} ],
45
46    # suppress lines unique to file 1 and lines unique to file 2
47    ['opt-12', '-1', '-2', @inputs, {OUT=>"3\n"} ],
48
49    # suppress lines unique to file 1 and those that appear in both files
50    ['opt-13', '-1', '-3', @inputs, {OUT=>"2\n"} ],
51
52    # suppress lines unique to file 2 and those that appear in both files
53    ['opt-23', '-2', '-3', @inputs, {OUT=>"1\n"} ],
54
55    # suppress all output (really?)
56    ['opt-123', '-1', '-2', '-3', @inputs, {OUT=>""} ],
57
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"}],
62
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"}],
67
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"}],
72
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"}],
77
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"}],
82
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"}],
86
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" }],
92
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" }],
98
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"}],
103
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"}],
108
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"}],
112
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"}],
118
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"}],
125
126    # alternate delimiter: ','
127    ['delim-comma', '--output-delimiter=,', @inputs,
128     {OUT=>"1\n,2\n,,3\n"} ],
129
130    # two-character alternate delimiter: '++'
131    ['delim-2char', '--output-delimiter=++', @inputs,
132     {OUT=>"1\n++2\n++++3\n"} ],
133
134    # invalid empty delimiter
135    ['delim-empty', '--output-delimiter=', @inputs, {EXIT=>1},
136     {ERR => "$prog: empty '--output-delimiter' not allowed\n"}],
137
138    # invalid dual delimiter
139    ['delim-dual', '--output-delimiter=,', '--output-delimiter=+',
140     @inputs, {EXIT=>1}, {ERR => "$prog: multiple delimiters specified\n"}],
141
142    # valid dual delimiter specification
143    ['delim-dual2', '--output-delimiter=,', '--output-delimiter=,', @inputs,
144     {OUT=>"1\n,2\n,,3\n"} ],
145
146  );
147
148 my $save_temps = $ENV{DEBUG};
149 my $verbose = $ENV{VERBOSE};
150
151 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
152 exit $fail;