From 9504be7d78ddf8442df369f2f26c4c4305f4849d Mon Sep 17 00:00:00 2001 From: brectanus Date: Thu, 20 Dec 2007 19:22:13 +0000 Subject: [PATCH] Fix a bug in testing framework where NUL is lost in parameter and add support for running only a single test in a conf file. --- apache2/msc_test.c | 2 +- apache2/t/run-tests.pl | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/apache2/msc_test.c b/apache2/msc_test.c index 0988ebfd..b0095ec2 100644 --- a/apache2/msc_test.c +++ b/apache2/msc_test.c @@ -323,7 +323,7 @@ int main(int argc, const char * const argv[]) type = argv[1]; name = argv[2]; param_len = strlen(argv[3]); - param = apr_pmemdup(g_mp, argv[3], param_len); + param = (unsigned char *)apr_pstrmemdup(g_mp, argv[3], param_len); unescape_inplace(param, ¶m_len); if (argc >= 5) { returnval = argv[4]; diff --git a/apache2/t/run-tests.pl b/apache2/t/run-tests.pl index 4c265cf7..5eb185e3 100755 --- a/apache2/t/run-tests.pl +++ b/apache2/t/run-tests.pl @@ -1,4 +1,12 @@ #!/usr/bin/perl +# +# Run unit tests. +# +# Syntax: +# All: run-tests.pl +# All in file: run-tests.pl file +# Nth in file: run-tests.pl file N +# use strict; use File::Basename qw(basename dirname); @@ -10,7 +18,7 @@ my $PASSED = 0; my $TOTAL = 0; if (defined $ARGV[0]) { - runfile(dirname($ARGV[0]), basename($ARGV[0])); + runfile(dirname($ARGV[0]), basename($ARGV[0]), $ARGV[1]); done(); } @@ -32,7 +40,7 @@ done(); sub runfile { - my($dir, $cfg) = @_; + my($dir, $cfg, $testnum) = @_; my $fn = "$dir/$cfg"; my @data = (); my $edata; @@ -54,8 +62,11 @@ sub runfile { msg("\nLoaded ".@C." tests from $fn"); for my $t (@C) { + $n++; + next if (defined $testnum and $n != $testnum); + my %t = %{$t || {}}; - my $id = sprintf("%6d", $n + 1); + my $id = sprintf("%6d", $n); my $in = $t{input}; my $out = escape($t{output}); # Escape so we can send via commandline quit(1, "Failed to interpret output \"$cfg\": $@") if ($@); @@ -76,7 +87,6 @@ sub runfile { print TEST "$in"; close TEST; - $n++; $rc = $?; $pass += $rc ? 0 : 1; @@ -84,10 +94,10 @@ sub runfile { } - $TOTAL += $n; + $TOTAL += $testnum ? 1 : $n; $PASSED += $pass; - msg(sprintf("Passed: %2d; Failed %2d", $pass, ($n - $pass))); + msg(sprintf("Passed: %2d; Failed %2d", $pass, $testnum ? (1 - $pass) : ($n - $pass))); } sub escape {