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:
Daniel Stenberg 2023-08-24 23:51:24 +02:00
parent bb65f73b5d
commit 3d089c41ea
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
2 changed files with 16 additions and 3 deletions

View File

@ -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

View File

@ -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) {