.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" 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 .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . 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 "Test::Modern 3pm" .TH Test::Modern 3pm "2020-12-29" "perl v5.32.0" "User Contributed Perl Documentation" .\" 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" Test::Modern \- precision testing for modern perl .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Test::Modern; \& \& # Your tests here \& \& done_testing; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Test::Modern provides the best features of Test::More, Test::Fatal, Test::Warnings, Test::API, Test::LongString, and Test::Deep, as well as ideas from Test::Requires, Test::DescribeMe, Test::Moose, and Test::CleanNamespaces. .PP Test::Modern also automatically imposes strict and warnings on your script, and loads IO::File. (Much of the same stuff Modern::Perl does.) .PP Although Test::Modern is a modern testing framework, it should run fine on pre-modern versions of Perl. It should be easy to install on Perl 5.8.9 and above; and if you can persuade its dependencies to install (not necessarily easy!), should be \s-1OK\s0 on anything back to Perl 5.6.1. .SS "Features from Test::More" .IX Subsection "Features from Test::More" Test::Modern exports the following subs from Test::More: .ie n .IP """ok($truth, $description)""" 4 .el .IP "\f(CWok($truth, $description)\fR" 4 .IX Item "ok($truth, $description)" .PD 0 .ie n .IP """is($got, $expected, $description)""" 4 .el .IP "\f(CWis($got, $expected, $description)\fR" 4 .IX Item "is($got, $expected, $description)" .ie n .IP """isnt($got, $unexpected, $description)""" 4 .el .IP "\f(CWisnt($got, $unexpected, $description)\fR" 4 .IX Item "isnt($got, $unexpected, $description)" .ie n .IP """like($got, $regexp, $description)""" 4 .el .IP "\f(CWlike($got, $regexp, $description)\fR" 4 .IX Item "like($got, $regexp, $description)" .ie n .IP """unlike($got, $regexp, $description)""" 4 .el .IP "\f(CWunlike($got, $regexp, $description)\fR" 4 .IX Item "unlike($got, $regexp, $description)" .ie n .IP """is_deeply($got, $expected, $description)""" 4 .el .IP "\f(CWis_deeply($got, $expected, $description)\fR" 4 .IX Item "is_deeply($got, $expected, $description)" .ie n .IP """cmp_ok($got, $operator, $expected, $description)""" 4 .el .IP "\f(CWcmp_ok($got, $operator, $expected, $description)\fR" 4 .IX Item "cmp_ok($got, $operator, $expected, $description)" .ie n .IP """new_ok($class, \e@args, $name)""" 4 .el .IP "\f(CWnew_ok($class, \e@args, $name)\fR" 4 .IX Item "new_ok($class, @args, $name)" .ie n .IP """isa_ok($object|$subclass, $class, $name)""" 4 .el .IP "\f(CWisa_ok($object|$subclass, $class, $name)\fR" 4 .IX Item "isa_ok($object|$subclass, $class, $name)" .ie n .IP """can_ok($object|$class, @methods)""" 4 .el .IP "\f(CWcan_ok($object|$class, @methods)\fR" 4 .IX Item "can_ok($object|$class, @methods)" .ie n .IP """pass($description)""" 4 .el .IP "\f(CWpass($description)\fR" 4 .IX Item "pass($description)" .ie n .IP """fail($description)""" 4 .el .IP "\f(CWfail($description)\fR" 4 .IX Item "fail($description)" .ie n .IP """subtest($description, sub { ... })""" 4 .el .IP "\f(CWsubtest($description, sub { ... })\fR" 4 .IX Item "subtest($description, sub { ... })" .ie n .IP """diag(@messages)""" 4 .el .IP "\f(CWdiag(@messages)\fR" 4 .IX Item "diag(@messages)" .ie n .IP """note(@messages)""" 4 .el .IP "\f(CWnote(@messages)\fR" 4 .IX Item "note(@messages)" .ie n .IP """explain(@messages)""" 4 .el .IP "\f(CWexplain(@messages)\fR" 4 .IX Item "explain(@messages)" .ie n .IP """skip($why, $count) if $reason""" 4 .el .IP "\f(CWskip($why, $count) if $reason\fR" 4 .IX Item "skip($why, $count) if $reason" .ie n .IP """todo_skip($why, $count) if $reason""" 4 .el .IP "\f(CWtodo_skip($why, $count) if $reason\fR" 4 .IX Item "todo_skip($why, $count) if $reason" .ie n .IP "$TODO" 4 .el .IP "\f(CW$TODO\fR" 4 .IX Item "$TODO" .ie n .IP """plan(%plan)""" 4 .el .IP "\f(CWplan(%plan)\fR" 4 .IX Item "plan(%plan)" .ie n .IP """done_testing""" 4 .el .IP "\f(CWdone_testing\fR" 4 .IX Item "done_testing" .ie n .IP """BAIL_OUT($reason)""" 4 .el .IP "\f(CWBAIL_OUT($reason)\fR" 4 .IX Item "BAIL_OUT($reason)" .PD .PP The \f(CW\*(C`use_ok\*(C'\fR, \f(CW\*(C`require_ok\*(C'\fR, \f(CW\*(C`eq_array\*(C'\fR, \f(CW\*(C`eq_hash\*(C'\fR, and \f(CW\*(C`eq_set\*(C'\fR functions are also available, but not exported by default. For \f(CW\*(C`use_ok\*(C'\fR and \&\f(CW\*(C`require_ok\*(C'\fR it's normally better to use the Perl built-ins \f(CW\*(C`use\*(C'\fR and \&\f(CW\*(C`require\*(C'\fR which will die (failing your test) if things are not \s-1OK.\s0 For the \f(CW\*(C`eq_*\*(C'\fR functions, they can usually be replaced by \f(CW\*(C`is_deeply\*(C'\fR. .SS "Features from Test::Fatal" .IX Subsection "Features from Test::Fatal" Test::Modern exports the following subs from Test::Fatal: .ie n .IP """exception { BLOCK }""" 4 .el .IP "\f(CWexception { BLOCK }\fR" 4 .IX Item "exception { BLOCK }" .SS "Features from Test::Warnings" .IX Subsection "Features from Test::Warnings" Test::Modern exports the following subs from Test::Warnings: .ie n .IP """warning { BLOCK }""" 4 .el .IP "\f(CWwarning { BLOCK }\fR" 4 .IX Item "warning { BLOCK }" .PD 0 .ie n .IP """warnings { BLOCK }""" 4 .el .IP "\f(CWwarnings { BLOCK }\fR" 4 .IX Item "warnings { BLOCK }" .PD .PP In addition, Test::Modern always enables the \f(CW\*(C`had_no_warnings\*(C'\fR test at the end of the file, ensuring that your test script generated no warnings other than the expected ones which were caught by \f(CW\*(C`warnings\*(C'\fR blocks. (See also \f(CW\*(C`PERL_TEST_MODERN_ALLOW_WARNINGS\*(C'\fR in \*(L"\s-1ENVIRONMENT\*(R"\s0.) .PP Test::Modern can also export an additional function for testing warnings, but does not export it by default: .ie n .IP """shouldnt_warn { BLOCK }""" 4 .el .IP "\f(CWshouldnt_warn { BLOCK }\fR" 4 .IX Item "shouldnt_warn { BLOCK }" Runs a block of code that will hopefully not warn, but might. Tests that it doesn't warn, but performs that test as a \*(L"todo\*(R" test, so if it fails, your test suite can still pass. .SS "Features from Test::API" .IX Subsection "Features from Test::API" Test::Modern exports the following subs from Test::API: .ie n .IP """public_ok($package, @functions)""" 4 .el .IP "\f(CWpublic_ok($package, @functions)\fR" 4 .IX Item "public_ok($package, @functions)" .PD 0 .ie n .IP """import_ok($package, export => \e@functions, export_ok => \e@functions)""" 4 .el .IP "\f(CWimport_ok($package, export => \e@functions, export_ok => \e@functions)\fR" 4 .IX Item "import_ok($package, export => @functions, export_ok => @functions)" .ie n .IP """class_api_ok($class, @methods)""" 4 .el .IP "\f(CWclass_api_ok($class, @methods)\fR" 4 .IX Item "class_api_ok($class, @methods)" .PD .SS "Features from Test::LongString" .IX Subsection "Features from Test::LongString" Test::Modern exports the following subs from Test::LongString: .ie n .IP """is_string($got, $expected, $description)""" 4 .el .IP "\f(CWis_string($got, $expected, $description)\fR" 4 .IX Item "is_string($got, $expected, $description)" .PD 0 .ie n .IP """is_string_nows($got, $expected, $description)""" 4 .el .IP "\f(CWis_string_nows($got, $expected, $description)\fR" 4 .IX Item "is_string_nows($got, $expected, $description)" .ie n .IP """like_string($got, $regexp, $description)""" 4 .el .IP "\f(CWlike_string($got, $regexp, $description)\fR" 4 .IX Item "like_string($got, $regexp, $description)" .ie n .IP """unlike_string($got, $regexp, $description)""" 4 .el .IP "\f(CWunlike_string($got, $regexp, $description)\fR" 4 .IX Item "unlike_string($got, $regexp, $description)" .ie n .IP """contains_string($haystack, $needle, $description)""" 4 .el .IP "\f(CWcontains_string($haystack, $needle, $description)\fR" 4 .IX Item "contains_string($haystack, $needle, $description)" .ie n .IP """lacks_string($haystack, $needle, $description)""" 4 .el .IP "\f(CWlacks_string($haystack, $needle, $description)\fR" 4 .IX Item "lacks_string($haystack, $needle, $description)" .PD .PP Actually Test::Modern provides these via a wrapper. If Test::LongString is not installed then Test::Modern will provide a fallback implementation using Test::More's \f(CW\*(C`is\*(C'\fR, \f(CW\*(C`isnt\*(C'\fR, \f(CW\*(C`like\*(C'\fR, and \&\f(CW\*(C`unlike\*(C'\fR functions. (The diagnostics won't be as good in the case of failures.) .SS "Features from Test::Deep" .IX Subsection "Features from Test::Deep" Test::Modern exports the following subs from Test::Deep: .ie n .IP """cmp_deeply($got, $expected, $description)""" 4 .el .IP "\f(CWcmp_deeply($got, $expected, $description)\fR" 4 .IX Item "cmp_deeply($got, $expected, $description)" .PP The following are not exported by default, but can be exported upon request: .ie n .IP """ignore()""" 4 .el .IP "\f(CWignore()\fR" 4 .IX Item "ignore()" .PD 0 .ie n .IP """methods(%hash)""" 4 .el .IP "\f(CWmethods(%hash)\fR" 4 .IX Item "methods(%hash)" .ie n .IP """listmethods(%hash)""" 4 .el .IP "\f(CWlistmethods(%hash)\fR" 4 .IX Item "listmethods(%hash)" .ie n .IP """shallow($thing)""" 4 .el .IP "\f(CWshallow($thing)\fR" 4 .IX Item "shallow($thing)" .ie n .IP """noclass($thing)""" 4 .el .IP "\f(CWnoclass($thing)\fR" 4 .IX Item "noclass($thing)" .ie n .IP """useclass($thing)""" 4 .el .IP "\f(CWuseclass($thing)\fR" 4 .IX Item "useclass($thing)" .ie n .IP """re($regexp, $capture_data, $flags)""" 4 .el .IP "\f(CWre($regexp, $capture_data, $flags)\fR" 4 .IX Item "re($regexp, $capture_data, $flags)" .ie n .IP """superhashof(\e%hash)""" 4 .el .IP "\f(CWsuperhashof(\e%hash)\fR" 4 .IX Item "superhashof(%hash)" .ie n .IP """subhashof(\e%hash)""" 4 .el .IP "\f(CWsubhashof(\e%hash)\fR" 4 .IX Item "subhashof(%hash)" .ie n .IP """bag(@elements)""" 4 .el .IP "\f(CWbag(@elements)\fR" 4 .IX Item "bag(@elements)" .ie n .IP """set(@elements)""" 4 .el .IP "\f(CWset(@elements)\fR" 4 .IX Item "set(@elements)" .ie n .IP """superbagof(@elements)""" 4 .el .IP "\f(CWsuperbagof(@elements)\fR" 4 .IX Item "superbagof(@elements)" .ie n .IP """subbagof(@elements)""" 4 .el .IP "\f(CWsubbagof(@elements)\fR" 4 .IX Item "subbagof(@elements)" .ie n .IP """supersetof(@elements)""" 4 .el .IP "\f(CWsupersetof(@elements)\fR" 4 .IX Item "supersetof(@elements)" .ie n .IP """subsetof(@elements)""" 4 .el .IP "\f(CWsubsetof(@elements)\fR" 4 .IX Item "subsetof(@elements)" .ie n .IP """all(@expecteds)""" 4 .el .IP "\f(CWall(@expecteds)\fR" 4 .IX Item "all(@expecteds)" .ie n .IP """any(@expecteds)""" 4 .el .IP "\f(CWany(@expecteds)\fR" 4 .IX Item "any(@expecteds)" .ie n .IP """obj_isa($class)""" 4 .el .IP "\f(CWobj_isa($class)\fR" 4 .IX Item "obj_isa($class)" .ie n .IP """array_each($thing)""" 4 .el .IP "\f(CWarray_each($thing)\fR" 4 .IX Item "array_each($thing)" .ie n .IP """str($string)""" 4 .el .IP "\f(CWstr($string)\fR" 4 .IX Item "str($string)" .ie n .IP """num($number, $tolerance)""" 4 .el .IP "\f(CWnum($number, $tolerance)\fR" 4 .IX Item "num($number, $tolerance)" .ie n .IP """bool($value)""" 4 .el .IP "\f(CWbool($value)\fR" 4 .IX Item "bool($value)" .ie n .IP """code(\e&subref)""" 4 .el .IP "\f(CWcode(\e&subref)\fR" 4 .IX Item "code(&subref)" .PD .PP As an alternative to using those functions, Test::Modern exports a constant \&\f(CW\*(C`TD\*(C'\fR upon which you can call them as methods: .PP .Vb 2 \& # like Test::Deep::bag(@elements) \& TD\->bag(@elements) .Ve .SS "Features from Test::Pod and Test::Pod::Coverage" .IX Subsection "Features from Test::Pod and Test::Pod::Coverage" \&\fBThese features are currently considered experimental. They may be removed from a future version of Test::Modern.\fR .PP Test::Modern can export the following subs from Test::Pod and Test::Pod::Coverage, though they are not exported by default: .ie n .IP """pod_file_ok($file, $description)""" 4 .el .IP "\f(CWpod_file_ok($file, $description)\fR" 4 .IX Item "pod_file_ok($file, $description)" .PD 0 .ie n .IP """all_pod_files_ok(@dirs)""" 4 .el .IP "\f(CWall_pod_files_ok(@dirs)\fR" 4 .IX Item "all_pod_files_ok(@dirs)" .ie n .IP """pod_coverage_ok($module, $params, $description)""" 4 .el .IP "\f(CWpod_coverage_ok($module, $params, $description)\fR" 4 .IX Item "pod_coverage_ok($module, $params, $description)" .ie n .IP """all_pod_coverage_ok($params, $description)""" 4 .el .IP "\f(CWall_pod_coverage_ok($params, $description)\fR" 4 .IX Item "all_pod_coverage_ok($params, $description)" .PD .PP In fact, Test::Modern wraps these tests in checks to see whether Test::Pod(::Coverage) is installed, and the state of the \&\f(CW\*(C`RELEASE_TESTING\*(C'\fR, \f(CW\*(C`AUTHOR_TESTING\*(C'\fR, and \f(CW\*(C`EXTENDED_TESTING\*(C'\fR environment variables. If none of those environment variables is set to true, then the test is skipped altogether. If Test::Pod(::Coverage) is not installed, then the test is skipped, unless \f(CW\*(C`RELEASE_TESTING\*(C'\fR is true, in which case \fITest::Pod(::Coverage) must be installed\fR. .PP This is usually a pretty sensible behaviour. You want authors to be made aware of pod errors if possible. You want to make sure they are tested before doing a release. End users probably don't want a pod formatting error to prevent them from installing the software, unless they opt into it using \f(CW\*(C`EXTENDED_TESTING\*(C'\fR. .PP Also, Test::Modern wraps the \f(CW\*(C`all_*\*(C'\fR functions to run them in a subtest (because otherwise they can interfere with your test plans). .SS "Features from Test::Version" .IX Subsection "Features from Test::Version" \&\fBThese features are currently considered experimental. They may be removed from a future version of Test::Modern.\fR .PP Test::Modern can export the following subs from Test::Version, though they are not exported by default: .ie n .IP """version_ok($file, $description)""" 4 .el .IP "\f(CWversion_ok($file, $description)\fR" 4 .IX Item "version_ok($file, $description)" .PD 0 .ie n .IP """version_all_ok(@dirs)""" 4 .el .IP "\f(CWversion_all_ok(@dirs)\fR" 4 .IX Item "version_all_ok(@dirs)" .PD .PP These are wrapped similarly to those described in the \&\*(L"Features from Test::Pod and Test::Coverage\*(R". .PP Test::Modern can also export another sub based on \f(CW\*(C`version_all_ok\*(C'\fR: .ie n .IP """version_all_same(@dirs)""" 4 .el .IP "\f(CWversion_all_same(@dirs)\fR" 4 .IX Item "version_all_same(@dirs)" Acts like \f(CW\*(C`version_all_ok\*(C'\fR but also checks that all modules have the same version number. .SS "Features inspired by Test::Moose" .IX Subsection "Features inspired by Test::Moose" Test::Modern does not use Test::Moose, but does provide the following function inspired by it: .ie n .IP """does_ok($object|$subclass, $class, $name)""" 4 .el .IP "\f(CWdoes_ok($object|$subclass, $class, $name)\fR" 4 .IX Item "does_ok($object|$subclass, $class, $name)" Like \f(CW\*(C`isa_ok\*(C'\fR, but calls \f(CW\*(C`$obj\->DOES\*(C'\fR instead of \f(CW\*(C`$obj\->isa\*(C'\fR. .SS "Features inspired by Test::CleanNamespaces" .IX Subsection "Features inspired by Test::CleanNamespaces" Test::Modern does not use Test::CleanNamespaces, but does provide the following function inspired by it: .ie n .IP """namespaces_clean(@namespaces)""" 4 .el .IP "\f(CWnamespaces_clean(@namespaces)\fR" 4 .IX Item "namespaces_clean(@namespaces)" Tests that namespaces don't contain any imported functions. (i.e. you haven't forgotten to use namespace::autoclean or namespace::sweep in a class). .Sp Unlike the version of this function supplied with Test::CleanNamespaces, if \f(CW@namespaces\fR contains more than one namespace, these will be run in a subtest, so the whole thing will only count as one test. .SS "Features inspired by Test::Benchmark" .IX Subsection "Features inspired by Test::Benchmark" Test::Modern does not use Test::Benchmark, but does provide the following feature inspired by it: .ie n .IP """is_fastest($implementation, $times, \e%implementations, $desc)""" 4 .el .IP "\f(CWis_fastest($implementation, $times, \e%implementations, $desc)\fR" 4 .IX Item "is_fastest($implementation, $times, %implementations, $desc)" .Vb 1 \& use Test::Modern qw( is_fastest ); \& \& is_fastest("speedy", \-1, { \& "speedy" => sub { ... }, \& "slowcoach" => sub { ... }, \& }); .Ve .Sp This ensures that the named coderef runs the fastest out of a hashref of alternatives. The \f(CW\*(C`\-1\*(C'\fR parameter in the example is the number of times to run the coderefs (see Benchmark for more details, including how numbers less than zero are interpreted). .PP \&\fBCaveat:\fR on fast computers, a set of coderefs that you might expect to differ in speed might all run in a negligible period of time, and thus be rounded to zero, in which case your test case could randomly fail. Use this test with caution! .PP \&\fBCaveat the second:\fR these tests tend to be slow. Use sparingly. .PP Because of the aforementioned caveats, it is a good idea to move your benchmarking tests into separate test scripts, keeping an imaginary wall between them and the bulk of your test suite (which tests correctness rather than speed). .PP Test::Modern provides an import hint suitable for including at the top of these benchmarking tests to mark them as being primarily concerned with speed: .PP .Vb 1 \& use Test::Modern \-benchmark; .Ve .PP This will not only import the \f(CW\*(C`is_fastest\*(C'\fR function, but will also \&\fIskip the entire script\fR unless one of the \f(CW\*(C`EXTENDED_TESTING\*(C'\fR or \&\f(CW\*(C`RELEASE_TESTING\*(C'\fR environment variables is set. .SS "Features inspired by Test::Requires" .IX Subsection "Features inspired by Test::Requires" Test::Modern does not use Test::Requires, but does provide the following feature inspired by it: .ie n .IP """use Test::Modern \-requires => \e%requirements""" 4 .el .IP "\f(CWuse Test::Modern \-requires => \e%requirements\fR" 4 .IX Item "use Test::Modern -requires => %requirements" This will skip the entire test script if the requirements are not met. For example: .Sp .Vb 5 \& use Test::Modern \-requires => { \& \*(Aqperl\*(Aq => \*(Aq5.010\*(Aq, \& \*(AqMoose\*(Aq => \*(Aq2.11\*(Aq, \& \*(Aqnamespace::autoclean\*(Aq => undef, \& }; .Ve .SS "Features inspired by Test::RequiresInternet" .IX Subsection "Features inspired by Test::RequiresInternet" Similarly you can skip the test script if an Internet connection is not available: .PP .Vb 1 \& use Test::Modern \-internet; .Ve .PP You can check for the ability to connect to particular hosts and ports: .PP .Vb 4 \& use Test::Modern \-internet => [ \& \*(Aqwww.example.com\*(Aq => \*(Aqhttp\*(Aq, \& \*(Aq8.8.8.8\*(Aq => 53, \& ]; .Ve .PP Test::Modern does not use Test::RequiresInternet but I've stolen much of the latter's implementation. .SS "Features inspired by Test::Without::Module" .IX Subsection "Features inspired by Test::Without::Module" Test::Modern does not use Test::Without::Module, but does provide the following feature inspired by it: .ie n .IP """use Test::Modern \-without => \e@modules""" 4 .el .IP "\f(CWuse Test::Modern \-without => \e@modules\fR" 4 .IX Item "use Test::Modern -without => @modules" This will run the tests as if the module was not installed. Useful for testing things in the absence of optional dependencies. For example: .Sp .Vb 1 \& use Test::Modern \-without => [ "Class::XSAccessor" ]; .Ve .Sp It cannot suppress modules from being loaded if they are required by Test::Modern itself. To get a list of what modules Test::Modern requires, run the following command: .Sp .Vb 1 \& perl \-MTest::Modern \-le\*(Aqprint for sort keys %INC\*(Aq .Ve .Sp (Note that the actual implementation is mostly stolen from Devel::Hide which seems to behave better than Test::Without::Module.) .SS "Features inspired by Test::DescribeMe" .IX Subsection "Features inspired by Test::DescribeMe" These export tags allow you to classify tests as \*(L"author tests\*(R", \&\*(L"release tests\*(R", \*(L"extended tests\*(R", or \*(L"interactive tests\*(R". .PP They will cause your test script to be skipped depending on various environment variables. .ie n .IP """use Test::Modern \-author""" 4 .el .IP "\f(CWuse Test::Modern \-author\fR" 4 .IX Item "use Test::Modern -author" .PD 0 .ie n .IP """use Test::Modern \-release""" 4 .el .IP "\f(CWuse Test::Modern \-release\fR" 4 .IX Item "use Test::Modern -release" .ie n .IP """use Test::Modern \-extended""" 4 .el .IP "\f(CWuse Test::Modern \-extended\fR" 4 .IX Item "use Test::Modern -extended" .ie n .IP """use Test::Modern \-interactive""" 4 .el .IP "\f(CWuse Test::Modern \-interactive\fR" 4 .IX Item "use Test::Modern -interactive" .PD .SS "Features inspired by Test::Lib" .IX Subsection "Features inspired by Test::Lib" \&\fBThese features are currently considered experimental. They may be removed from a future version of Test::Modern.\fR .PP Test::Modern tries to find a directory called \f(CW\*(C`t/lib\*(C'\fR by traversing up the directory tree from the caller file. If found, this directory will be added to \f(CW@INC\fR. .PP Test::Lib would croak if such a directory cannot be found. Test::Modern carries on if it can't find it. If you want something more like the Test::Lib behaviour, use the \f(CW\*(C`\-lib\*(C'\fR import tag: .PP .Vb 1 \& use Test::Modern \-lib; .Ve .SS "Brand Spanking New Features" .IX Subsection "Brand Spanking New Features" Test::Modern provides a shortcut which combines several features it has pilfered from other testing modules: .ie n .IP """object_ok($object, $name, %tests)""" 4 .el .IP "\f(CWobject_ok($object, $name, %tests)\fR" 4 .IX Item "object_ok($object, $name, %tests)" Runs a gamut of subtests on an object: .Sp .Vb 10 \& object_ok( \& $object, \& $name, \& isa => \e@classes, \& does => \e@roles, \& can => \e@methods, \& api => \e@methods, \& clean => $boolean, \& more => sub { \& my $object = shift; \& ...; \& } \& ); .Ve .Sp \&\f(CW$object\fR may be a blessed object, or an unblessed coderef which returns a blessed object. The \f(CW\*(C`isa\*(C'\fR test runs \f(CW\*(C`isa_ok\*(C'\fR; the \&\f(CW\*(C`does\*(C'\fR test runs \f(CW\*(C`does_ok\*(C'\fR, the \f(CW\*(C`can\*(C'\fR test runs \&\f(CW\*(C`can_ok\*(C'\fR, and the \f(CW\*(C`api\*(C'\fR test runs \f(CW\*(C`class_api_ok\*(C'\fR. \&\f(CW\*(C`clean\*(C'\fR allows you to run \f(CW\*(C`namespaces_clean\*(C'\fR on the object's class. .Sp \&\f(CW\*(C`more\*(C'\fR introduces a coderef for running more tests. Within this sub you can use any of the standard Test::More, Test::LongString, etc tests. It is automatically run in a \f(CW\*(C`try\*(C'\fR block (see Try::Tiny); throwing an exception will cause the test to fail, but not cause the script to end. .Sp Any of the test hash keys may be omitted, in which case that test will not be run. \f(CW$name\fR may be omitted. .Sp If the test succeeds, it returns the object (which may be useful for further tests). Otherwise, returns \f(CW\*(C`undef\*(C'\fR. .Sp Practical example: .Sp .Vb 10 \& my $bob = object_ok( \& sub { Employee\->new(name => \*(AqRobert Jones\*(Aq) }, \& \*(Aq$bob\*(Aq, \& isa => [qw( Employee Person Moo::Object )], \& does => [qw( Employable )], \& can => [qw( name employee_number tax_code )], \& clean => 1, \& more => sub { \& my $object = shift; \& is($object\->name, "Robert Jones"); \& like($object\->employee_number, qr/^[0\-9]+$/); \& }, \& ); \& \& # make further use of $bob \& object_ok( \& sub { $bob\->line_manager }, \& isa => [qw( Person )], \& ); .Ve .SH "EXPORT" .IX Header "EXPORT" This module uses Exporter::Tiny to perform its exports. This allows exported subs to be renamed, etc. .PP The following export tags are supported: .ie n .IP """\-more""" 4 .el .IP "\f(CW\-more\fR" 4 .IX Item "-more" Exports the \*(L"Features from Test::More\*(R", except deprecated ones. .ie n .IP """\-deprecated""" 4 .el .IP "\f(CW\-deprecated\fR" 4 .IX Item "-deprecated" Exports the deprecated Test::More features. .ie n .IP """\-fatal""" 4 .el .IP "\f(CW\-fatal\fR" 4 .IX Item "-fatal" Exports the \*(L"Features from Test::Fatal\*(R". .ie n .IP """\-warnings""" 4 .el .IP "\f(CW\-warnings\fR" 4 .IX Item "-warnings" Exports the \*(L"Features from Test::Warnings\*(R". .ie n .IP """\-api""" 4 .el .IP "\f(CW\-api\fR" 4 .IX Item "-api" Exports the \*(L"Features from Test::API\*(R", including \f(CW\*(C`class_api_ok\*(C'\fR. .ie n .IP """\-strings""" 4 .el .IP "\f(CW\-strings\fR" 4 .IX Item "-strings" Exports the \*(L"Features from Test::LongString\*(R". .ie n .IP """\-deep""" 4 .el .IP "\f(CW\-deep\fR" 4 .IX Item "-deep" Exports cmp_deeply and \s-1TD\s0. .ie n .IP """\-deeper""" 4 .el .IP "\f(CW\-deeper\fR" 4 .IX Item "-deeper" Exports \fIall\fR the \*(L"Features from Test::Deep\*(R". .ie n .IP """\-moose""" 4 .el .IP "\f(CW\-moose\fR" 4 .IX Item "-moose" Exports the \*(L"Features inspired by Test::Moose\*(R". .ie n .IP """\-clean""" 4 .el .IP "\f(CW\-clean\fR" 4 .IX Item "-clean" Exports the \*(L"Features inspired by Test::CleanNamespaces\*(R". .ie n .IP """\-pod""" 4 .el .IP "\f(CW\-pod\fR" 4 .IX Item "-pod" Exports the \*(L"Features from Test::Pod and Test::Pod::Coverage\*(R". .ie n .IP """\-versions""" 4 .el .IP "\f(CW\-versions\fR" 4 .IX Item "-versions" Exports the \*(L"Features from Test::Version\*(R". .ie n .IP """\-default""" 4 .el .IP "\f(CW\-default\fR" 4 .IX Item "-default" Exports the default features \*(-- all of the above except \f(CW\*(C`\-deprecated\*(C'\fR, \&\f(CW\*(C`\-pod\*(C'\fR, \f(CW\*(C`\-versions\*(C'\fR, and \f(CW\*(C`\-deeper\*(C'\fR. Also exports \f(CW\*(C`object_ok\*(C'\fR. .ie n .IP """\-all""" 4 .el .IP "\f(CW\-all\fR" 4 .IX Item "-all" Exports all of the above features \fIincluding\fR \f(CW\*(C`\-deprecated\*(C'\fR, \&\f(CW\*(C`\-pod\*(C'\fR, \f(CW\*(C`\-versions\*(C'\fR, \f(CW\*(C`\-deeper\*(C'\fR, \f(CW\*(C`object_ok\*(C'\fR, and \&\f(CW\*(C`shouldnt_warn\*(C'\fR. .ie n .IP """\-author"", ""\-extended"", ""\-interactive"", and ""\-release""" 4 .el .IP "\f(CW\-author\fR, \f(CW\-extended\fR, \f(CW\-interactive\fR, and \f(CW\-release\fR" 4 .IX Item "-author, -extended, -interactive, and -release" Classify the test script. .ie n .IP """\-benchmark""" 4 .el .IP "\f(CW\-benchmark\fR" 4 .IX Item "-benchmark" The test script consists mostly of benchmarking. .ie n .IP """\-internet""" 4 .el .IP "\f(CW\-internet\fR" 4 .IX Item "-internet" The test script requires Internet access. .ie n .IP """\-requires"", ""\-without""" 4 .el .IP "\f(CW\-requires\fR, \f(CW\-without\fR" 4 .IX Item "-requires, -without" Specify modules required or hidden for these test cases. .ie n .IP """\-lib""" 4 .el .IP "\f(CW\-lib\fR" 4 .IX Item "-lib" Makes the absence of a \f(CW\*(C`t/lib\*(C'\fR directory fatal. .Sp See \*(L"Features inspired by Test::Lib\*(R". .ie n .IP """\-verbose""" 4 .el .IP "\f(CW\-verbose\fR" 4 .IX Item "-verbose" Makes test output more verbose. (Currently only \f(CW\*(C`is_faster\*(C'\fR takes notice of this.) .PP \&\f(CW$TODO\fR is currently \fIalways\fR exported. .SH "ENVIRONMENT" .IX Header "ENVIRONMENT" Test::Modern is affected by the following environment variables: .ie n .IP """AUTHOR_TESTING"", ""AUTOMATED_TESTING"", ""EXTENDED_TESTING"", ""RELEASE_TESTING""" 4 .el .IP "\f(CWAUTHOR_TESTING\fR, \f(CWAUTOMATED_TESTING\fR, \f(CWEXTENDED_TESTING\fR, \f(CWRELEASE_TESTING\fR" 4 .IX Item "AUTHOR_TESTING, AUTOMATED_TESTING, EXTENDED_TESTING, RELEASE_TESTING" These variables affect the behaviour of Test::Modern's pod-checking and version-checking. See \*(L"Features from Test::Pod and Test::Coverage\*(R" and \*(L"Features from Test::Version\*(R". .Sp They also can trigger certain import tags to skip a test script. See \&\*(L"Features inspired by Test::DescribeMe\*(R", and \&\*(L"Features inspired by Test::Benchmark\*(R" .ie n .IP """NO_NETWORK_TESTS""" 4 .el .IP "\f(CWNO_NETWORK_TESTS\fR" 4 .IX Item "NO_NETWORK_TESTS" Automatically skips any tests which indicate that they require Internet access, without even checking to see if the Internet is accessible. See \*(L"Features inspired by Test::RequiresInternet\*(R". .ie n .IP """PERL_TEST_MODERN_ALLOW_WARNINGS""" 4 .el .IP "\f(CWPERL_TEST_MODERN_ALLOW_WARNINGS\fR" 4 .IX Item "PERL_TEST_MODERN_ALLOW_WARNINGS" Setting this to true allows you to disable Test::Warnings' end test. .Sp Normally the end test will cause a test script to fail if any unexpected warnings are encountered during its execution. New versions of Perl, and upgrades of dependencies can cause a previously good test suite to start emitting warnings. This environment variable can be used as a \*(L"quick fix\*(R" to get the test suite passing again. .SH "BUGS" .IX Header "BUGS" Please report any bugs to . .SH "SEE ALSO" .IX Header "SEE ALSO" My Favourite Test::* Modules , Precision Testing for Modern Perl . .PP Test::More, Test::Fatal, Test::Warnings, Test::API, Test::LongString, Test::Deep, Test::Moose, Test::CleanNamespaces, Test::Requires, Test::Without::Module, Test::RequiresInternet, Test::DescribeMe, Test::Lib, Test::Pod, Test::Pod::Coverage, Test::Version. .PP Test::Most is a similar idea, but provides a slightly different combination of features. .SH "AUTHOR" .IX Header "AUTHOR" Toby Inkster . .SH "COPYRIGHT AND LICENCE" .IX Header "COPYRIGHT AND LICENCE" This software is copyright (c) 2014 by Toby Inkster. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. .SH "DISCLAIMER OF WARRANTIES" .IX Header "DISCLAIMER OF WARRANTIES" \&\s-1THIS PACKAGE IS PROVIDED \*(L"AS IS\*(R" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.\s0