PrePAN

Sign in to PrePAN

Test::Self Provide a mechanism to run tests on individual perl scripts outside the context of a module-starter like framework

Author
torbjorn@github
Date
URL
Status
In Review
Good

Synopsis

## on command line
perl -MTest::Self perlscript.pl

## or if imported in the script, maybe:
./perlscript.pl --self-test

## and then in perlscript.pl:

#!/usr/bin/perl

use strict;
use warnings;

use Test::Self(); # skip import to make sure perl -MTest::Self also works

# .. rest of script

# .. and maybe embed tests like this:

sub __testself__check_that_something_works {

  is( 1, 1, "the universe works" );

}

sub __testself__check_something_else {

  pass( "debug" );

}

## and then perhaps have the module use Test::Build to run these subs as subtest's

Description

Synopsis says most. Run tests from within a script as easy as possible.

Comments

This looks similar to Test::Class, although I like the the way that module uses attributes better. Maybe this could use Test::Class to run the tests.

It seems like the novel part is how to choose which code is run during testing, without testing, or both.

It may be better if the default import doesn't run tests, and then you could run them like

perl -MTest::Self=run script.pl

Also, have a look at Test;:Inline, which is also similar.

Please sign up to post a review.