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
Родитель bb65f73b5d
Коммит 3d089c41ea
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 5CC908FDB71E12C2
2 изменённых файлов: 16 добавлений и 3 удалений

Просмотреть файл

@ -101,8 +101,7 @@ like:
Accept-Encoding: nothing
%endif
**Note** that there can be no nested conditions. You can only do one
conditional at a time and you can only check for a single feature in it.
Nested conditions are supported.
# Variables

Просмотреть файл

@ -300,8 +300,12 @@ sub prepro {
my $show = 1;
my @out;
my $data_crlf;
my @pshow;
my $plvl;
my $line;
for my $s (@entiretest) {
my $f = $s;
$line++;
if($s =~ /^ *%if (.*)/) {
my $cond = $1;
my $rev = 0;
@ -311,15 +315,25 @@ sub prepro {
$rev = 1;
}
$rev ^= $feature{$cond} ? 1 : 0;
push @pshow, $show; # push the previous state
$plvl++;
$show = $rev;
next;
}
elsif($s =~ /^ *%else/) {
if(!$plvl) {
print STDERR "error: test$testnum:$line: %else no %if\n";
last;
}
$show ^= 1;
next;
}
elsif($s =~ /^ *%endif/) {
$show = 1;
if(!$plvl--) {
print STDERR "error: test$testnum:$line: %endif had no %if\n";
last;
}
$show = pop @pshow;
next;
}
if($show) {