tests: add support for nested %if conditions
Provides more flexiblity to test cases. Also warn and bail out if there is an '%else' or %endif' without a preceeding '%if'. Ref: #11610 Closes #11728
This commit is contained in:
parent
bb65f73b5d
commit
3d089c41ea
@ -101,8 +101,7 @@ like:
|
|||||||
Accept-Encoding: nothing
|
Accept-Encoding: nothing
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
**Note** that there can be no nested conditions. You can only do one
|
Nested conditions are supported.
|
||||||
conditional at a time and you can only check for a single feature in it.
|
|
||||||
|
|
||||||
# Variables
|
# Variables
|
||||||
|
|
||||||
|
|||||||
@ -300,8 +300,12 @@ sub prepro {
|
|||||||
my $show = 1;
|
my $show = 1;
|
||||||
my @out;
|
my @out;
|
||||||
my $data_crlf;
|
my $data_crlf;
|
||||||
|
my @pshow;
|
||||||
|
my $plvl;
|
||||||
|
my $line;
|
||||||
for my $s (@entiretest) {
|
for my $s (@entiretest) {
|
||||||
my $f = $s;
|
my $f = $s;
|
||||||
|
$line++;
|
||||||
if($s =~ /^ *%if (.*)/) {
|
if($s =~ /^ *%if (.*)/) {
|
||||||
my $cond = $1;
|
my $cond = $1;
|
||||||
my $rev = 0;
|
my $rev = 0;
|
||||||
@ -311,15 +315,25 @@ sub prepro {
|
|||||||
$rev = 1;
|
$rev = 1;
|
||||||
}
|
}
|
||||||
$rev ^= $feature{$cond} ? 1 : 0;
|
$rev ^= $feature{$cond} ? 1 : 0;
|
||||||
|
push @pshow, $show; # push the previous state
|
||||||
|
$plvl++;
|
||||||
$show = $rev;
|
$show = $rev;
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
elsif($s =~ /^ *%else/) {
|
elsif($s =~ /^ *%else/) {
|
||||||
|
if(!$plvl) {
|
||||||
|
print STDERR "error: test$testnum:$line: %else no %if\n";
|
||||||
|
last;
|
||||||
|
}
|
||||||
$show ^= 1;
|
$show ^= 1;
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
elsif($s =~ /^ *%endif/) {
|
elsif($s =~ /^ *%endif/) {
|
||||||
$show = 1;
|
if(!$plvl--) {
|
||||||
|
print STDERR "error: test$testnum:$line: %endif had no %if\n";
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
$show = pop @pshow;
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
if($show) {
|
if($show) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user