tests: add test for locale decimal processing
[coreutils.git] / tests / misc / comm.pl
blob2e87f8080c0449fc94a99a17c55c37a9d6dd120a
1 #!/usr/bin/perl
2 # -*- perl -*-
3 # Test comm
5 # Copyright (C) 2008-2019 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 <https://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\n3\n3"}}, {IN=>{b=>"2\n2\n3\n3\n3"}});
31 my @zinputs = ({IN=>{za=>"1\0003\0003\0003"}},
32 {IN=>{zb=>"2\0002\0003\0003\0003"}});
34 my @Tests =
36 # basic operation
37 ['basic', @inputs, {OUT=>"1\n\t2\n\t2\n\t\t3\n\t\t3\n\t\t3\n"} ],
38 ['zbasic', '-z', @zinputs, {OUT=>"1\0\t2\0\t2\0\t\t3\0\t\t3\0\t\t3\0"} ],
40 # suppress lines unique to file 1
41 ['opt-1', '-1', @inputs, {OUT=>"2\n2\n\t3\n\t3\n\t3\n"} ],
42 ['zopt-1', '-z', '-1', @zinputs, {OUT=>"2\0002\000\t3\000\t3\000\t3\000"} ],
44 # suppress lines unique to file 2
45 ['opt-2', '-2', @inputs, {OUT=>"1\n\t3\n\t3\n\t3\n"} ],
46 ['zopt-2', '-z', '-2', @zinputs, {OUT=>"1\000\t3\000\t3\000\t3\000"} ],
48 # suppress lines that appear in both files
49 ['opt-3', '-3', @inputs, {OUT=>"1\n\t2\n\t2\n"} ],
50 ['zopt-3', '-z', '-3', @zinputs, {OUT=>"1\000\t2\000\t2\000"} ],
52 # suppress lines unique to file 1 and lines unique to file 2
53 ['opt-12', '-1', '-2', @inputs, {OUT=>"3\n3\n3\n"} ],
54 ['zopt-12', '-12z', @zinputs, {OUT=>"3\0003\0003\000"} ],
56 # suppress lines unique to file 1 and those that appear in both files
57 ['opt-13', '-1', '-3', @inputs, {OUT=>"2\n2\n"} ],
58 ['zopt-13', '-13z', @zinputs, {OUT=>"2\0002\000"} ],
60 # suppress lines unique to file 2 and those that appear in both files
61 ['opt-23', '-2', '-3', @inputs, {OUT=>"1\n"} ],
62 ['zopt-23', '-23z', @zinputs, {OUT=>"1\000"} ],
64 # suppress all output
65 ['opt-123', '-1', '-2', '-3', @inputs, {OUT=>""} ],
67 # show summary: 1 only in file1, 2 only in file2, 3 in both files
68 ['total-all', '--total', @inputs, {OUT=>"1\n\t2\n\t2\n\t\t3\n\t\t3\n\t\t3\n"
69 . "1\t2\t3\ttotal\n"} ],
71 # show summary only, suppressing regular output
72 ['total-123', '--total', '-123', @inputs, {OUT=>"1\t2\t3\ttotal\n"} ],
74 # invalid missing command line argument (1)
75 ['missing-arg1', $inputs[0], {EXIT=>1},
76 {ERR => "$prog: missing operand after 'a'\n"
77 . "Try '$prog --help' for more information.\n"}],
79 # invalid missing command line argument (both)
80 ['missing-arg2', {EXIT=>1},
81 {ERR => "$prog: missing operand\n"
82 . "Try '$prog --help' for more information.\n"}],
84 # invalid extra command line argument
85 ['extra-arg', @inputs, 'no-such', {EXIT=>1},
86 {ERR => "$prog: extra operand 'no-such'\n"
87 . "Try '$prog --help' for more information.\n"}],
89 # out-of-order input
90 ['ooo', {IN=>{a=>"1\n3"}}, {IN=>{b=>"3\n2"}}, {EXIT=>1},
91 {OUT => "1\n\t\t3\n\t2\n"},
92 {ERR => "$prog: file 2 is not in sorted order\n"}],
94 # out-of-order input, fatal
95 ['ooo2', '--check-order', {IN=>{a=>"1\n3"}}, {IN=>{b=>"3\n2"}}, {EXIT=>1},
96 {OUT => "1\n\t\t3\n"},
97 {ERR => "$prog: file 2 is not in sorted order\n"}],
99 # out-of-order input, ignored
100 ['ooo3', '--nocheck-order', {IN=>{a=>"1\n3"}}, {IN=>{b=>"3\n2"}},
101 {OUT => "1\n\t\t3\n\t2\n"}],
103 # both inputs out-of-order
104 ['ooo4', {IN=>{a=>"3\n1\n0"}}, {IN=>{b=>"3\n2\n0"}}, {EXIT=>1},
105 {OUT => "\t\t3\n1\n0\n\t2\n\t0\n"},
106 {ERR => "$prog: file 1 is not in sorted order\n".
107 "$prog: file 2 is not in sorted order\n" }],
109 # both inputs out-of-order on last pair
110 ['ooo5', {IN=>{a=>"3\n1"}}, {IN=>{b=>"3\n2"}}, {EXIT=>1},
111 {OUT => "\t\t3\n1\n\t2\n"},
112 {ERR => "$prog: file 1 is not in sorted order\n".
113 "$prog: file 2 is not in sorted order\n" }],
115 # first input out-of-order extended
116 ['ooo5b', {IN=>{a=>"0\n3\n1"}}, {IN=>{b=>"2\n3"}}, {EXIT=>1},
117 {OUT => "0\n\t2\n\t\t3\n1\n"},
118 {ERR => "$prog: file 1 is not in sorted order\n"}],
120 # second input out-of-order extended
121 ['ooo5c', {IN=>{a=>"0\n3"}}, {IN=>{b=>"2\n3\n1"}}, {EXIT=>1},
122 {OUT => "0\n\t2\n\t\t3\n\t1\n"},
123 {ERR => "$prog: file 2 is not in sorted order\n"}],
125 # both inputs out-of-order, but fully pairable
126 ['ooo6', {IN=>{a=>"2\n1\n0"}}, {IN=>{b=>"2\n1\n0"}}, {EXIT=>0},
127 {OUT => "\t\t2\n\t\t1\n\t\t0\n"}],
129 # both inputs out-of-order, fully pairable, but forced to fail
130 ['ooo7', '--check-order', {IN=>{a=>"2\n1\n0"}}, {IN=>{b=>"2\n1\n0"}},
131 {EXIT=>1},
132 {OUT => "\t\t2\n"},
133 {ERR => "$prog: file 1 is not in sorted order\n"}],
135 # out-of-order, line 2 is a prefix of line 1
136 # until coreutils-7.2, this test would fail -- no disorder detected
137 ['ooo-prefix', '--check-order', {IN=>{a=>"Xa\nX\n"}}, {IN=>{b=>""}},
138 {EXIT=>1},
139 {OUT => "Xa\n"},
140 {ERR => "$prog: file 1 is not in sorted order\n"}],
142 # alternate delimiter: ','
143 ['delim-comma', '--output-delimiter=,', @inputs,
144 {OUT=>"1\n,2\n,2\n,,3\n,,3\n,,3\n"} ],
146 # two-character alternate delimiter: '++'
147 ['delim-2char', '--output-delimiter=++', @inputs,
148 {OUT=>"1\n++2\n++2\n++++3\n++++3\n++++3\n"} ],
150 # NUL delimiter
151 ['delim-empty', '--output-delimiter=', @inputs,
152 {OUT=>"1\n\0002\n\0002\n\000\0003\n\000\0003\n\000\0003\n"} ],
153 ['zdelim-empty', '-z', '-z --output-delimiter=', @zinputs,
154 {OUT=>"1\000\0002\000\0002\000\000\0003\000\000\0003\000\000\0003\000"} ],
156 # invalid dual delimiter
157 ['delim-dual', '--output-delimiter=,', '--output-delimiter=+', @inputs,
158 {EXIT=>1}, {ERR => "$prog: multiple output delimiters specified\n"}],
160 # valid dual delimiter specification
161 ['delim-dual2', '--output-delimiter=,', '--output-delimiter=,', @inputs,
162 {OUT=>"1\n,2\n,2\n,,3\n,,3\n,,3\n"} ],
164 # show summary, zero-terminated
165 ['totalz-all', '--total', '-z', @zinputs,
166 {OUT=>"1\000\t2\000\t2\000\t\t3\000\t\t3\000\t\t3\000"
167 . "1\t2\t3\ttotal\000"} ],
169 # show summary only (-123), zero-terminated and with ',' as delimiter
170 ['totalz-123', '--total', '-z123', '--output-delimiter=,', @zinputs,
171 {OUT=>"1,2,3,total\000"} ],
174 my $save_temps = $ENV{DEBUG};
175 my $verbose = $ENV{VERBOSE};
177 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
178 exit $fail;