# A regression test "framework" for Privoxy. For documentation see:
# perldoc privoxy-regression-test.pl
#
-# $Id: privoxy-regression-test.pl,v 1.104 2008/01/21 18:23:49 fk Exp $
+# $Id: privoxy-regression-test.pl,v 1.110 2008/02/16 12:55:18 fk Exp fk $
#
# Wish list:
#
use Getopt::Long;
use constant {
- PRT_VERSION => 'Privoxy-Regression-Test 0.2',
+ PRT_VERSION => 'Privoxy-Regression-Test 0.2',
- CURL => 'curl',
+ CURL => 'curl',
# CLI option defaults
CLI_RETRIES => 1,
sub load_regressions_tests () {
our $privoxy_cgi_url;
+ our @privoxy_config;
my @actionfiles;
- my $curl_url = '';
+ my $curl_url = '';
my $file_number = 0;
$curl_url .= $privoxy_cgi_url;
foreach (@{get_cgi_page_or_else($curl_url)}) {
+ chomp;
if (/<td>(.*?)<\/td><td class=\"buttons\"><a href=\"\/show-status\?file=actions&index=(\d+)\">/) {
my $url = $privoxy_cgi_url . 'show-status?file=actions&index=' . $2;
$actionfiles[$file_number++] = $url;
+
+ } elsif (m@config\.html#.*\">([^<]*)</a>\s+(.*)<br>@) {
+
+ my $directive = $1 . " " . $2;
+ push (@privoxy_config, $directive);
}
}
$count++;
enlist_new_test(\@regression_tests, $token, $value, $si, $ri, $count);
}
+
+ if ($token =~ /level\s+(\d+)/i) {
+
+ my $level = $1;
+ register_dependency($level, $value);
+ }
if ($si == -1 || $ri == -1) {
# No beginning of a test detected yet,
l(LL_FILE_LOADING, "Method: " . $value);
$regression_tests[$si][$ri]{'method'} = $value;
+
} else {
+
# We don't use it, so we don't need
$no_checks = 1;
}
}
-
if (get_cli_option('loops') > 1) {
log_message("Total: Executed " . $all_tests . " regression tests. " .
$all_successes . " successes, " . $all_failures . " failures.");
return ((cli_option_is_set('level') and get_cli_option('level') != $level)
or ($level < get_cli_option('min-level'))
or ($level > get_cli_option('max-level'))
+ or dependency_unsatisfied($level)
);
}
and get_cli_option('test-number') != $test_number)
}
+sub dependency_unsatisfied ($) {
+
+ my $level = shift;
+ our %dependencies;
+ our @privoxy_config;
+ my $dependency_problem = 0;
+
+ if (defined ($dependencies{$level}{'config line'})) {
+
+ my $dependency = $dependencies{$level}{'config line'};
+ $dependency_problem = 1;
+
+ foreach (@privoxy_config) {
+
+ $dependency_problem = 0 if (/$dependency/);
+ }
+ }
+
+ return $dependency_problem;
+}
+
+sub register_dependency ($$) {
+
+ my $level = shift;
+ my $dependency = shift;
+ our %dependencies;
+
+ if ($dependency =~ /config line\s+(.*)/) {
+
+ $dependencies{$level}{'config line'} = $1;
+ }
+}
# XXX: somewhat misleading name
sub execute_regression_test ($) {
}
-
return $result;
}
my $curl_parameters = '';
my $expected_status_code = $test{'expected-status-code'};
- if ($method =~ /HEAD/i) {
-
- $curl_parameters .= '--head ';
-
- } else {
-
- $curl_parameters .= '-X ' . $method . ' ';
- }
+ $curl_parameters .= '--request ' . $method . ' ';
+ # Don't complain in case about the 'missing' body
+ $curl_parameters .= '--head ' if ($method =~ /^HEAD$/i);
$curl_parameters .= PRIVOXY_CGI_URL;
return $result;
}
-
sub execute_dumb_fetch_test ($) {
my $test_ref = shift;
my $expected_status_code = $test{'expected-status-code'};
if (defined $test{method}) {
- $curl_parameters .= '-X ' . $test{method} . ' ';
+ $curl_parameters .= '--request ' . $test{method} . ' ';
}
if ($test{type} == TRUSTED_CGI_REQUEST) {
$curl_parameters .= '--referer ' . PRIVOXY_CGI_URL . ' ';
return $success;
}
-
sub get_header_name ($) {
my $header = shift;
if ($expect_header eq 'REMOVAL'
or $expect_header eq 'NO CHANGE'
- or $expect_header eq 'SOME CHANGE') {
+ or $expect_header eq 'SOME CHANGE') {
$expect_header = $test{'data'};
foreach (@buffer) {
- # XXX: shoul probably verify that the request
+ # XXX: should probably verify that the request
# was actually answered by Fellatio.
if (/^$header_to_get/) {
$header = $_;
return $header;
}
-sub get_header_to_check ($) {
-
- # No longer in use but not removed yet.
-
- my $buffer_ref = shift;
- my $header;
- my @buffer = @{$buffer_ref};
- my $line;
- my $processed_request_reached = 0;
- my $read_header = 0;
- my $processed_request = '';
-
- l(LL_ERROR, "You are not supposed to use get_header_to_()!");
-
- foreach (@buffer) {
-
- # Skip everything before the Processed request
- if (/Processed Request/) {
- $processed_request_reached = 1;
- next;
- }
- next unless $processed_request_reached;
-
- # End loop after the Processed request
- last if (/<\/pre>/);
-
- # Ditch tags and leading/trailing white space.
- s@^\s*<.*?>@@g;
- s@\s*$@@g;
-
- $processed_request .= $_;
-
- if (/^X-Privoxy-Regression-Test/) {
- $read_header = 1;
- next;
- }
-
- if ($read_header) {
- $header = $_;
- $read_header = 0;
- }
-
- }
-
- return $header;
-}
-
sub get_status_code ($) {
my $buffer_ref = shift;
my $s = "\n\t";
foreach my $key (get_test_keys()) {
- #$test{$key} = $test{$key} // 'undefined';
$test{$key} = 'Not set' unless (defined $test{$key});
}
$curl_line .= ' --proxy ' . get_cli_option('privoxy-address');
}
+ # We want to see the HTTP status code
+ $curl_line .= " --include ";
# Let Privoxy emit two log messages less.
$curl_line .= ' -H \'Proxy-Connection:\' ' unless $parameters =~ /Proxy-Connection:/;
$curl_line .= ' -H \'Connection: close\' ' unless $parameters =~ /Connection:/;
$curl_line .= " -s ";
# We do care about the failure reason if any.
$curl_line .= " -S ";
- # We want to see the HTTP status code
- $curl_line .= " --include ";
# We want to advertise ourselves
$curl_line .= " --user-agent '" . PRT_VERSION . "' ";
# We aren't too patient
return defined $cli_options{$cli_option};
}
-
sub get_cli_option ($) {
our %cli_options;
return $cli_options{$cli_option};
}
-
sub main () {
init_our_variables();