From f414884978fe4f6697e62fffe3d314925d8d46ab Mon Sep 17 00:00:00 2001
From: Fabian Keil <fk@fabiankeil.de>
Date: Sat, 17 Nov 2012 12:12:42 +0100
Subject: [PATCH 3/4] runtests.pl: Add an -m option to specify a "test
 manifest" file

It's supposed to change runtests.pl's behaviour in various
ways but at the moment it can only contain restraints for
test numbers, keywords and tools.

The syntax should be changed to be extendable and maybe
more closely reflect the "curl test" syntax. Currently
it's a bunch of lines like these:

test:$TESTNUMBER:Reason why this test with number $TESTNUMBER should be skipped
keyword:$KEYWORD:Reason why tests whose keywords contain the $KEYWORD should be skipped
tool:$TOOL:Reason why tests with tools that contain $TOOL should be skipped

The idea is to let third parties like the Privoxy project
distribute a manifest file with their tarballs that specifies
which curl tests are expected to work, without having to
fork the whole curl test suite.

It would make sense to let the manifest specify additional
(project-specific) tests directories and provide additional
command line arguments for runtests.pl.
---
 tests/runtests.pl | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/tests/runtests.pl b/tests/runtests.pl
index b8ec7f9..ab66987 100755
--- a/tests/runtests.pl
+++ b/tests/runtests.pl
@@ -116,6 +116,7 @@ my $CLIENT6IP="[::1]";    # address which curl uses for incoming connections
 
 my $use_external_proxy = 0;
 my $proxy_address;
+my %custom_skip_reasons;
 
 my $base = 8990; # base port number
 
@@ -3130,6 +3131,31 @@ sub singletest {
         }
     }
 
+    if (!$why && defined $custom_skip_reasons{test}{$testnum}) {
+        $why = $custom_skip_reasons{test}{$testnum};
+    }
+
+    if (!$why && defined $custom_skip_reasons{tool}) {
+        foreach my $tool (getpart("client", "tool")) {
+            foreach my $tool_skip_pattern (keys $custom_skip_reasons{tool}) {
+                if ($tool =~ /$tool_skip_pattern/i) {
+                    $why = $custom_skip_reasons{tool}{$tool_skip_pattern};
+                }
+            }
+        }
+    }
+
+    if (!$why && defined $custom_skip_reasons{keyword}) {
+        foreach my $keyword (getpart("info", "keywords")) {
+            foreach my $keyword_skip_pattern (keys $custom_skip_reasons{keyword}) {
+                if ($keyword =~ /$keyword_skip_pattern/i) {
+                    $why = $custom_skip_reasons{keyword}{$keyword_skip_pattern};
+                }
+            }
+        }
+    }
+
+
     # test definition may instruct to (un)set environment vars
     # this is done this early, so that the precheck can use environment
     # variables and still bail out fine on errors
@@ -4772,6 +4798,24 @@ while(@ARGV) {
         $use_external_proxy=1;
         $proxy_address=$ARGV[0];
     }
+    elsif($ARGV[0] eq "-m") {
+        shift @ARGV;
+        my $manifest = $ARGV[0];
+        open(my $fd, "<", $manifest) or die "Couldn't open '$manifest': $!";
+        while (my $line = <$fd>) {
+            next if ($line =~ /^#/);
+            chomp $line;
+            my ($type, $pattern, $skip_reason) = split(/\s*:\s*/, $line, 3);
+
+            die "Unsupported type: $type\n" if($type !~ /^keyword|test|tool$/);
+            if ($type =~ /^test$/) {
+                # Strip leading zeros in the test number
+                $pattern = int($pattern);
+            }
+            $custom_skip_reasons{$type}{$pattern} = $skip_reason;
+        }
+        close($fd);
+    }
     elsif($ARGV[0] eq "-l") {
         # lists the test case names only
         $listonly=1;
@@ -4822,6 +4866,7 @@ Usage: runtests.pl [options] [test selection(s)]
   -H  addr use the specified IPv4 host IP address instead of the default
   -k       keep stdout and stderr files present after tests
   -l       list all test case names/descriptions
+  -m file  load the specifed test manifest to decide which tests get executed
   -n       no valgrind
   -p       print log file contents when a test fails
   -P proxy use the specified proxy
-- 
1.9.0


