Skip to content

Commit bcd88a0

Browse files
authored
Merge pull request diffblue#1821 from smowton/smowton/feature/test-pl-tags
test.pl: add support for tagging test-cases
2 parents ae6775a + 45f0939 commit bcd88a0

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

regression/test.pl

+33-8
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ ($)
6666
return @data;
6767
}
6868

69-
sub test($$$$$$$) {
70-
my ($name, $test, $t_level, $cmd, $ign, $dry_run, $defines) = @_;
71-
my ($level, $input, $options, $grep_options, @results) = load("$test");
69+
sub test($$$$$$$$$) {
70+
my ($name, $test, $t_level, $cmd, $ign, $dry_run, $defines, $include_tags, $exclude_tags) = @_;
71+
my ($level_and_tags, $input, $options, $grep_options, @results) = load("$test");
7272
my @keys = keys %{$defines};
7373
foreach my $key (@keys) {
7474
my $value = $defines->{$key};
@@ -82,6 +82,28 @@ ($$$$$$$)
8282
}
8383
}
8484

85+
my @tags = split(/\s/, $level_and_tags);
86+
my $level = shift @tags;
87+
my %tags_set = map { $_ => 1 } @tags;
88+
89+
# If the user has passes -I (include-tag) or -X (exclude-tag) options, then
90+
# run the test only if it matches no exclude-tags and either include-tags is
91+
# not given (implying run all tests) or it matches at least one include-tag.
92+
93+
my $include_tags_length = @$include_tags;
94+
my $passes_tag_tests = ($include_tags_length == 0);
95+
foreach my $include_tag (@$include_tags) {
96+
if(exists($tags_set{$include_tag})) {
97+
$passes_tag_tests = 1;
98+
}
99+
}
100+
101+
foreach my $exclude_tag (@$exclude_tags) {
102+
if(exists($tags_set{$exclude_tag})) {
103+
$passes_tag_tests = 0;
104+
}
105+
}
106+
85107
# If the 4th line is activate-multi-line-match we enable multi-line checks
86108
if($grep_options ne "activate-multi-line-match") {
87109
# No such flag, so we add it back in
@@ -124,7 +146,7 @@ ($$$$$$$)
124146
}
125147

126148
my $failed = 2;
127-
if($level & $t_level) {
149+
if(($level & $t_level) && $passes_tag_tests) {
128150

129151
if ($dry_run) {
130152
return 0;
@@ -244,12 +266,14 @@ ($$$$)
244266
-K known: run tests associated with known bugs
245267
-D <key=value> Define - replace \$key string with "value" string in
246268
test descriptors
269+
-I <tag> run only tests that have the given secondary tag. Can be repeated.
270+
-X <tag> exclude tests that have the given secondary tag. Can be repeated.
247271
248272
249273
test.pl expects a test.desc file in each subdirectory. The file test.desc
250274
follows the format specified below. Any line starting with // will be ignored.
251275
252-
<level>
276+
<level> [<tag1> [<tag2>...]]
253277
<main source>
254278
<options>
255279
<activate-multi-line-match>
@@ -261,6 +285,7 @@ ($$$$)
261285
262286
where
263287
<level> is one of CORE, THOROUGH, FUTURE or KNOWNBUG
288+
<tag1>, <tag2> ... <tagn> are zero or more space-separated secondary tags, for use with the -I and -X parameters
264289
<main source> is a file with extension .c/.i/.gb/.cpp/.ii/.xml/.class/.jar
265290
<options> additional options to be passed to CMD
266291
<activate-multi-line-match> The fourth line can optionally be activate-multi-line-match, if this is the
@@ -278,9 +303,9 @@ ($$$$)
278303
use Getopt::Long qw(:config pass_through bundling);
279304
$main::VERSION = 0.1;
280305
$Getopt::Std::STANDARD_HELP_VERSION = 1;
281-
our ($opt_c, $opt_i, $opt_j, $opt_n, $opt_p, $opt_h, $opt_C, $opt_T, $opt_F, $opt_K, %defines); # the variables for getopt
306+
our ($opt_c, $opt_i, $opt_j, $opt_n, $opt_p, $opt_h, $opt_C, $opt_T, $opt_F, $opt_K, %defines, @include_tags, @exclude_tags); # the variables for getopt
282307
$opt_j = 0;
283-
GetOptions("D=s", \%defines);
308+
GetOptions("D=s" => \%defines, "X=s" => \@exclude_tags, "I=s" => \@include_tags);
284309
getopts('c:i:j:nphCTFK') or &main::HELP_MESSAGE(\*STDOUT, "", $main::VERSION, "");
285310
$opt_c or &main::HELP_MESSAGE(\*STDOUT, "", $main::VERSION, "");
286311
(!$opt_j || $has_thread_pool) or &main::HELP_MESSAGE(\*STDOUT, "", $main::VERSION, "");
@@ -319,7 +344,7 @@ ($)
319344
defined($pool) or print " Running $files[$_]";
320345
my $start_time = time();
321346
$failed_skipped = test(
322-
$test, $files[$_], $t_level, $opt_c, $opt_i, $dry_run, \%defines);
347+
$test, $files[$_], $t_level, $opt_c, $opt_i, $dry_run, \%defines, \@include_tags, \@exclude_tags);
323348
my $runtime = time() - $start_time;
324349

325350
lock($skips);

0 commit comments

Comments
 (0)