Test::...Script(3pm)
π Test::Assertions::TestScript β the vibe β¨
okay bestie, pull up a chair π«Ά this is a page from the User Contributed Perl Documentation manual set, and honestly? it's giving "let me hold your hand while you write tests". iconic behavior, no cap. π
πΈ NAME πΈ
Test::Assertions::TestScript β the base class for test scripts. that's it. that's the whole job. it's the scaffolding, the group chat admin, the friend who sets everything up before you walk in. π
β¨ SYNOPSIS β¨
like, literally just this:
use Test::Assertions::TestScript;
use Module::To::Test qw( frobnicate );
ASSERT(frobnicate(),"Frobnicate returns true");
see how chill that is? you use the thing, you use your module, you ASSERT. periodt. π
π¦ DESCRIPTION π¦
Test::Assertions::TestScript gives you a base for writing test scripts. it handles the boring little chores so you don't have to, and specifically it does these four things:
- the
libandt/libdirectories get added to@INC. π§ - the current directory gets changed to the directory the script lives in. π
- the test script's command-line options get parsed. (peep "COMMAND-LINE OPTIONS" below, bestie)
- the test set of functions from
Test::Assertionsget imported into your test script. π
and it's making some assumptions about your project's filesystem layout, so let's be honest about those:
- the modules you're testing live in the
libdirectory of your project. π - test scripts live in the
tdirectory. π - there may also be a
t/libdirectory, for any modules written for the test process itself. ποΈ
important vibe check:Test::Assertions::TestScriptshould beused before any modules you intend to test. order matters, don't be chaotic about it. π
π OPTIONS π
options can be handed to the import function. they go after the use or import. like so:
use Test::Assertions::TestScript( tests => 10, options => { 'b', \$opt_b })
here's what's defined:
testsβ the number of tests to pass along toplan testsfromTest::Assertions. so if you wanna tellTest::Assertions::TestScriptthat your script contains 42 tests, you say:
use Test::Assertions::TestScript tests => 42;
optionsβ a hashref of extra options to capture viaGetopt::Long. theoptionsimport parameter is passed verbatim toGetOptions, so to capture the-bcommand line option you need something along these lines:
use Test::Assertions::TestScript( options => { 'b' => \$opt_b } );
π COMMAND-LINE OPTIONS π
a script based on Test::Assertions::TestScript will detect these command line options, bestie:
-tβ shallow tracing. traces getprinted and AutoImport is turned on. π-Tβ deep tracing. traces getprinted and AutoImport is turned on. π--trace-module=MODULEβ imports tracing into MODULE specifically. can be specified multiple times. π§΅-sβ save generated output. you'll need to write the actual code to do this yourself in your testscript, but you can peek at$Test::Assertions::TestScript::SAVE_OUTPUTto see whether this argument was given. πΎ
heads up fr fr: be aware that all other command line options will be disregarded unless the options import parameter is used to capture them. so like, if you're wondering why your flag is being ignored... that's why. π
β VERSION β
$Revision: 1.18 $
π AUTHOR π
Colin Robertson <cpan _at_ bbc _dot_ co _dot_ uk>
π COPYRIGHT π
(c) BBC 2005-6. This program is free software; you can redistribute it and/or modify it under the GNU GPL.
See the file COPYING in this distribution, or http://www.gnu.org/licenses/gpl.txt
and that's the whole page, bestie!! π₯³ this lil manual moment was brought to you by perl v5.36.0, dated 2022-11-19, from the Test::...Script(3pm) page. slay, go write some tests πβ¨
π¦ where this page comes from
- debian bookworm: libtest-assertions-perl 1.054-5 Β· GPL-2.0-or-later
- debian trixie: libtest-assertions-perl 1.054-5 Β· GPL-2.0-or-later
- ubuntu noble: libtest-assertions-perl 1.054-5 Β· GPL-2.0-or-later
- ubuntu resolute: libtest-assertions-perl 1.054-5 Β· GPL-2.0-or-later
- ubuntu stonking: libtest-assertions-perl 1.054-5 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms