From: Jarkko Hietaniemi Date: Thu, 17 Jan 2002 14:39:20 +0000 (+0000) Subject: Rename kill_perl to fresh_perl; replace fresh_perl() X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f5cda3312a6c23399b23c70aea893ce8a70c7d94;p=p5sagit%2Fp5-mst-13.2.git Rename kill_perl to fresh_perl; replace fresh_perl() with fresh_perl_is() and fresh_perl_like(). p4raw-id: //depot/perl@14309 --- diff --git a/MANIFEST b/MANIFEST index f8a6289..605acf0 100644 --- a/MANIFEST +++ b/MANIFEST @@ -2343,7 +2343,7 @@ t/pod/testpchk.pl Module to test Pod::Checker for a given file t/pod/testpods/lib/Pod/Stuff.pm Sample data for find.t t/README Instructions for regression tests t/run/exit.t Test perl's exit status. -t/run/kill_perl.t Tests that kill perl. +t/run/fresh_perl.t Tests that require a fresh perl. t/run/noswitch.t Test aliasing ARGV for other switch tests t/run/runenv.t Test if perl honors its environment variables. t/run/switcha.t Test the -a switch diff --git a/t/run/kill_perl.t b/t/run/fresh_perl.t similarity index 98% rename from t/run/kill_perl.t rename to t/run/fresh_perl.t index 3b46009..73680eb 100644 --- a/t/run/kill_perl.t +++ b/t/run/fresh_perl.t @@ -2,7 +2,7 @@ # ** DO NOT ADD ANY MORE TESTS HERE ** # Instead, put the test in the appropriate test file and use the -# kill_perl() function in t/test.pl. +# fresh_perl_is()/fresh_perl_like() functions in t/test.pl. # This is for tests that will normally cause segfaults, and other nasty # errors that might kill the interpreter and for some reason you can't @@ -52,7 +52,9 @@ foreach my $prog (@prgs) { my($prog,$expected) = split(/\nEXPECT\n/, $raw_prog); - kill_perl($prog, $expected, { switches => [$switch] }, $name); + $expected =~ s/\n+$//; + + fresh_perl_is($prog, $expected, { switches => [$switch] }, $name); } __END__ @@ -280,7 +282,7 @@ print "ok\n" if ("\0" lt "\xFF"); EXPECT ok ######## -open(H,'run/kill_perl.t'); # must be in the 't' directory +open(H,'run/fresh_perl.t'); # must be in the 't' directory stat(H); print "ok\n" if (-e _ and -f _ and -r _); EXPECT diff --git a/t/test.pl b/t/test.pl index 379e136..a00dd5e 100644 --- a/t/test.pl +++ b/t/test.pl @@ -396,8 +396,16 @@ my $tmpfile = "misctmp000"; 1 while -f ++$tmpfile; END { unlink_all $tmpfile } -sub kill_perl { - my($prog, $expected, $runperl_args, $name) = @_; +# +# _fresh_perl +# +# The $resolve must be a subref that tests the first argument +# for success, or returns the definition of success (e.g. the +# expected scalar) if given no arguments. +# + +sub _fresh_perl { + my($prog, $resolve, $runperl_args, $name) = @_; $runperl_args ||= {}; $runperl_args->{progfile} = $tmpfile; @@ -437,19 +445,45 @@ sub kill_perl { $results =~ s/\n\n/\n/g; } - $expected =~ s/\n+$//; - - my $pass = $results eq $expected; + my $pass = $resolve->($results); unless ($pass) { print STDERR "# PROG: $switch\n$prog\n"; - print STDERR "# EXPECTED:\n$expected\n"; + print STDERR "# EXPECTED:\n", $resolve->(), "\n"; print STDERR "# GOT:\n$results\n"; print STDERR "# STATUS: $status\n"; } ($name) = $prog =~ /^(.{1,35})/ unless $name; - _ok($pass, _where(), "kill_perl - $name"); + _ok($pass, _where(), "fresh_perl - $name"); +} + +# +# run_perl_is +# +# Combination of run_perl() and is(). +# + +sub fresh_perl_is { + my($prog, $expected, $runperl_args, $name) = @_; + _fresh_perl($prog, + sub { @_ ? $_[0] eq $expected : $expected }, + $runperl_args, $name); +} + +# +# run_perl_like +# +# Combination of run_perl() and like(). +# + +sub fresh_perl_like { + my($prog, $expected, $runperl_args, $name) = @_; + _fresh_perl($prog, + sub { @_ ? + $_[0] =~ (ref $expected ? $expected : /$expected/) : + $expected }, + $runperl_args, $name); } 1;