From 62ffa42b7e4c402bea6621c2a4c30a38540d3107 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 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 might make sense to let the manifest specify additional
(project-specific) tests directories and provide additional
command line arguments for runtests.pl.

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

To specify multiple $TESTNUMBERs, $KEYWORDs and $TOOLs
on a single line, split them with commas.
---
 tests/runtests.pl | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/tests/runtests.pl b/tests/runtests.pl
index af21140..f24da4f 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
 
@@ -3055,6 +3056,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
@@ -4698,6 +4724,27 @@ 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, $patterns, $skip_reason) = split(/\s*:\s*/, $line, 3);
+
+            die "Unsupported type: $type\n" if($type !~ /^keyword|test|tool$/);
+
+            foreach my $pattern (split(/,/, $patterns)) {
+                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;
@@ -4747,6 +4794,7 @@ Usage: runtests.pl [options] [test selection(s)]
   -h       this help text
   -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


