Badger::Test(3pm)
π Badger::Test β the test module, but make it cute π
perl v5.36.0 Β· 2023-08-28 β okay bestie, this is the Badger::Test page from the User Contributed Perl Documentation, and we're about to make test suites feel like a group chat that actually ships. π¦
β¨ NAME β¨
Badger::Test β it's a test module, bestie. That's the whole vibe. π
β¨ SYNOPSIS β¨
okay so here's the whole energy in one block:
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');
like?? it's giving Test::More but with a Badger glow-up. π
β¨ DESCRIPTION β¨
This module implements a simple test framework in the style of Test::Simple or Test::More. no cap β all the subroutines you'd expect are here: plan(), ok(), is(), isnt() and the rest of the squad. But it <em>also</em> implements a bunch of import hooks so you get the Badger-specific features too. it's giving main character energy for your t/ directory. π
β¨ EXPORTED SUBROUTINES β¨
The Badger::Test module exports the following subroutines, similar to those found in Test::Simple or Test::More. π«Ά
πΈ plan($tests)
Tell the world how many tests you plan to run. You can also do this with the tests import hook instead, iykyk.
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 <em>not</em> equal. (yes the example string below still says "are equal", that's the original's little joke, we keep it exactly, no notes π)
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 <em>not</em> 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. iconic. π
pass('Module Loaded');
πΈ fail($name)
Fail a test. it happens to the best of us. π
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 <em>all</em> the tests. You should call this <strong>instead of</strong> plan(), okay?
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');
π¦ args(@args)
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. either is fine, bestie. π«Ά
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. so don't get cute and shuffle your flags around β it stops looking the moment it sees something it doesn't know. π
π¦ summary()
Prints a summary of the test results. Delegates to the 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().
π¦ 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
π¦ trace($flag)
This method enables or disables stack tracing in the Badger::Exception module.
π¦ all($flag)
This method enables or disables the internal $ALL flag. It is called by the args() method when the -a or -all command line argument is specified. When the flag is set, it forces all tests to be run regardless of any if_env conditions. overriding the vibes, respectfully. π₯
π¦ help()
This method returns the help text displayed when help is requested with the -h or --help command line options. See args() for further details. π
β¨ IMPORT HOOKS β¨
The following import hooks are provided to allow you to load and configure the Badger::Test module in one fell swoop. one line, all the settings, obsessed. β¨
π 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. (yes, "moes" β we're keeping the typo exactly as it is, it's canon now π)
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;
π if_env
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 RELEASE_TESTING or AUTOMATED_TESTING environment variables is set. However, specifying the -a or --all command line option will force all tests to be run regardless. πͺ
$ perl t/pod_coverage.t --all
β¨ 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/> β legend behaviour, honestly. π
β¨ COPYRIGHT β¨
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. π«Ά
β¨ SEE ALSO β¨
Badger::Test::Manager, Test::Simple, Test::More. go read those next bestie, iykyk πβ¨
perl v5.36.0 Β· 2023-08-28 Β· Badger::Test(3pm) β okay that's the whole page, you ate that. now go write some tests and make them pass. bye bestie! πππ¦
π¦ where this page comes from
- debian trixie: libbadger-perl 0.16-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libbadger-perl 0.16-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libbadger-perl 0.16-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms