Class-Object
view release on metacpan or search on metacpan
t/lib/Test/More.pm view on Meta::CPAN
unless( $ok ) {
_print *TESTERR, <<DIAGNOSTIC;
# Tried to use '$module'.
# Error: $@
DIAGNOSTIC
}
return $ok;
}
sub require_ok ($) {
my($module) = shift;
my $pack = caller;
eval <<REQUIRE;
package $pack;
require $module;
REQUIRE
my $ok = ok( !$@, "require $module;" );
unless( $ok ) {
_print *TESTERR, <<DIAGNOSTIC;
# Tried to require '$module'.
# Error: $@
DIAGNOSTIC
}
return $ok;
}
=head2 Conditional tests
Sometimes running a test under certain conditions will cause the
test script to die. A certain function or method isn't implemented
(such as fork() on MacOS), some resource isn't available (like a
net connection) or a module isn't available. In these cases its
necessary to skip test, or declare that they are supposed to fail
but will work in the future (a todo test).
For more details on skip and todo tests, L<Test::Harness>.
=over 4
=item B<skip> * UNIMPLEMENTED *
skip BLOCK $how_many, $why, $if;
B<NOTE> Should that be $if or $unless?
This declares a block of tests to skip, why and under what conditions
to skip them. An example is the easiest way to illustrate:
skip {
ok( head("http://www.foo.com"), "www.foo.com is alive" );
ok( head("http://www.foo.com/bar"), " and has bar" );
} 2, "LWP::Simple not installed",
!eval { require LWP::Simple; LWP::Simple->import; 1 };
The $if condition is optional, but $why is not.
=cut
sub skip {
die "skip() is UNIMPLEMENTED!";
}
=item B<todo> * UNIMPLEMENTED *
todo BLOCK $how_many, $why;
todo BLOCK $how_many, $why, $until;
Declares a block of tests you expect to fail and why. Perhaps its
because you haven't fixed a bug:
todo { is( $Gravitational_Constant, 0 ) } 1,
"Still tinkering with physics --God";
If you have a set of functionality yet to implement, you can make the
whole suite dependent on that new feature.
todo {
$pig->takeoff;
ok( $pig->altitude > 0 );
ok( $pig->mach > 2 );
ok( $pig->serve_peanuts );
} 1, "Pigs are still safely grounded",
Pigs->can('fly');
=cut
sub todo {
die "todo() is UNIMPLEMENTED!";
}
=head2 Comparision functions
Not everything is a simple eq check or regex. There are times you
need to see if two arrays are equivalent, for instance. For these
instances, Test::More provides a handful of useful functions.
B<NOTE> These are NOT well-tested on circular references. Nor am I
quite sure what will happen with filehandles.
=over 4
=item B<eq_array>
eq_array(\@this, \@that);
Checks if two arrays are equivalent. This is a deep check, so
multi-level structures are handled correctly.
=cut
( run in 2.058 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )