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
|
#!/usr/bin/perl
# Test the --debug feature
# Copyright (C) 2018-2022 Free Software Foundation, Inc.
# This program 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.
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
use strict;
use File::stat;
(my $program_name = $0) =~ s|.*/||;
# Turn off localization of executable's output.
@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
my $prog = 'sed';
print "PATH = $ENV{PATH}\n";
=pod
This list contains a template for the tests.
Two 'foreach' loops below add the '{IN/OUT}' hash entries
of typical coreutils tests, adds single-quotes around the sed program,
and adds the --debug command line option.
NOTE: test names with "_" character will be checked with NULL input,
but not with non-empty input (eg. to avoid executing external programs).
=cut
my @Tests =
(
## Test parsing of SED commands, without any execution
['c0', '=' ],
['c1', ':FOO' ],
['c2', '{=}' ],
['c3', '#FOO' ],
['c4', 'aFOO' ],
['c5', 'b' ],
['c6', 'bx;:x' ],
['c7', 'cFOO' ],
['c8', 'D' ],
['c9', 'd' ],
['c10_', 'e' ],
['c11_', 'ew' ],
['c12', 'F' ],
['c13', 'G' ],
['c14', 'g' ],
['c15', 'H' ],
['c16', 'h' ],
['c17', 'iFOO' ],
['c18', 'l' ],
['c19', 'l3' ],
['c20', 'N' ],
['c21', 'n' ],
['c22', 'P' ],
['c23', 'p' ],
['c24', 'Q' ],
['c25_', 'Q3' ],
['c26', 'q' ],
['c27_', 'q3' ],
['c28', 'Rx' ],
['c29', 'rx' ],
['c30', 's/x//' ],
['c31', 'T' ],
['c32', 'Tx;:x' ],
['c33', 't' ],
['c34', 'tx;:x' ],
['c35', 'v' ],
['c36', 'Wx' ],
['c37', 'wx' ],
['c38', 'x' ],
['c39', 'y/x/y/' ],
['c40', 'z' ],
['c41', '' ],
## Test parsing of SED addresses, without any execution
['a0', '1=' ],
['a1', '1!=' ],
['a2', '1,2=' ],
['a3', '1,2!=' ],
['a4', '$=' ],
['a5', '$!=' ],
['a6', '1~3=' ],
['a7', '1~3=' ],
['a8', '50~0=' ],
['a9', '/foo/=' ],
['a10', '/foo/!=' ],
['a11', '\@foo@=' ],
['a12', '0,/foo/=' ],
['a13', '1,/foo/=' ],
['a14', '/foo/,1=' ],
['a15', '1,+10=' ],
['a16', '1,~10=' ],
['a17', '/foo/,+10='],
['a18', '/foo/,~10='],
## Test strings with special characters
['s1', '/\\a/=' ],
['s2', '/\\b/=' ],
['s3', '/\\f/=' ],
['s4', '/\\r/=' ],
['s5', '/\\t/=' ],
['s6', '/\\v/=' ],
['s7', '/\\n/=' ],
['s8', '/\\\\/=' ],
['s9', '/\x01/=' ],
['s10','/\//=' ],
## Address Regex variations
['r0', '/a/= ; //=' ],
['r1', '/a/I=' ],
['r2', '/a/M=' ],
['r3', '/a/IM=' ],
## substitute variations
['t0', 's/a/b/' ],
['t1', 's/a/b/g' ],
['t2', 's/a/b/i' ],
['t3', 's/a/b/I' ],
['t4', 's/a/b/m' ],
['t5', 's/a/b/M' ],
['t6', 's/a/b/wX' ],
['t7', 's/a/b/p' ],
['t8', 's/a/b/e' ],
['t9', 's/a/b/3' ],
['t10','s/a/b/iMg5p'],
['t20','s/\\(a\\)/\\1/' ],
['t21','s/a/\\Ua/' ],
['t22','s/a/\\ua/' ],
['t23','s/a/\\La/' ],
['t24','s/a/\\la/' ],
['t25','s/a/\\U\\Ea/' ],
['t26','s/a/&/' ],
## Some special cases
['l1', 'a\\' ],
['l2', 'c\\' ],
['l3', 'i\\' ],
['l4', 's/[0-9]/&/' ], # report matched regex register
['l5', 'n;N;D' ], # n/N/D with patterns containing \n.
['l6', 'n;n;n;n;n' ], # n causing end-of-cycle
['l7', 's/^/a/' ], # zero-length regex match
['l8', 's/\\($\\)/a/' ], # zero-length regex match
);
foreach my $t (@Tests)
{
my $name = shift @$t;
my $cmd = shift @$t;
# Add "--debug" and single-quotes around the sed program.
$cmd = "--debug '" . $cmd . "'";
unshift @$t, $cmd;
unshift @$t, $name;
# Add the typical coreutils hash entries.
# With empty input, the sed program will be printed (due to --debug),
# but not executed.
push @$t, {IN=>''};
push @$t, {OUT=>''};
push @$t, {OUT_SUBST=>'s/.*//s'};
}
# Repeat the tests with some input, to test --debug during execution.
# Discard the output, the exact debug output is not set in stone.
my @xtests;
Test:
foreach my $t (@Tests)
{
# Remove the '{IN}' hash
my @newt = grep { ! ( ref $_ eq 'HASH' && exists $_->{IN} ) } @$t;
next if $newt[0] =~ /_/;
# Rename the test (add "x_" prefix, for execution)
$newt[0] = 'x_' . $newt[0];
# Add non-empty input.
push @newt, {IN=>"1\n2\n3\n4\n"};
push @xtests, \@newt;
}
push @Tests, @xtests;
my $save_temps = $ENV{SAVE_TEMPS};
my $verbose = $ENV{VERBOSE};
my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
exit $fail;
|