From c54a1092fdb66be0e73d54a2444b642fdfebd289 Mon Sep 17 00:00:00 2001
From: Fabian Keil <fk@fabiankeil.de>
Date: Mon, 16 Jun 2014 16:03:00 +0200
Subject: [PATCH 3/6] runtests.pl: Add a %TESTNUMBER variable to make copying
 tests more convenient

---
 tests/runtests.pl | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/tests/runtests.pl b/tests/runtests.pl
index d6401a4..29544a0 100755
--- a/tests/runtests.pl
+++ b/tests/runtests.pl
@@ -2625,7 +2625,7 @@ sub checksystem {
 # a command, in either case passed by reference
 #
 sub subVariables {
-  my ($thing) = @_;
+  my ($thing, $testnum) = @_;
 
   # ports
 
@@ -2679,6 +2679,7 @@ sub subVariables {
   $$thing =~ s/%PWD/$pwd/g;
   $$thing =~ s/%SRCDIR/$srcdir/g;
   $$thing =~ s/%USER/$USER/g;
+  $$thing =~ s/%TESTNUMBER/$testnum/g;
 
   # The purpose of FTPTIME2 and FTPTIME3 is to provide times that can be
   # used for time-out tests and that whould work on most hosts as these
@@ -2693,10 +2694,11 @@ sub subVariables {
 }
 
 sub fixarray {
+    my $testnum = shift;
     my @in = @_;
 
     for(@in) {
-        subVariables \$_;
+        subVariables \$_, $testnum;
     }
     return @in;
 }
@@ -3115,7 +3117,7 @@ sub singletest {
     if(@setenv) {
         foreach my $s (@setenv) {
             chomp $s;
-            subVariables \$s;
+            subVariables \$s, $testnum;
             if($s =~ /([^=]*)=(.*)/) {
                 my ($var, $content) = ($1, $2);
                 # remember current setting, to restore it once test runs
@@ -3155,7 +3157,7 @@ sub singletest {
         if(@precheck) {
             $cmd = $precheck[0];
             chomp $cmd;
-            subVariables \$cmd;
+            subVariables \$cmd, $testnum;
             if($cmd) {
                 my @p = split(/ /, $cmd);
                 if($p[0] !~ /\//) {
@@ -3223,17 +3225,17 @@ sub singletest {
     }
 
     # this is the valid protocol blurb curl should generate
-    my @protocol= fixarray ( getpart("verify", "protocol") );
+    my @protocol= fixarray ( $testnum, getpart("verify", "protocol") );
 
     # this is the valid protocol blurb curl should generate to a proxy
-    my @proxyprot = fixarray ( getpart("verify", "proxy") );
+    my @proxyprot = fixarray ( $testnum, getpart("verify", "proxy") );
 
     # redirected stdout/stderr to these files
     $STDOUT="$LOGDIR/stdout$testnum";
     $STDERR="$LOGDIR/stderr$testnum";
 
     # if this section exists, we verify that the stdout contained this:
-    my @validstdout = fixarray ( getpart("verify", "stdout") );
+    my @validstdout = fixarray ( $testnum, getpart("verify", "stdout") );
 
     # if this section exists, we verify upload
     my @upload = getpart("verify", "upload");
@@ -3280,7 +3282,7 @@ sub singletest {
         # make some nice replace operations
         $cmd =~ s/\n//g; # no newlines please
         # substitute variables in the command line
-        subVariables \$cmd;
+        subVariables \$cmd, $testnum;
     }
     else {
         # there was no command given, use something silly
@@ -3301,7 +3303,7 @@ sub singletest {
             return -1;
         }
         my $fileContent = join('', @inputfile);
-        subVariables \$fileContent;
+        subVariables \$fileContent, $testnum;
 #        logmsg "DEBUG: writing file " . $filename . "\n";
         open(OUTFILE, ">$filename");
         binmode OUTFILE; # for crapage systems, use binary
@@ -3633,7 +3635,7 @@ sub singletest {
     if(@postcheck) {
         $cmd = $postcheck[0];
         chomp $cmd;
-        subVariables \$cmd;
+        subVariables \$cmd, $testnum;
         if($cmd) {
             logmsg "postcheck $cmd\n" if($verbose);
             my $rc = runclient("$cmd");
@@ -3680,7 +3682,7 @@ sub singletest {
         my @actual = loadarray($STDOUT);
 
         # variable-replace in the stdout we have from the test case file
-        @validstdout = fixarray(@validstdout);
+        @validstdout = fixarray($testnum, @validstdout);
 
         # get all attributes
         my %hash = getpartattr("verify", "stdout");
@@ -3881,7 +3883,7 @@ sub singletest {
                 @generated = @newgen;
             }
 
-            @outfile = fixarray(@outfile);
+            @outfile = fixarray($testnum, @outfile);
 
             $res = compare($testnum, $testname, "output ($filename)",
                            \@generated, \@outfile);
-- 
1.9.0


