Declares that this test will run an indeterminate # of tests.
=cut
my($No_Plan) = 0;
sub no_plan {
$No_Plan = 1;
$Have_Plan = 1;
}
=item B<has_plan>
$plan = $Test->has_plan
Find out whether a plan has been defined. $plan is either C<undef> (no plan has been set), C<no_plan> (indeterminate # of tests) or an integer (the number of expected tests).
=cut
sub has_plan {
return($Expected_Tests) if $Expected_Tests;
return('no_plan') if $No_Plan;
return(undef);
};
=item B<skip_all>
$Test->skip_all;
$Test->skip_all($reason);
Skips all the tests, using the given $reason. Exits immediately with 0.
=cut
my $Skip_All = 0;
sub skip_all {
my($self, $reason) = @_;
my $out = "1..0";
$out .= " # Skip $reason" if $reason;
$out .= "\n";
$Skip_All = 1;
$self->_print($out) unless $self->no_header;
exit(0);
}
=back
=head2 Running tests
These actually run the tests, analogous to the functions in
Test::More.
$name is always optional.
=over 4
=item B<ok>
$Test->ok($test, $name);
Your basic test. Pass if $test is true, fail if $test is false. Just
like Test::Simple's ok().
=cut
sub ok {
my($self, $test, $name) = @_;
# $test might contain an object which we don't want to accidentally
# store, so we turn it into a boolean.
$test = $test ? 1 : 0;
unless( $Have_Plan ) {
require Carp;
Carp::croak("You tried to run a test without a plan! Gotta have a plan.");
}
lock $Curr_Test;
$Curr_Test++;
$self->diag(<<ERR) if defined $name and $name =~ /^[\d\s]+$/;
You named your test '$name'. You shouldn't use numbers for your test names.