NAME
Badger::Test - test module
SYNOPSIS
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');
DESCRIPTION
This module implements a simple test framework in the style of Test::Simple or Test::More. As well as the usual plan(), ok(), is(), isnt() and other subroutines you would expect to find, it also implements a number of import hooks to enable certain Badger-specific features.
EXPORTED SUBROUTINES
The Badger::Test
module exports the following subroutines, similar to those found in Test::Simple or Test::More.
plan($tests)
Specify how many tests you plan to run. You can also sepcify this using the tests import hook.
plan(1);
ok($flag, $name)
Report on the success or failure of a test:
ok(1, 'This is good');
ok(0, 'This is bad');
is($this, $that, $name)
Test if the first two arguments are equal.
is($this, $that, "This and that are equal");
isnt($this, $that, $name)
Test if the first two arguments are not equal.
isnt($this, $that, "This and that are equal");
like($text, qr/regex/, $name)
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");
unlike($text, qr/regex/, $name)
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");
pass($name)
Pass a test.
pass('Module Loaded');
fail($name)
Fail a test.
fail('Stonehenge in danger of being crushed by a dwarf');
skip($reason)
Skip a single test.
skip("That's just nit-picking isn't it?");
skip_all($reason)
Skip all tests. This should be called instead of plan()
skip_all("We don't have that piece of scenery any more");
skip_some($number,$reason)
Skip a number of tests.
skip_some(11, "Hugeness of object understated");
skip_rest(,$reason)
Skip any remaining tests.
skip_rest("Should have made a big thing out of it");
CLASS METHODS
The Badger::Test
module defines the following class methods to access and/or configure the test framework.
tests()
This class method can be used to set the number of tests. It does the same thing as the plan() subroutine.
Badger::Test->tests(42);
manager()
Method to get or set the name of the backend test manager object class. This is defined in the $MANAGER package variable. The default manager is Badger::Test::Manager.
# defining a custom manager class
Badger::Test->manager('My::Test::Manager');
summary()
Prints a summary of the test results. Delegates to Badger::Test::Manager method of the same name.
colour()
Method to enable or disable colour output.
Badger::Test->colour(1); # technicolor
Badger::Test->colour(0); # monochrome
color()
An alias for colour().
args(@args)
This method parses the arguments looking for -d
to enable debugging, -c
to enable colour output or -s
to print a test summary. This method is called by the args import hook. Arguments can also be passed as a reference to a list, in which case any -c
, -d
or -s
arguments at the start will be removed.
Badger::Test->args(@ARGV); # either
Badger::Test->args(\@ARGV); # or
debug_modules($modules)
This method can be called to define one or more modules that should have their $DEBUG
flag enabled when running in debug mode (i.e. with the -d
command line option). This method is called by the debug import hook.
Badger::Test->debug('My::Badger::Module');
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.
debugging($flag)
This method enables or disables debugging for all modules named in the $DEBUG_MODULES
list. It also sets the internal $DEBUG
flag.
Badger::Test->debugging(1); # enable debugging
Badger::Test->debugging(0); # disable debugging
IMPORT HOOKS
The following import hooks are provided to allow you to load and configure the Badger::Test
module in one fell swoop.
tests
Specify the number of tests. Does the same thing as calling the plan() subroutine or tests() class method.
use Badger::Test
tests => 42;
manager
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';
colour
An import hook to enable colour mode. See the colour() method.
use Badger::Test
colour => 1;
color
An alias for colour
args
This import hook can be used to feed the command line arguments to the args() method so that -d
and -c
enable debugging and colour moes, respectively.
use Badger::Test
args => \@ARGV;
debug
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;
PACKAGE VARIABLES
$MANAGER
This package variable stores the name of the manager class, Badger::Test::Manager by default.
$DEBUG
The $DEBUG
package variable holds the name(s) of module(s) for which debugging should be enabled, as defined via the debug() method.
$DEBUGGING
Flag set true or false to indicate debugging mode is enabled or disabled. As set by the debugging() method.
AUTHOR
Andy Wardley http://wardley.org/
COPYRIGHT
Copyright (C) 1996-2008 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.