]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
testutil: make runtests support %include
authorDaniel Stenberg <daniel@haxx.se>
Sun, 31 Dec 2023 15:27:46 +0000 (16:27 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 2 Jan 2024 07:44:06 +0000 (08:44 +0100)
Using this instruction, a test case can include the contents of a file
into the test during the preprocessing.

Closes #12612

tests/FILEFORMAT.md
tests/testutil.pm

index 665d93eb855a559de0ece21486b9375f70e9d9a5..5a8e7832323561dfc31e6b7e4f4a923f89819047 100644 (file)
@@ -74,6 +74,17 @@ For example, to insert the word hello 100 times:
 
     %repeat[100 x hello]%
 
+## Include file
+
+This instruction allows a test case to include another file. It is helpful to
+remember that the ordinary variables are expanded before the include happens
+so `%LOGDIR` and the others can be used in the include line.
+
+The file name cannot contain `%` as that letter is used to end the name for
+the include instruction:
+
+    %include filename%
+
 ## Conditional lines
 
 Lines in the test file can be made to appear conditionally on a specific
index ece0b6e0539e95247a65cbe29cdf078bfcb47138..1a44083e1bf24bb579b972ab084aeb922310e9e8 100644 (file)
@@ -94,6 +94,15 @@ sub clearlogs {
 
 
 #######################################################################
+
+sub includefile {
+    my ($f) = @_;
+    open(F, "<$f");
+    my @a = <F>;
+    close(F);
+    return join("", @a);
+}
+
 sub subbase64 {
     my ($thing) = @_;
 
@@ -113,6 +122,7 @@ sub subbase64 {
         $d =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
         $$thing =~ s/%%HEX%%/$d/;
     }
+    # repeat
     while($$thing =~ s/%repeat\[(\d+) x (.*?)\]%/%%REPEAT%%/i) {
         # decode %NN characters
         my ($d, $n) = ($2, $1);
@@ -120,6 +130,9 @@ sub subbase64 {
         my $all = $d x $n;
         $$thing =~ s/%%REPEAT%%/$all/;
     }
+
+    # include a file
+    $$thing =~ s/%include ([^%]*)%[\n\r]+/includefile($1)/ge;
 }
 
 my $prevupdate;  # module scope so it remembers the last value