Test::...Script(3pm)

πŸ“¦
version 1.054 Β· 6 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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 lib and t/lib directories 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::Assertions get 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 lib directory of your project. πŸ“
  • test scripts live in the t directory. πŸ“‚
  • there may also be a t/lib directory, for any modules written for the test process itself. πŸ—‚οΈ
important vibe check: Test::Assertions::TestScript should be used 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 to plan tests from Test::Assertions. so if you wanna tell Test::Assertions::TestScript that your script contains 42 tests, you say:
use Test::Assertions::TestScript tests => 42;
  • options β€” a hashref of extra options to capture via Getopt::Long. the options import parameter is passed verbatim to GetOptions, so to capture the -b command 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 get printed and AutoImport is turned on. πŸ”
  • -T β€” deep tracing. traces get printed 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_OUTPUT to 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>


(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 πŸ’–βœ¨