On Tue, Apr 12, 2005 at 02:02:07PM -0400, Sam Tregar wrote:
> On Tue, 12 Apr 2005, Paul Johnson wrote:
>
> > I would do it in the same way as if this had nothing to do with tests.
> > That is, abstract away the common code into a module, which can also
> > live under t/
>
> That would be a lot of work in this case. I found an easier
> solution. In tweek-then-foo.t:
>
> {
> local $ENV{SUB_TEST} = 1;
> do 't/foo.t' or die ...;
> }
That's almost exactly what the DBI does when testing DBI::PurePerl.
#!perl -w
local $ENV{DBI_PUREPERL} = 2;
do 't/01basics.t' or warn $!;
die if $@;
exit 0
I found the "... or warn $!; die if $@;" incantation worked best.
The DBI's Makefile.PL automatically writes a zvpp_*.t for all
existing *.t files. I've appended the code that does that.
Note the extra wrinkle to DTRT for threads.
Tim.
foreach my $test (sort @tests) {
next if $test !~ /^[0-8]/;
my $usethr = ($test =~ /(\d+|\b)thr/ && $] >= 5.008 &&
$Config{useithreads});
while ( my ($v_type, $v_info) = each %test_variants ) {
my $v_test = "t/zv${v_type}_$test";
printf "Creating %-16s test variant: $v_test %s\n",
$v_info->{name}, ($usethr) ? "(use threads)" : "";
open PPT, ">$v_test" or warn "Can't create $v_test: $!";
print PPT "#!perl -w\n";
print PPT "use threads;\n" if $usethr;
print PPT "$_\n" foreach @{$v_info->{add}};
print PPT "do 't/$test' or warn \$!;\n";
print PPT 'die if $@;'."\n";
print PPT "exit 0\n";
close PPT or warn "Error writing $v_test: $!";
}
}