1 | #!/usr/bin/perl
|
---|
2 | # Test the --debug feature
|
---|
3 |
|
---|
4 | # Copyright (C) 2018-2022 Free Software Foundation, Inc.
|
---|
5 |
|
---|
6 | # This program is free software: you can redistribute it and/or modify
|
---|
7 | # it under the terms of the GNU General Public License as published by
|
---|
8 | # the Free Software Foundation, either version 3 of the License, or
|
---|
9 | # (at your option) any later version.
|
---|
10 |
|
---|
11 | # This program is distributed in the hope that it will be useful,
|
---|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | # GNU General Public License for more details.
|
---|
15 |
|
---|
16 | # You should have received a copy of the GNU General Public License
|
---|
17 | # along with this program. If not, see <https://www.gnu.org/licenses/>.
|
---|
18 |
|
---|
19 | use strict;
|
---|
20 | use File::stat;
|
---|
21 |
|
---|
22 | (my $program_name = $0) =~ s|.*/||;
|
---|
23 |
|
---|
24 | # Turn off localization of executable's output.
|
---|
25 | @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
|
---|
26 |
|
---|
27 | my $prog = 'sed';
|
---|
28 |
|
---|
29 | print "PATH = $ENV{PATH}\n";
|
---|
30 |
|
---|
31 | =pod
|
---|
32 | This list contains a template for the tests.
|
---|
33 | Two 'foreach' loops below add the '{IN/OUT}' hash entries
|
---|
34 | of typical coreutils tests, adds single-quotes around the sed program,
|
---|
35 | and adds the --debug command line option.
|
---|
36 |
|
---|
37 | NOTE: test names with "_" character will be checked with NULL input,
|
---|
38 | but not with non-empty input (eg. to avoid executing external programs).
|
---|
39 | =cut
|
---|
40 | my @Tests =
|
---|
41 | (
|
---|
42 | ## Test parsing of SED commands, without any execution
|
---|
43 | ['c0', '=' ],
|
---|
44 | ['c1', ':FOO' ],
|
---|
45 | ['c2', '{=}' ],
|
---|
46 | ['c3', '#FOO' ],
|
---|
47 | ['c4', 'aFOO' ],
|
---|
48 | ['c5', 'b' ],
|
---|
49 | ['c6', 'bx;:x' ],
|
---|
50 | ['c7', 'cFOO' ],
|
---|
51 | ['c8', 'D' ],
|
---|
52 | ['c9', 'd' ],
|
---|
53 | ['c10_', 'e' ],
|
---|
54 | ['c11_', 'ew' ],
|
---|
55 | ['c12', 'F' ],
|
---|
56 | ['c13', 'G' ],
|
---|
57 | ['c14', 'g' ],
|
---|
58 | ['c15', 'H' ],
|
---|
59 | ['c16', 'h' ],
|
---|
60 | ['c17', 'iFOO' ],
|
---|
61 | ['c18', 'l' ],
|
---|
62 | ['c19', 'l3' ],
|
---|
63 | ['c20', 'N' ],
|
---|
64 | ['c21', 'n' ],
|
---|
65 | ['c22', 'P' ],
|
---|
66 | ['c23', 'p' ],
|
---|
67 | ['c24', 'Q' ],
|
---|
68 | ['c25_', 'Q3' ],
|
---|
69 | ['c26', 'q' ],
|
---|
70 | ['c27_', 'q3' ],
|
---|
71 | ['c28', 'Rx' ],
|
---|
72 | ['c29', 'rx' ],
|
---|
73 | ['c30', 's/x//' ],
|
---|
74 | ['c31', 'T' ],
|
---|
75 | ['c32', 'Tx;:x' ],
|
---|
76 | ['c33', 't' ],
|
---|
77 | ['c34', 'tx;:x' ],
|
---|
78 | ['c35', 'v' ],
|
---|
79 | ['c36', 'Wx' ],
|
---|
80 | ['c37', 'wx' ],
|
---|
81 | ['c38', 'x' ],
|
---|
82 | ['c39', 'y/x/y/' ],
|
---|
83 | ['c40', 'z' ],
|
---|
84 | ['c41', '' ],
|
---|
85 |
|
---|
86 | ## Test parsing of SED addresses, without any execution
|
---|
87 | ['a0', '1=' ],
|
---|
88 | ['a1', '1!=' ],
|
---|
89 | ['a2', '1,2=' ],
|
---|
90 | ['a3', '1,2!=' ],
|
---|
91 | ['a4', '$=' ],
|
---|
92 | ['a5', '$!=' ],
|
---|
93 | ['a6', '1~3=' ],
|
---|
94 | ['a7', '1~3=' ],
|
---|
95 | ['a8', '50~0=' ],
|
---|
96 | ['a9', '/foo/=' ],
|
---|
97 | ['a10', '/foo/!=' ],
|
---|
98 | ['a11', '\@foo@=' ],
|
---|
99 | ['a12', '0,/foo/=' ],
|
---|
100 | ['a13', '1,/foo/=' ],
|
---|
101 | ['a14', '/foo/,1=' ],
|
---|
102 | ['a15', '1,+10=' ],
|
---|
103 | ['a16', '1,~10=' ],
|
---|
104 | ['a17', '/foo/,+10='],
|
---|
105 | ['a18', '/foo/,~10='],
|
---|
106 |
|
---|
107 | ## Test strings with special characters
|
---|
108 | ['s1', '/\\a/=' ],
|
---|
109 | ['s2', '/\\b/=' ],
|
---|
110 | ['s3', '/\\f/=' ],
|
---|
111 | ['s4', '/\\r/=' ],
|
---|
112 | ['s5', '/\\t/=' ],
|
---|
113 | ['s6', '/\\v/=' ],
|
---|
114 | ['s7', '/\\n/=' ],
|
---|
115 | ['s8', '/\\\\/=' ],
|
---|
116 | ['s9', '/\x01/=' ],
|
---|
117 | ['s10','/\//=' ],
|
---|
118 |
|
---|
119 | ## Address Regex variations
|
---|
120 | ['r0', '/a/= ; //=' ],
|
---|
121 | ['r1', '/a/I=' ],
|
---|
122 | ['r2', '/a/M=' ],
|
---|
123 | ['r3', '/a/IM=' ],
|
---|
124 |
|
---|
125 | ## substitute variations
|
---|
126 | ['t0', 's/a/b/' ],
|
---|
127 | ['t1', 's/a/b/g' ],
|
---|
128 | ['t2', 's/a/b/i' ],
|
---|
129 | ['t3', 's/a/b/I' ],
|
---|
130 | ['t4', 's/a/b/m' ],
|
---|
131 | ['t5', 's/a/b/M' ],
|
---|
132 | ['t6', 's/a/b/wX' ],
|
---|
133 | ['t7', 's/a/b/p' ],
|
---|
134 | ['t8', 's/a/b/e' ],
|
---|
135 | ['t9', 's/a/b/3' ],
|
---|
136 | ['t10','s/a/b/iMg5p'],
|
---|
137 |
|
---|
138 | ['t20','s/\\(a\\)/\\1/' ],
|
---|
139 | ['t21','s/a/\\Ua/' ],
|
---|
140 | ['t22','s/a/\\ua/' ],
|
---|
141 | ['t23','s/a/\\La/' ],
|
---|
142 | ['t24','s/a/\\la/' ],
|
---|
143 | ['t25','s/a/\\U\\Ea/' ],
|
---|
144 | ['t26','s/a/&/' ],
|
---|
145 |
|
---|
146 | ## Some special cases
|
---|
147 | ['l1', 'a\\' ],
|
---|
148 | ['l2', 'c\\' ],
|
---|
149 | ['l3', 'i\\' ],
|
---|
150 | ['l4', 's/[0-9]/&/' ], # report matched regex register
|
---|
151 | ['l5', 'n;N;D' ], # n/N/D with patterns containing \n.
|
---|
152 | ['l6', 'n;n;n;n;n' ], # n causing end-of-cycle
|
---|
153 | ['l7', 's/^/a/' ], # zero-length regex match
|
---|
154 | ['l8', 's/\\($\\)/a/' ], # zero-length regex match
|
---|
155 | );
|
---|
156 |
|
---|
157 |
|
---|
158 | foreach my $t (@Tests)
|
---|
159 | {
|
---|
160 | my $name = shift @$t;
|
---|
161 | my $cmd = shift @$t;
|
---|
162 |
|
---|
163 | # Add "--debug" and single-quotes around the sed program.
|
---|
164 | $cmd = "--debug '" . $cmd . "'";
|
---|
165 | unshift @$t, $cmd;
|
---|
166 | unshift @$t, $name;
|
---|
167 |
|
---|
168 | # Add the typical coreutils hash entries.
|
---|
169 | # With empty input, the sed program will be printed (due to --debug),
|
---|
170 | # but not executed.
|
---|
171 | push @$t, {IN=>''};
|
---|
172 | push @$t, {OUT=>''};
|
---|
173 | push @$t, {OUT_SUBST=>'s/.*//s'};
|
---|
174 | }
|
---|
175 |
|
---|
176 | # Repeat the tests with some input, to test --debug during execution.
|
---|
177 | # Discard the output, the exact debug output is not set in stone.
|
---|
178 | my @xtests;
|
---|
179 | Test:
|
---|
180 | foreach my $t (@Tests)
|
---|
181 | {
|
---|
182 | # Remove the '{IN}' hash
|
---|
183 | my @newt = grep { ! ( ref $_ eq 'HASH' && exists $_->{IN} ) } @$t;
|
---|
184 | next if $newt[0] =~ /_/;
|
---|
185 |
|
---|
186 | # Rename the test (add "x_" prefix, for execution)
|
---|
187 | $newt[0] = 'x_' . $newt[0];
|
---|
188 |
|
---|
189 | # Add non-empty input.
|
---|
190 | push @newt, {IN=>"1\n2\n3\n4\n"};
|
---|
191 | push @xtests, \@newt;
|
---|
192 | }
|
---|
193 |
|
---|
194 | push @Tests, @xtests;
|
---|
195 |
|
---|
196 | my $save_temps = $ENV{SAVE_TEMPS};
|
---|
197 | my $verbose = $ENV{VERBOSE};
|
---|
198 |
|
---|
199 | my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
|
---|
200 | exit $fail;
|
---|