1
0
mirror of https://github.com/moparisthebest/curl synced 2025-01-11 05:58:01 -05:00

runtests: turn preprocessing into a separate function

... and remove all other variable substitutions as they're now done once
and for all in the preprocessor.
This commit is contained in:
Daniel Stenberg 2021-01-18 09:16:41 +01:00
parent 7542ec5b32
commit bbfad7e8a1
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -3369,15 +3369,6 @@ sub subNewlines {
} }
} }
sub fixarray {
my @in = @_;
for(@in) {
subVariables(\$_);
}
return @in;
}
####################################################################### #######################################################################
# Provide time stamps for single test skipped events # Provide time stamps for single test skipped events
# #
@ -3428,6 +3419,46 @@ sub timestampskippedevents {
} }
} }
#
# 'prepro' processes the input array and replaces %-variables in the array
# etc. Returns the processed version of the array
sub prepro {
my (@entiretest) = @_;
my $show = 1;
my @out;
for my $s (@entiretest) {
my $f = $s;
if($s =~ /^ *%if (.*)/) {
my $cond = $1;
my $rev = 0;
if($cond =~ /^!(.*)/) {
$cond = $1;
$rev = 1;
}
$rev ^= $feature{$cond} ? 1 : 0;
$show = $rev;
next;
}
elsif($s =~ /^ *%else/) {
$show ^= 1;
next;
}
elsif($s =~ /^ *%endif/) {
$show = 1;
next;
}
if($show) {
subVariables(\$s, "%");
subBase64(\$s);
subNewlines(\$s) if($has_hyper);
push @out, $s;
}
}
return @out;
}
####################################################################### #######################################################################
# Run a single specified test case # Run a single specified test case
# #
@ -3586,52 +3617,16 @@ sub singletest {
# "basic" test case readers to enjoy variable replacements. # "basic" test case readers to enjoy variable replacements.
my @entiretest = fulltest(); my @entiretest = fulltest();
my $otest = "log/test$testnum"; my $otest = "log/test$testnum";
open(D, ">$otest");
my $diff;
my $show = 1;
for my $s (@entiretest) {
my $f = $s;
if($s =~ /^ *%if (.*)/) {
my $cond = $1;
my $rev = 0;
if($cond =~ /^!(.*)/) { @entiretest = prepro(@entiretest);
$cond = $1;
$rev = 1; # save the new version
} open(D, ">$otest");
$rev ^= $feature{$cond} ? 1 : 0; print D @entiretest;
$show = $rev;
next;
}
elsif($s =~ /^ *%else/) {
$show ^= 1;
next;
}
elsif($s =~ /^ *%endif/) {
$show = 1;
next;
}
if($show) {
subVariables(\$s, "%");
subBase64(\$s);
subNewlines(\$s) if($has_hyper);
if($f ne $s) {
$diff++;
}
print D $s;
}
else {
$diff++;
}
}
close(D); close(D);
# remove the separate test file again if nothing was updated to keep
# things simpler
unlink($otest) if(!$diff);
# in case the process changed the file, reload it # in case the process changed the file, reload it
loadtest("log/test${testnum}") if($diff); loadtest("log/test${testnum}");
# timestamp required servers verification end # timestamp required servers verification end
$timesrvrend{$testnum} = Time::HiRes::time(); $timesrvrend{$testnum} = Time::HiRes::time();
@ -3640,7 +3635,6 @@ sub singletest {
if(@setenv) { if(@setenv) {
foreach my $s (@setenv) { foreach my $s (@setenv) {
chomp $s; chomp $s;
subVariables(\$s);
if($s =~ /([^=]*)=(.*)/) { if($s =~ /([^=]*)=(.*)/) {
my ($var, $content) = ($1, $2); my ($var, $content) = ($1, $2);
# remember current setting, to restore it once test runs # remember current setting, to restore it once test runs
@ -3672,7 +3666,6 @@ sub singletest {
if(@precheck) { if(@precheck) {
$cmd = $precheck[0]; $cmd = $precheck[0];
chomp $cmd; chomp $cmd;
subVariables(\$cmd);
if($cmd) { if($cmd) {
my @p = split(/ /, $cmd); my @p = split(/ /, $cmd);
if($p[0] !~ /\//) { if($p[0] !~ /\//) {
@ -3751,23 +3744,20 @@ sub singletest {
map s/\n/\r\n/g, @reply; map s/\n/\r\n/g, @reply;
} }
} }
for my $r (@reply) {
subVariables(\$r);
}
# this is the valid protocol blurb curl should generate # this is the valid protocol blurb curl should generate
my @protocol= fixarray ( getpart("verify", "protocol") ); my @protocol= getpart("verify", "protocol");
# this is the valid protocol blurb curl should generate to a proxy # this is the valid protocol blurb curl should generate to a proxy
my @proxyprot = fixarray ( getpart("verify", "proxy") ); my @proxyprot = getpart("verify", "proxy");
# redirected stdout/stderr to these files # redirected stdout/stderr to these files
$STDOUT="$LOGDIR/stdout$testnum"; $STDOUT="$LOGDIR/stdout$testnum";
$STDERR="$LOGDIR/stderr$testnum"; $STDERR="$LOGDIR/stderr$testnum";
# if this section exists, we verify that the stdout contained this: # if this section exists, we verify that the stdout contained this:
my @validstdout = fixarray ( getpart("verify", "stdout") ); my @validstdout = getpart("verify", "stdout");
my @validstderr = fixarray ( getpart("verify", "stderr") ); my @validstderr = getpart("verify", "stderr");
# if this section exists, we verify upload # if this section exists, we verify upload
my @upload = getpart("verify", "upload"); my @upload = getpart("verify", "upload");
@ -3780,7 +3770,7 @@ sub singletest {
} }
# if this section exists, it might be FTP server instructions: # if this section exists, it might be FTP server instructions:
my @ftpservercmd = fixarray ( getpart("reply", "servercmd") ); my @ftpservercmd = getpart("reply", "servercmd");
my $CURLOUT="$LOGDIR/curl$testnum.out"; # curl output if not stdout my $CURLOUT="$LOGDIR/curl$testnum.out"; # curl output if not stdout
@ -3818,7 +3808,6 @@ sub singletest {
# make some nice replace operations # make some nice replace operations
$cmd =~ s/\n//g; # no newlines please $cmd =~ s/\n//g; # no newlines please
# substitute variables in the command line # substitute variables in the command line
subVariables(\$cmd);
} }
else { else {
# there was no command given, use something silly # there was no command given, use something silly
@ -3840,7 +3829,6 @@ sub singletest {
return -1; return -1;
} }
my $fileContent = join('', @inputfile); my $fileContent = join('', @inputfile);
subVariables(\$fileContent);
open(OUTFILE, ">$filename"); open(OUTFILE, ">$filename");
binmode OUTFILE; # for crapage systems, use binary binmode OUTFILE; # for crapage systems, use binary
if($fileattr{'nonewline'}) { if($fileattr{'nonewline'}) {
@ -4112,7 +4100,6 @@ sub singletest {
if(@postcheck) { if(@postcheck) {
$cmd = join("", @postcheck); $cmd = join("", @postcheck);
chomp $cmd; chomp $cmd;
subVariables(\$cmd);
if($cmd) { if($cmd) {
logmsg "postcheck $cmd\n" if($verbose); logmsg "postcheck $cmd\n" if($verbose);
my $rc = runclient("$cmd"); my $rc = runclient("$cmd");
@ -4172,9 +4159,6 @@ sub singletest {
@actual = @newgen; @actual = @newgen;
} }
# variable-replace in the stdout we have from the test case file
@validstdout = fixarray(@validstdout);
# get all attributes # get all attributes
my %hash = getpartattr("verify", "stdout"); my %hash = getpartattr("verify", "stdout");
@ -4223,9 +4207,6 @@ sub singletest {
@actual = @newgen; @actual = @newgen;
} }
# variable-replace in the stderr we have from the test case file
@validstderr = fixarray(@validstderr);
# get all attributes # get all attributes
my %hash = getpartattr("verify", "stderr"); my %hash = getpartattr("verify", "stderr");
@ -4281,7 +4262,7 @@ sub singletest {
# what parts to cut off from the protocol # what parts to cut off from the protocol
my @strippart = getpart("verify", "strippart"); my @strippart = getpart("verify", "strippart");
my $strip; my $strip;
@strippart = fixarray(@strippart);
for $strip (@strippart) { for $strip (@strippart) {
chomp $strip; chomp $strip;
for(@out) { for(@out) {
@ -4436,8 +4417,6 @@ sub singletest {
@generated = @newgen; @generated = @newgen;
} }
@outfile = fixarray(@outfile);
$res = compare($testnum, $testname, "output ($filename)", $res = compare($testnum, $testname, "output ($filename)",
\@generated, \@outfile); \@generated, \@outfile);
if($res) { if($res) {