.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Test2::Tools::Basic 3perl" .TH Test2::Tools::Basic 3perl 2024-09-01 "perl v5.40.0" "Perl Programmers Reference Guide" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Test2::Tools::Basic \- Test2 implementation of the basic testing tools. .SH DESCRIPTION .IX Header "DESCRIPTION" This is a Test2 based implementation of the more basic tools originally provided by Test::More. Not all Test::More tools are provided by this package, only the basic/simple ones. Some tools have been modified for better diagnostics capabilities. .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use Test2::Tools::Basic; \& \& ok($x, "simple test"); \& \& if ($passing) { \& pass(\*(Aqa passing test\*(Aq); \& } \& else { \& fail(\*(Aqa failing test\*(Aq); \& } \& \& diag "This is a diagnostics message on STDERR"; \& note "This is a diagnostics message on STDOUT"; \& \& { \& my $todo = todo "Reason for todo"; \& ok(0, "this test is todo"); \& } \& \& ok(1, "this test is not todo"); \& \& todo "reason" => sub { \& ok(0, "this test is todo"); \& }; \& \& ok(1, "this test is not todo"); \& \& SKIP: { \& skip "This will wipe your drive"; \& \& # This never gets run: \& ok(!system(\*(Aqsudo rm \-rf /\*(Aq), "Wipe drive"); \& } \& \& done_testing; .Ve .SH EXPORTS .IX Header "EXPORTS" All subs are exported by default. .SS PLANNING .IX Subsection "PLANNING" .IP plan($num) 4 .IX Item "plan($num)" .PD 0 .ie n .IP "plan('tests' => $num)" 4 .el .IP "plan('tests' => \f(CW$num\fR)" 4 .IX Item "plan('tests' => $num)" .ie n .IP "plan('skip_all' => $reason)" 4 .el .IP "plan('skip_all' => \f(CW$reason\fR)" 4 .IX Item "plan('skip_all' => $reason)" .PD Set the number of tests that are expected. This must be done first or last, never in the middle of testing. .Sp For legacy compatibility you can specify 'tests' as the first argument before the number. You can also use this to skip all with the 'skip_all' prefix, followed by a reason for skipping. .IP skip_all($reason) 4 .IX Item "skip_all($reason)" Set the plan to 0 with a reason, then exit true. This should be used before any tests are run. .IP done_testing 4 .IX Item "done_testing" Used to mark the end of testing. This is a safe way to have a dynamic or unknown number of tests. .IP bail_out($reason) 4 .IX Item "bail_out($reason)" Invoked when something has gone horribly wrong: stop everything, kill all threads and processes, end the process with a false exit status. .SS ASSERTIONS .IX Subsection "ASSERTIONS" .IP ok($bool) 4 .IX Item "ok($bool)" .PD 0 .ie n .IP "ok($bool, $name)" 4 .el .IP "ok($bool, \f(CW$name\fR)" 4 .IX Item "ok($bool, $name)" .ie n .IP "ok($bool, $name, @diag)" 4 .el .IP "ok($bool, \f(CW$name\fR, \f(CW@diag\fR)" 4 .IX Item "ok($bool, $name, @diag)" .PD Simple assertion. If \f(CW$bool\fR is true the test passes, and if it is false the test fails. The test name is optional, and all arguments after the name are added as diagnostics message if and only if the test fails. If the test passes all the diagnostics arguments will be ignored. .IP \fBpass()\fR 4 .IX Item "pass()" .PD 0 .IP pass($name) 4 .IX Item "pass($name)" .PD Fire off a passing test (a single Ok event). The name is optional .IP \fBfail()\fR 4 .IX Item "fail()" .PD 0 .IP fail($name) 4 .IX Item "fail($name)" .ie n .IP "fail($name, @diag)" 4 .el .IP "fail($name, \f(CW@diag\fR)" 4 .IX Item "fail($name, @diag)" .PD Fire off a failing test (a single Ok event). The name and diagnostics are optional. .SS DIAGNOSTICS .IX Subsection "DIAGNOSTICS" .IP diag(@messages) 4 .IX Item "diag(@messages)" Write diagnostics messages. All items in \f(CW@messages\fR will be joined into a single string with no separator. When using TAP, diagnostics are sent to STDERR. .Sp Returns false, so as to preserve failure. .IP note(@messages) 4 .IX Item "note(@messages)" Write note-diagnostics messages. All items in \f(CW@messages\fR will be joined into a single string with no separator. When using TAP, notes are sent to STDOUT. .SS META .IX Subsection "META" .ie n .IP "$todo = todo($reason)" 4 .el .IP "\f(CW$todo\fR = todo($reason)" 4 .IX Item "$todo = todo($reason)" .PD 0 .ie n .IP "todo $reason => sub { ... }" 4 .el .IP "todo \f(CW$reason\fR => sub { ... }" 4 .IX Item "todo $reason => sub { ... }" .PD This is used to mark some results as TODO. TODO means that the test may fail, but will not cause the overall test suite to fail. .Sp There are two ways to use this. The first is to use a codeblock, and the TODO will only apply to the codeblock. .Sp .Vb 1 \& ok(1, "before"); # Not TODO \& \& todo \*(Aqthis will fail\*(Aq => sub { \& # This is TODO, as is any other test in this block. \& ok(0, "blah"); \& }; \& \& ok(1, "after"); # Not TODO .Ve .Sp The other way is to use a scoped variable. TODO will end when the variable is destroyed or set to undef. .Sp .Vb 1 \& ok(1, "before"); # Not TODO \& \& { \& my $todo = todo \*(Aqthis will fail\*(Aq; \& \& # This is TODO, as is any other test in this block. \& ok(0, "blah"); \& }; \& \& ok(1, "after"); # Not TODO .Ve .Sp This is the same thing, but without the \f(CW\*(C`{...}\*(C'\fR scope. .Sp .Vb 1 \& ok(1, "before"); # Not TODO \& \& my $todo = todo \*(Aqthis will fail\*(Aq; \& \& ok(0, "blah"); # TODO \& \& $todo = undef; \& \& ok(1, "after"); # Not TODO .Ve .IP skip($why) 4 .IX Item "skip($why)" .PD 0 .ie n .IP "skip($why, $count)" 4 .el .IP "skip($why, \f(CW$count\fR)" 4 .IX Item "skip($why, $count)" .PD This is used to skip some tests. This requires you to wrap your tests in a block labeled \f(CW\*(C`SKIP:\*(C'\fR. This is somewhat magical. If no \f(CW$count\fR is specified then it will issue a single result. If you specify \f(CW$count\fR it will issue that many results. .Sp .Vb 2 \& SKIP: { \& skip "This will wipe your drive"; \& \& # This never gets run: \& ok(!system(\*(Aqsudo rm \-rf /\*(Aq), "Wipe drive"); \& } .Ve .SH SOURCE .IX Header "SOURCE" The source code repository for Test2\-Suite can be found at \&\fIhttps://github.com/Test\-More/Test2\-Suite/\fR. .SH MAINTAINERS .IX Header "MAINTAINERS" .IP "Chad Granum " 4 .IX Item "Chad Granum " .SH AUTHORS .IX Header "AUTHORS" .PD 0 .IP "Chad Granum " 4 .IX Item "Chad Granum " .PD .SH COPYRIGHT .IX Header "COPYRIGHT" Copyright 2018 Chad Granum . .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .PP See \fIhttp://dev.perl.org/licenses/\fR