- EXPORTED SUBROUTINES
- ok($flag, $name)
- is($this, $that, $name)
- isnt($this, $that, $name)
- like($text, qr/regex/, $name)
- unlike($text, qr/regex/, $name)
- CLASS METHODS
- IMPORT HOOKS
- PACKAGE VARIABLES
- SEE ALSO
use Badger::Test tests => 8, debug => 'My::Badger::Module Your::Badger::Module', args => \@ARGV; # -d in @ARGV will enable $DEBUG for My::Badger::Module # and Your::Badger::Module, as well as exporting a $DEBUG # flag here. -c will enable colour mode. # e.g. $ perl t/test.t -d -c ok( $bool, 'Test passes if $bool true' ); is( $one, $two, 'Test passes if $one eq $two' ); isnt( $one, $two, 'Test passes if $one ne $two' ); like( $one, qr/regex/, 'Test passes if $one =~ /regex/' ); unlike( $one, qr/regex/, 'Test passes if $one !~ /regex/' ); pass('This test always passes'); fail('This test always fails');
Specify how many tests you plan to run. You can also specify this using the tests import hook.
Report on the success or failure of a test:
ok(1, 'This is good'); ok(0, 'This is bad');
Test if the first two arguments are equal.
is($this, $that, "This and that are equal");
Test if the first two arguments are not equal.
isnt($this, $that, "This and that are equal");
Test if the first argument is matched by the regex passed as the second argument.
like($this, qr/like that/i, "This and that are alike");
Test if the first argument is not matched by the regex passed as the second argument.
unlike($this, qr/like that/i, "This and that are unalike");
Skip all tests. This should be called instead of plan()
skip_all("We don't have that piece of scenery any more");
Skip a number of tests.
skip_some(11, "Hugeness of object understated");
Badger::Test module defines the following class methods
to access and/or configure the test framework.
This class method can be used to set the number of tests. It does the same thing as the plan() subroutine.
This method can be used to set various testing options from command line arguments. It is typically called via the args import option.
use Badger::Test debug => 'My::Module', args => \@ARGV, tests => 42;
The method parses the arguments looking for the following options:
-d --debug Enable debugging -t --trace Enable stack tracing -c --colour/--color Enable colour output -s --summary Display summary of test results -h --help This help summary
Arguments can be passed as a list or reference to a list.
Badger::Test->args(@ARGV); # either Badger::Test->args(\@ARGV); # or
Any of the arguments listed above appearing at the start of the list will be removed from the list and acted upon. Processing will end as soon as an unrecognised argument is encountered.
Prints a summary of the test results. Delegates to Badger::Test::Manager method of the same name.
Method to enable or disable colour output.
Badger::Test->colour(1); # technicolor Badger::Test->colour(0); # monochrome
This method can be called to define one or more modules that should have
$DEBUG flag enabled when running in debug mode (i.e.
-d command line option). This method is called by
the debug import hook.
Multiple modules can be specified in a single string or by reference to a list.
# whitespace-delimited string Badger::Test->debug('My::Badger::Module Your::Badger::Module'); # list reference Badger::Test->debug(['My::Badger::Module', 'Your::Badger::Module']);
This method simply stores the list of modules in the
$DEBUG_MODULES package variable for the debugging() method to use.
This method enables or disables debugging for all modules named in the
$DEBUG_MODULES list. It also sets the internal
Badger::Test->debugging(1); # enable debugging Badger::Test->debugging(0); # disable debugging
This method enables or disables stack tracing in the Badger::Exception module.
The following import hooks are provided to allow you to load and
Badger::Test module in one fell swoop.
An import hook to define a different test manager module. See the manager() method.
use My::Test::Manager; use Badger::Test manager => 'My::Test::Manager';
An import hook to enable colour mode. See the colour() method.
use Badger::Test colour => 1;
This import hook can be used to feed the command line arguments to the args() method so that
-c enable debugging and colour moes, respectively.
use Badger::Test args => \@ARGV;
An import hook to associate a list of module with our debugging mode. See the debug() method.
use Badger::Test debug => 'My::Badger::Module Your Badger::Module', args => \@ARGV;
This import hook can be used to automatically skip all the tests in a script unless a specific environment variable (or any from a list of variables) is defined. This is typically used to prevent certain test scripts from being run by end users (e.g. Pod coverage/kwalitee test scripts).
use Badger::Test tests => 5, args => \@ARGV, if_env => 'RELEASE_TESTING AUTOMATED_TESTING';
In this example the tests will only be run if either of the
environment variables is set. However, specifying the
--all command line option will force all tests to be run
$ perl t/pod_coverage.t --all
This package variable stores the name of the manager class, Badger::Test::Manager by default.
$DEBUG package variable holds the name(s) of module(s)
for which debugging should be enabled, as defined via the debug() method.
Copyright (C) 1996-2009 Andy Wardley. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.