|
NAMETest::Modern - precision testing for modern perlSYNOPSISuse Test::Modern; # Your tests here done_testing; DESCRIPTIONTest::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.Test::Modern also automatically imposes strict and warnings on your script, and loads IO::File. (Much of the same stuff Modern::Perl does.) 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 OK on anything back to Perl 5.6.1. Features from Test::MoreTest::Modern exports the following subs from Test::More:
The "use_ok", "require_ok", "eq_array", "eq_hash", and "eq_set" functions are also available, but not exported by default. For "use_ok" and "require_ok" it's normally better to use the Perl built-ins "use" and "require" which will die (failing your test) if things are not OK. For the "eq_*" functions, they can usually be replaced by "is_deeply". Features from Test::FatalTest::Modern exports the following subs from Test::Fatal:
Features from Test::WarningsTest::Modern exports the following subs from Test::Warnings:
In addition, Test::Modern always enables the "had_no_warnings" test at the end of the file, ensuring that your test script generated no warnings other than the expected ones which were caught by "warnings" blocks. (See also "PERL_TEST_MODERN_ALLOW_WARNINGS" in "ENVIRONMENT".) Test::Modern can also export an additional function for testing warnings, but does not export it by default:
Features from Test::APITest::Modern exports the following subs from Test::API:
Features from Test::LongStringTest::Modern exports the following subs from Test::LongString:
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 "is", "isnt", "like", and "unlike" functions. (The diagnostics won't be as good in the case of failures.) Features from Test::DeepTest::Modern exports the following subs from Test::Deep:
The following are not exported by default, but can be exported upon request:
As an alternative to using those functions, Test::Modern exports a constant "TD" upon which you can call them as methods: # like Test::Deep::bag(@elements) TD->bag(@elements) Features from Test::Pod and Test::Pod::CoverageThese features are currently considered experimental. They may be removed from a future version of Test::Modern.Test::Modern can export the following subs from Test::Pod and Test::Pod::Coverage, though they are not exported by default:
In fact, Test::Modern wraps these tests in checks to see whether Test::Pod(::Coverage) is installed, and the state of the "RELEASE_TESTING", "AUTHOR_TESTING", and "EXTENDED_TESTING" 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 "RELEASE_TESTING" is true, in which case Test::Pod(::Coverage) must be installed. 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 "EXTENDED_TESTING". Also, Test::Modern wraps the "all_*" functions to run them in a subtest (because otherwise they can interfere with your test plans). Features from Test::VersionThese features are currently considered experimental. They may be removed from a future version of Test::Modern.Test::Modern can export the following subs from Test::Version, though they are not exported by default:
These are wrapped similarly to those described in the "Features from Test::Pod and Test::Coverage". Test::Modern can also export another sub based on "version_all_ok":
Features inspired by Test::MooseTest::Modern does not use Test::Moose, but does provide the following function inspired by it:
Features inspired by Test::CleanNamespacesTest::Modern does not use Test::CleanNamespaces, but does provide the following function inspired by it:
Features inspired by Test::BenchmarkTest::Modern does not use Test::Benchmark, but does provide the following feature inspired by it:
Caveat: 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! Caveat the second: these tests tend to be slow. Use sparingly. 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). 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: use Test::Modern -benchmark; This will not only import the "is_fastest" function, but will also skip the entire script unless one of the "EXTENDED_TESTING" or "RELEASE_TESTING" environment variables is set. Features inspired by Test::RequiresTest::Modern does not use Test::Requires, but does provide the following feature inspired by it:
Features inspired by Test::RequiresInternetSimilarly you can skip the test script if an Internet connection is not available:use Test::Modern -internet; You can check for the ability to connect to particular hosts and ports: use Test::Modern -internet => [ 'www.example.com' => 'http', '8.8.8.8' => 53, ]; Test::Modern does not use Test::RequiresInternet but I've stolen much of the latter's implementation. Features inspired by Test::Without::ModuleTest::Modern does not use Test::Without::Module, but does provide the following feature inspired by it:
Features inspired by Test::DescribeMeThese export tags allow you to classify tests as "author tests", "release tests", "extended tests", or "interactive tests".They will cause your test script to be skipped depending on various environment variables.
Features inspired by Test::LibThese features are currently considered experimental. They may be removed from a future version of Test::Modern.Test::Modern tries to find a directory called "t/lib" by traversing up the directory tree from the caller file. If found, this directory will be added to @INC. 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 "-lib" import tag: use Test::Modern -lib; Brand Spanking New FeaturesTest::Modern provides a shortcut which combines several features it has pilfered from other testing modules:
EXPORTThis module uses Exporter::Tiny to perform its exports. This allows exported subs to be renamed, etc.The following export tags are supported:
$TODO is currently always exported. ENVIRONMENTTest::Modern is affected by the following environment variables:
BUGSPlease report any bugs to <http://rt.cpan.org/Dist/Display.html?Queue=Test-Modern>.SEE ALSOMy Favourite Test::* Modules <http://blogs.perl.org/users/toby_inkster/2014/02/my-favourite-test-modules.html>, Precision Testing for Modern Perl <http://blogs.perl.org/users/toby_inkster/2014/03/precision-testing-for-modern-perl.html>.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. Test::Most is a similar idea, but provides a slightly different combination of features. AUTHORToby Inkster <tobyink@cpan.org>.COPYRIGHT AND LICENCEThis software is copyright (c) 2014 by Toby Inkster.This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. DISCLAIMER OF WARRANTIESTHIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Visit the GSP FreeBSD Man Page Interface. |