From 3d089c41ea9c0d7a4798e602b010b324c2b5b893 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 24 Aug 2023 23:51:24 +0200 Subject: [PATCH] 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 --- tests/FILEFORMAT.md | 3 +-- tests/runner.pm | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/tests/FILEFORMAT.md b/tests/FILEFORMAT.md index e7245c2b7..7adc84720 100644 --- a/tests/FILEFORMAT.md +++ b/tests/FILEFORMAT.md @@ -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 diff --git a/tests/runner.pm b/tests/runner.pm index bb0934c06..5626c39da 100644 --- a/tests/runner.pm +++ b/tests/runner.pm @@ -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) {