Highlight: Stopped waiting for the request line. Timeout: 121.
[privoxy.git] / tools / privoxy-regression-test.pl
index b2d16f5..40c64e4 100755 (executable)
@@ -7,7 +7,7 @@
 # A regression test "framework" for Privoxy. For documentation see:
 # perldoc privoxy-regression-test.pl
 #
-# $Id: privoxy-regression-test.pl,v 1.52 2009/09/18 17:30:59 fabiankeil Exp $
+# $Id: privoxy-regression-test.pl,v 1.54 2009/10/01 15:05:26 fabiankeil Exp $
 #
 # Wish list:
 #
@@ -655,43 +655,21 @@ sub register_dependency ($$) {
 sub execute_regression_test ($) {
 
     my $test = shift;
-    my $result = 0;
-
-    if ($test->{'type'} == CLIENT_HEADER_TEST) {
-
-        $result = execute_client_header_regression_test($test);
-
-    } elsif ($test->{'type'} == SERVER_HEADER_TEST) {
-
-        $result = execute_server_header_regression_test($test);
-
-    } elsif ($test->{'type'} == DUMB_FETCH_TEST
-          or $test->{'type'} == TRUSTED_CGI_REQUEST) {
-
-        $result = execute_dumb_fetch_test($test);
-
-    } elsif ($test->{'type'} == METHOD_TEST) {
-
-        $result = execute_method_test($test);
-
-    } elsif ($test->{'type'} == BLOCK_TEST) {
-
-        $result = execute_block_test($test);
-
-    } elsif ($test->{'type'} == STICKY_ACTIONS_TEST) {
-
-        $result = execute_sticky_actions_test($test);
-
-    } elsif ($test->{'type'} == REDIRECT_TEST) {
-
-        $result = execute_redirect_test($test);
-
-    } else {
-
-        die "Unsupported test type detected: " . $test->{'type'};
-    }
-
-    return $result;
+    my $type = $test->{'type'};
+    my %test_subs = (
+        (CLIENT_HEADER_TEST) => \&execute_client_header_regression_test,
+        (SERVER_HEADER_TEST) => \&execute_server_header_regression_test,
+        (DUMB_FETCH_TEST) => \&execute_dumb_fetch_test,
+        (TRUSTED_CGI_REQUEST) => \&execute_dumb_fetch_test,
+        (METHOD_TEST) => \&execute_method_test,
+        (BLOCK_TEST) => \&execute_block_test,
+        (STICKY_ACTIONS_TEST) => \&execute_sticky_actions_test,
+        (REDIRECT_TEST) => \&execute_redirect_test);
+
+    die "Unsupported test type detected: " . $type
+        unless defined ($test_subs{$type});
+
+    return $test_subs{$type}($test);
 }
 
 sub execute_method_test ($) {
@@ -721,16 +699,17 @@ sub execute_redirect_test ($) {
     my $test = shift;
     my $buffer_ref;
     my $status_code;
-    my $curl_parameters;
 
-    my $redirect_destination = 'NONE';
+    my $curl_parameters = '';
     my $url = $test->{'data'};
+    my $redirect_destination;
     my $expected_redirect_destination = $test->{'redirect destination'};
 
-    # XXX: Verify that a redirect applies before actually doing the request.
-    #      Otherwise the test may hit a real server in failure cases.
+    # XXX: Check if a redirect actualy applies before doing the request.
+    #      otherwise the test may hit a real server in failure cases.
+
+    $curl_parameters .= '--head ';
 
-    $curl_parameters = '--head ';
     $curl_parameters .= quote($url);
 
     $buffer_ref = get_page_with_curl($curl_parameters);
@@ -742,7 +721,6 @@ sub execute_redirect_test ($) {
           . "' but got a response with status code: " . $status_code);
         return 0;
     }
-
     foreach (@{$buffer_ref}) {
         if (/^Location: (.*)\r\n/) {
             $redirect_destination = $1;
@@ -1674,7 +1652,7 @@ header to a trusted value.
 
 If no explicit status code expectation is set, B<200> is used.
 
-To verify that an URL is blocked, use:
+To verify that a URL is blocked, use:
 
     # Blocked URL = http://www.example.com/blocked