Tests running Tests

Hello all.  I've got a test I want to write, but I don't know to write
it (easily).  I've got a test script, call it foo.t which uses
Test::More and runs under Test::Harness.  Now I want to make a new
test script tweek-then-foo.t which tweeks the system and then ensures
that foo.t still passes.  How do I write tweek-then-foo.t?

-sam
0
sam (26)
4/12/2005 5:20:18 PM
perl.qa 2168 articles. 0 followers. Follow

3 Replies
737 Views

Similar Articles

[PageSpeed] 55

On Tue, Apr 12, 2005 at 01:20:18PM -0400, Sam Tregar wrote:

> Hello all.  I've got a test I want to write, but I don't know to write
> it (easily).  I've got a test script, call it foo.t which uses
> Test::More and runs under Test::Harness.  Now I want to make a new
> test script tweek-then-foo.t which tweeks the system and then ensures
> that foo.t still passes.  How do I write tweek-then-foo.t?

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/

-- 
Paul Johnson - paul@pjcj.net
http://www.pjcj.net
0
paul
4/12/2005 5:28:45 PM
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 ...;
  }

And in foo.t, replacing the usual Test::More use line:

  BEGIN {
    unless ($ENV{SUB_TEST}) {
        eval "use Test::More qw(no_plan);";
        die $@ if $@;
    }
  }

Seems to work fine so far, and it definitely is a lot easier than
trying to modularize a rather hairy foo.t.

-sam
0
sam
4/12/2005 6:02:07 PM
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: $!";
            }
        }
0
Tim
4/13/2005 2:25:40 PM
Reply:

Similar Artilces:

test test test test test test
test test test test test test test test test test test ...

TEST TEST TEST TEST TEST
from forums 11:55 AM PST 02/12/2008 ...

test test test test
what is the deal with these bizarre "test updates"? i did a couple, but they just keep coming. On Feb 20, 7:08=A0pm, inspector.arc...@gmail.com wrote: > what is the deal with these bizarre "test updates"? i did a couple, > but they just keep coming. what? my email is accessible?! what the hell are you thinking? please delete these posts and remove my email address from public access. unbelievable! ...

test test test test
OE is a pain in my ass, test test test -- http://www.spywareinfo.com PGP Public key at http://www.spywareinfo.com/Mike_Healan.txt ...

testing and testing and testing :)
and again :) Carsten Book wrote: > and again :) Testing is fun! Stephen Donner wrote: > Carsten Book wrote: >> and again :) > > Testing is fun! test Stephen Donner wrote: > Stephen Donner wrote: >> Carsten Book wrote: >>> and again :) >> >> Testing is fun! > test testing too :p ...

test test test
test test test test for test "Praveen Hari" <phari@sybase.com> wrote in message news:enLr8dDFDHA.310@forums-1-dub... > test test test > > > ...

test test test
test test MJB Law Office wrote: > test test Is this legal? propman wrote: > MJB Law Office wrote: >> test test > > Is this legal? > Hey, propman, the post is from a law firm, so it must be legal! Right?? Daniel Daniel wrote: > propman wrote: >> MJB Law Office wrote: >>> test test >> >> Is this legal? >> > > Hey, propman, the post is from a law firm, so it must be legal! Right?? Mr. Bumble replies "If the law supposes that� the law is a ass�a idiot. If that�s the eye of the law, the law is...

test test test
test test test ...

test, test, test
test ...

Test Test Test
Name: Gervase Markham Email: gervatmozilladotorg Product: Firefox Summary: Test Test Test Comments: Testing Hendrix. Gerv Browser Details: Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9) Gecko/2008052912 Firefox/3.0 From URL: http://localhost/src/hendrix/ ...

Test TEst TEst Test for Pre-DRE
Test TEst TEst Test for Pre-DRE Test TEst TEst Test for Pre-DRE Test TEst TEst Test for Pre-DRE Test TEst TEst Test for Pre-DRE Test TEst TEst Test for Pre-DRE ...

Extra Tests for Test::Run (and evidently Test::Harness)
Hi all! These are some extra test files that I added to Test::Run, and possibly could be integrated into Test::Harness after some modification: t/output.t: <<<<<<<<<<<<<<<< #!/usr/bin/perl -w BEGIN { if( $ENV{PERL_CORE} ) { chdir 't'; @INC = ('../lib', 'lib'); } else { unshift @INC, 't/lib'; } } use strict; use Test::More tests => 2; use Test::Run::Obj; { open ALTOUT, ">", "altout.txt"; open SAVEOUT, "...

test test test #2
teet teet teet ...

test test test #3
test ...

Web resources about - Tests running Tests - perl.qa

Running - Wikipedia, the free encyclopedia
This article is about the type of locomotion in humans. For running in horses, see Horse gait . For locomotion in dogs, see Gait (dog) . For ...

'Future' AFL chairman Jeff Browne no longer in the running
The man once tipped to be a future AFL Commission chairman is no longer in the running to join the game's governing body.

China's debt-riddled economy running out of options, says RBA
China's teetering debt-plagued economy poses the single biggest threat to Australia's recovery, warns the Reserve Bank of Australia, which remains ...

Under Armour’s Gemini 2 sneakers make running smarter without extra baggage
... it launched a number devices at CES to accompany those integral software pieces. One of those things—the $150 Speedform Gemini 2 smart running ...

Facing Bolt and Tesla, Nissan running out of time to keep EV leadership
Filed under: Green , Nissan , AutoblogGreen Exclusive , Electric January sales slump for the Nissan Leaf electric vehicle continues where last ...

Walking the Walk: DeRay McKesson Is Running for Mayor of Baltimore
... who becomes the first of the prominent post-Ferguson activists to seek public office, said in a phone interview on Wednesday night. “I’m running ...

Donald Trump Is Running as a Conservative Republican
... presumably in a business-like manner. I recite the main points of Trump’s brief remarks to highlight the fact that on the issues he is running ...

Black Lives Matter Activist DeRay Mckesson Running for Mayor of Baltimore
Baltimore activist DeRay Mckesson, who made a name for himself as a Black Lives Matter protester, has thrown his hat in the ring for Mayor of ...

Time running out for lottery winner to claim huge prize
California authorities warn of deadline coming up for what could be largest unclaimed prize in state history

US Renewable Energy Eclipses Fossil Fuels For Second Year Running, Says BNEF
... Council for Sustainable Energy (BCSE). A Permanent Shift? “Two [&hellip US Renewable Energy Eclipses Fossil Fuels For Second Year Running, ...

Resources last updated: 2/7/2016 5:41:00 AM