mirrored from git://git.sv.gnu.org/datamash.git
/
datamash-error-msgs.pl
294 lines (251 loc) · 12.5 KB
/
datamash-error-msgs.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#!/usr/bin/env perl
=pod
Unit Tests for GNU Datamash - perform simple calculation on input data
Copyright (C) 2013-2021 Assaf Gordon <assafgordon@gmail.com>
This file is part of GNU Datamash.
GNU Datamash is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
GNU Datamash is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Datamash. If not, see <https://www.gnu.org/licenses/>.
Written by Assaf Gordon.
=cut
use strict;
use warnings;
# Until a better way comes along to auto-use Coreutils Perl modules
# as in the coreutils' autotools system.
use Coreutils;
use CuSkip;
use CuTmpdir qw(datamash);
use MIME::Base64 ;
(my $program_name = $0) =~ s|.*/||;
my $prog_bin = 'datamash';
# MAX_IDENTIFIER_LENGTH is defined in op-scanner.h
my $ident_too_long = "x" x 512 ;
## Cross-Compiling portability hack:
## under qemu/binfmt, argv[0] (which is used to report errors) will contain
## the full path of the binary, if the binary is on the $PATH.
## So we try to detect what is the actual returned value of the program
## in case of an error.
my $prog = `$prog_bin ---print-progname`;
$prog = $prog_bin unless $prog;
# TODO: add localization tests with "grouping"
# Turn off localization of executable's output.
@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
my @Tests =
(
# Invalid numeric value for column prasing should be treated as named column
['e1', 'sum 1x', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid numeric value '1x'\n"}],
# Processing mode without operation
['e2','groupby 1', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: missing operation\n"}],
# invalid operation after valid mode
['e3','groupby 1 foobar 2', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid operation 'foobar'\n"}],
# missing field number after processing mode
['e4','groupby', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: missing field for operation 'groupby'\n"}],
# Field range with invalid syntax
['e20','sum 1-', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid field range for operation 'sum'\n"}],
['e21','sum 1-x', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: field range for 'sum' must be numeric\n"}],
['e22','sum 4-2', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid field range for operation 'sum'\n"}],
# zero in range
['e23','sum 0-2', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid field '0' for operation 'sum'\n"}],
['e24','sum 1-0', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid field '0' for operation 'sum'\n"}],
#Negative in range
['e25','sum 1--5', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid field range for operation 'sum'\n"}],
# Test field pair syntax
['e41','pcov 1', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: operation 'pcov' requires field pairs\n"}],
['e42','pcov 1:', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid field pair for operation 'pcov'\n"}],
['e43','pcov :', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid field pair for operation 'pcov'\n"}],
['e44','pcov :1', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid field pair for operation 'pcov'\n"}],
['e46','pcov hello:world', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: -H or --header-in must be used with named columns\n"}],
['e47','sum 1:3', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: operation 'sum' cannot use pair of fields\n"}],
['e50','dotprod 1', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: operation 'dotprod' requires field pairs\n"}],
['e51','dotprod 1:', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid field pair for operation 'dotprod'\n"}],
['e52','dotprod :', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid field pair for operation 'dotprod'\n"}],
['e53','dotprod :1', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid field pair for operation 'dotprod'\n"}],
['e54','dotprod hello:world', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: -H or --header-in must be used with named columns\n"}],
# Test scanner edge-cases
# Floating point value
['e60','sum 4.5', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid field '4.5' for operation 'sum'\n"}],
['e61','sum 4.', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid field '4.' for operation 'sum'\n"}],
# invalid numbers
['e62','sum 4a', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid numeric value '4a'\n"}],
['e63','sum 4_', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid numeric value '4_'\n"}],
# Overflow strtol
['e64','sum 1234567890123456789012345678901234567', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid numeric value " .
"'1234567890123456789012345678901234567'\n"}],
# Invalid charcters
['e65','sum "foo^bar"', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid operand '^bar'\n"}],
# Empty columns
['e66','sum 1,,', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: missing field for operation 'sum'\n"}],
# Range with names instead of numbers
['e67','sum foo-bar', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: field range for 'sum' must be numeric\n"}],
# Invalid numeric value for column prasing should be treated as named column
['e70', 'sum 1x', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid numeric value '1x'\n"}],
# Processing mode without operation
['e71','groupby 1', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: missing operation\n"}],
# invalid operation after valid mode
['e72','groupby 1 foobar 2', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid operation 'foobar'\n"}],
# missing field number after processing mode
['e73','groupby', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: missing field for operation 'groupby'\n"}],
# Bin and optional parameters
['e80','bin:10:30 1', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: too many parameters for operation 'bin'\n"}],
['e81','bin: 1', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: missing parameter for operation 'bin'\n"}],
# NOTE about the message: because the parser first parses parameters,
# then checks if the operation actually needs parameters, the
# error first complains about 'missing' because there are colons
# but no numeric values.
['e82','sum: 1', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: missing parameter for operation 'sum'\n"}],
['e83','bin:10: 1', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: missing parameter for operation 'bin'\n"}],
# These ensures the '1' is not accidentally parsed as the field number
['e84','bin:10:1', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: missing field for operation 'bin'\n"}],
['e85','bin:10, 1', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: missing field for operation 'bin'\n"}],
['e86','bin:, 1', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid parameter , for operation 'bin'\n"}],
['e87','bin, 1', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: missing field for operation 'bin'\n"}],
['e88','bin:- 1', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid parameter - for operation 'bin'\n"}],
['e89','sum:10 1', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: too many parameters for operation 'sum'\n"}],
# Invalid field specifications for primary operations
['e90', 'groupby 1:2', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid field pair for operation 'groupby'\n"}],
# values for strbin operation
['e92','strbin:- 1', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid parameter - for operation 'strbin'\n"}],
['e93','strbin:0 1', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: strbin bucket size must not be zero\n"}],
# values for percentile operation
['e94','perc:0 1', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid percentile value 0\n"}],
['e95','perc:101 1', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid percentile value 101\n"}],
['e96','perc:foo 1', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid parameter foo for operation 'perc'\n"}],
['e97','perc:-32 1', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid parameter - for operation 'perc'\n"}],
['e98','perc:1:2 1', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: too many parameters for operation 'perc'\n"}],
# Invalid output delimiters
['e100', '--output-delimiter', {IN_PIPE=>""}, {EXIT=>1},
{ERR_SUBST=>'s/requires an argument -- output-delimiter/' .
'\'--output-delimiter\' requires an argument/'},
{ERR=>"$prog: option '--output-delimiter' requires an argument\n".
"Try '$prog --help' for more information.\n"}],
['e101', '--output-delimiter ""', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: the delimiter must be a single character\n"}],
['e102', '--output-delimiter "XX"', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: the delimiter must be a single character\n"}],
# values for trimmean operation
['e103','trimmean:12 1', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid trim mean value 12 (expected 0 <= X <= 0.5)\n"}],
['e104','trimmean:0.51 1', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid trim mean value 0.51 (expected 0 <= X <= 0.5)\n"}],
['e105','trimmean:-32 1', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid parameter - for operation 'trimmean'\n"}],
['e106','trimmean:1:2 1', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: too many parameters for operation 'trimmean'\n"}],
# Rounding
['e110','--round ""', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: missing rounding digits value\n"}],
['e111','--round "3a"', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid rounding digits value '3a'\n"}],
# Rounding Currently hard-coded to 1 to 50 decimal-point digits.
['e112','--round "0"', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid rounding digits value '0'\n"}],
['e113','--round "51"', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: invalid rounding digits value '51'\n"}],
# Custom Output Formats
['e120','--format ""', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: format '' has no % directive\n"}],
['e121','--format "foobar"', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: format 'foobar' has no % directive\n"}],
['e122','--format "aa%%ff"', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: format 'aa%%ff' has no % directive\n"}],
['e123','--format "%Lg"', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: format '%Lg' has unknown/invalid type %L directive\n"}],
['e124','--format "%*g"', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: format '%*g' has unknown/invalid type %* directive\n"}],
['e125','--format "%g %f"', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: format '%g %f' has too many % directives\n"}],
['e126','--format "%"', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: format '%' missing valid type after '%'\n"}],
['e127','--format "%3"', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: format '%3' missing valid type after '%'\n"}],
['e128','--format "%#.4"', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: format '%#.4' missing valid type after '%'\n"}],
['e129','--format "%f%"', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: format '%f%' has too many % directives\n"}],
['e130','--format "%f%3"', {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: format '%f%3' has too many % directives\n"}],
# identifier scanning errors
['e140',"-H sum 'foo\\'", {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: backslash at end of identifier\n"}],
['e141',"-H sum $ident_too_long", {IN_PIPE=>""}, {EXIT=>1},
{ERR=>"$prog: identifier name too long\n"}],
# invalid numeric input data
['e150', 'sum 1', {IN_PIPE=>"1.2.3\n"}, {EXIT=>1},
{ERR=>"$prog: invalid numeric value in line 1 field 1: '1.2.3'\n"}],
['e151', 'sum 1', {IN_PIPE=>"1.2.3\t4.5\n"}, {EXIT=>1},
{ERR=>"$prog: invalid numeric value in line 1 field 1: '1.2.3'\n"}],
['e152', 'sum 2', {IN_PIPE=>"1.2\t3.4.5\n"}, {EXIT=>1},
{ERR=>"$prog: invalid numeric value in line 1 field 2: '3.4.5'\n"}],
# bad seeds
['e153', '-S1.1 rand 1',
{IN_PIPE=>"1\n"}, {EXIT=>1},
{ERR=>"$prog: invalid seed\n"}],
['e154', '-S-1 rand 1',
{IN_PIPE=>"1\n"}, {EXIT=>1},
{ERR=>"$prog: invalid seed\n"}],
['e155', '-Sa rand 1',
{IN_PIPE=>"1\n"}, {EXIT=>1},
{ERR=>"$prog: invalid seed\n"}],
);
my $save_temps = $ENV{SAVE_TEMPS};
my $verbose = $ENV{VERBOSE};
my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
exit $fail;