]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tests: add support for nested %if conditions
authorDaniel Stenberg <daniel@haxx.se>
Thu, 24 Aug 2023 21:51:24 +0000 (23:51 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 25 Aug 2023 06:25:25 +0000 (08:25 +0200)
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
tests/runner.pm

index e7245c2b75111fe85384ef3b06818cebd4f3cef9..7adc84720147bbee36a01177913e82f9be4a8bfb 100644 (file)
@@ -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
 
index bb0934c06b8dba0771a88616993905272c51fbc5..5626c39da2f75aef2e62d806f539df59e4beb55a 100644 (file)
@@ -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) {