:
=over
=item C<< cmp_deeply($got, $expected, $description) >>
=back
The following are not exported by default, but can be exported upon request:
=over
=item C<< ignore() >>
=item C<< methods(%hash) >>
=item C<< listmethods(%hash) >>
=item C<< shallow($thing) >>
=item C<< noclass($thing) >>
=item C<< useclass($thing) >>
=item C<< re($regexp, $capture_data, $flags) >>
=item C<< superhashof(\%hash) >>
=item C<< subhashof(\%hash) >>
=item C<< bag(@elements) >>
=item C<< set(@elements) >>
=item C<< superbagof(@elements) >>
=item C<< subbagof(@elements) >>
=item C<< supersetof(@elements) >>
=item C<< subsetof(@elements) >>
=item C<< all(@expecteds) >>
=item C<< any(@expecteds) >>
=item C<< obj_isa($class) >>
=item C<< array_each($thing) >>
=item C<< str($string) >>
=item C<< num($number, $tolerance) >>
=item C<< bool($value) >>
=item C<< code(\&subref) >>
=back
As an alternative to using those functions, Test::Modern exports a constant
C upon which you can call them as methods:
# like Test::Deep::bag(@elements)
TD->bag(@elements)
=head2 Features from Test::Pod and Test::Pod::Coverage
B<< These features are currently considered experimental. They
may be removed from a future version of Test::Modern. >>
Test::Modern can export the following subs from L and
L, though they are not exported by default:
=over
=item C<< pod_file_ok($file, $description) >>
=item C<< all_pod_files_ok(@dirs) >>
=item C<< pod_coverage_ok($module, $params, $description) >>
=item C<< all_pod_coverage_ok($params, $description) >>
=back
In fact, Test::Modern wraps these tests in checks to see whether
Test::Pod(::Coverage) is installed, and the state of the
C, C, and C
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 C is
true, in which case I<< 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 C.
Also, Test::Modern wraps the C<< all_* >> functions to run them
in a subtest (because otherwise they can interfere with your test
plans).
=head2 Features from Test::Version
B<< These features are currently considered experimental. They
may be removed from a future version of Test::Modern. >>
Test::Modern can export the following subs from L,
though they are not exported by default:
=over
=item C<< version_ok($file, $description) >>
=item C<< version_all_ok(@dirs) >>
=back
These are wrapped similarly to those described in the
L"Features from Test::Pod and Test::Coverage">.
Test::Modern can also export another sub based on C:
=over
=item C<< version_all_same(@dirs) >>
Acts like C but also checks that all modules have
the same version number.
=back
=head2 Features inspired by Test::Moose
Test::Modern does not use L, but does provide the
following function inspired by it:
=over
=item C<< does_ok($object|$subclass, $class, $name) >>
Like C, but calls C<< $obj->DOES >> instead of C<< $obj->isa >>.
=back
=head2 Features inspired by Test::CleanNamespaces
Test::Modern does not use L, but does provide
the following function inspired by it:
=over
=item C<< namespaces_clean(@namespaces) >>
Tests that namespaces don't contain any imported functions. (i.e. you
haven't forgotten to use L or L
in a class).
Unlike the version of this function supplied with L,
if C<< @namespaces >> contains more than one namespace, these will be run
in a subtest, so the whole thing will only count as one test.
=back
=head2 Features inspired by Test::Benchmark
Test::Modern does not use L, but does provide the
following feature inspired by it:
=over
=item C<< is_fastest($implementation, $times, \%implementations, $desc) >>
use Test::Modern qw( is_fastest );
is_fastest("speedy", -1, {
"speedy" => sub { ... },
"slowcoach" => sub { ... },
});
This ensures that the named coderef runs the fastest out of a hashref
of alternatives. The C<< -1 >> parameter in the example is the number
of times to run the coderefs (see L for more details,
including how numbers less than zero are interpreted).
=back
B<< 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!
B<< 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 C function, but will also
I<< skip the entire script >> unless one of the C or
C environment variables is set.
=head2 Features inspired by Test::Requires
Test::Modern does not use L, but does provide the
following feature inspired by it:
=over
=item C<< use Test::Modern -requires => \%requirements >>
This will skip the entire test script if the requirements are not met.
For example:
use Test::Modern -requires => {
'perl' => '5.010',
'Moose' => '2.11',
'namespace::autoclean' => undef,
};
=back
=head2 Features inspired by Test::RequiresInternet
Similarly 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 L but I've stolen much
of the latter's implementation.
=head2 Features inspired by Test::Without::Module
Test::Modern does not use L, but does provide
the following feature inspired by it:
=over
=item C<< 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:
use Test::Modern -without => [ "Class::XSAccessor" ];
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:
perl -MTest::Modern -le'print for sort keys %INC'
(Note that the actual implementation is mostly stolen from
L which seems to behave better than
L.)
=back
=head2 Features inspired by Test::DescribeMe
These 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.
=over
=item C<< use Test::Modern -author >>
=item C<< use Test::Modern -release >>
=item C<< use Test::Modern -extended >>
=item C<< use Test::Modern -interactive >>
=back
=head2 Features inspired by Test::Lib
B<< These features are currently considered experimental. They
may be removed from a future version of Test::Modern. >>
Test::Modern tries to find a directory called C<< t/lib >> by
traversing up the directory tree from the caller file. If found,
this directory will be added to C<< @INC >>.
L would croak if such a directory cannot be found.
L carries on if it can't find it. If you want something
more like the Test::Lib behaviour, use the C<< -lib >> import tag:
use Test::Modern -lib;
=head2 Brand Spanking New Features
Test::Modern provides a shortcut which combines several features it has
pilfered from other testing modules:
=over
=item C<< object_ok($object, $name, %tests) >>
Runs a gamut of subtests on an object:
object_ok(
$object,
$name,
isa => \@classes,
does => \@roles,
can => \@methods,
api => \@methods,
clean => $boolean,
more => sub {
my $object = shift;
...;
}
);
C<< $object >> may be a blessed object, or an unblessed coderef which
returns a blessed object. The C<< isa >> test runs C<< isa_ok >>; the
C<< does >> test runs C<< does_ok >>, the C<< can >> test runs
C<< can_ok >>, and the C<< api >> test runs C<< class_api_ok >>.
C<< clean >> allows you to run C<< namespaces_clean >> on the object's
class.
C<< more >> 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 C<< try >> block (see L);
throwing an exception will cause the test to fail, but not cause the
script to end.
Any of the test hash keys may be omitted, in which case that test will
not be run. C<< $name >> may be omitted.
If the test succeeds, it returns the object (which may be useful for
further tests). Otherwise, returns C.
Practical example:
my $bob = object_ok(
sub { Employee->new(name => 'Robert Jones') },
'$bob',
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 )],
);
=back
=head1 EXPORT
This module uses L to perform its exports. This allows
exported subs to be renamed, etc.
The following export tags are supported:
=over
=item C<< -more >>
Exports the L"Features from Test::More">, except deprecated ones.
=item C<< -deprecated >>
Exports the deprecated Test::More features.
=item C<< -fatal >>
Exports the L"Features from Test::Fatal">.
=item C<< -warnings >>
Exports the L"Features from Test::Warnings">.
=item C<< -api >>
Exports the L"Features from Test::API">, including C.
=item C<< -strings >>
Exports the L"Features from Test::LongString">.
=item C<< -deep >>
Exports L.
=item C<< -deeper >>
Exports I the L"Features from Test::Deep">.
=item C<< -moose >>
Exports the L"Features inspired by Test::Moose">.
=item C<< -clean >>
Exports the L"Features inspired by Test::CleanNamespaces">.
=item C<< -pod >>
Exports the L"Features from Test::Pod and Test::Pod::Coverage">.
=item C<< -versions >>
Exports the L"Features from Test::Version">.
=item C<< -default >>
Exports the default features -- all of the above except C<< -deprecated >>,
C<< -pod >>, C<< -versions >>, and C<< -deeper >>. Also exports C.
=item C<< -all >>
Exports all of the above features I C<< -deprecated >>,
C<< -pod >>, C<< -versions >>, C<< -deeper >>, C, and
C.
=item C<< -author >>, C<< -extended >>, C<< -interactive >>, and C<< -release >>
Classify the test script.
=item C<< -benchmark >>
The test script consists mostly of benchmarking.
=item C<< -internet >>
The test script requires Internet access.
=item C<< -requires >>, C<< -without >>
Specify modules required or hidden for these test cases.
=item C<< -lib >>
Makes the absence of a C<< t/lib >> directory fatal.
See L"Features inspired by Test::Lib">.
=item C<< -verbose >>
Makes test output more verbose. (Currently only C takes notice
of this.)
=back
C<< $TODO >> is currently I |