ExtUtils-SVDmaker
view release on metacpan or search on metacpan
t/ExtUtils/SVDmaker/Test.pm view on Meta::CPAN
=head2 Functions
This module defines three public functions, C<plan(...)>, C<ok(...)>,
and C<skip(...)>. By default, all three are exported by
the C<use Test;> statement.
=over 4
=item C<plan(...)>
BEGIN { plan %theplan; }
This should be the first thing you call in your test script. It
declares your testing plan, how many there will be, if any of them
should be allowed to fail, and so on.
Typical usage is just:
use Test;
BEGIN { plan tests => 23 }
These are the things that you can put in the parameters to plan:
=over
=item C<tests =E<gt> I<number>>
The number of tests in your script.
This means all ok() and skip() calls.
=item C<todo =E<gt> [I<1,5,14>]>
A reference to a list of tests which are allowed to fail.
See L</TODO TESTS>.
=item C<onfail =E<gt> sub { ... }>
=item C<onfail =E<gt> \&some_sub>
A subroutine reference to be run at the end of the test script, if
any of the tests fail. See L</ONFAIL>.
=back
You must call C<plan(...)> once and only once. You should call it
in a C<BEGIN {...}> block, like so:
BEGIN { plan tests => 23 }
=cut
sub plan {
croak "Test::plan(%args): odd number of arguments" if @_ & 1;
croak "Test::plan(): should not be called more than once" if $planned;
local($\, $,); # guard against -l and other things that screw with
# print
_reset_globals();
_read_program( (caller)[1] );
my $max=0;
while (@_) {
my ($k,$v) = splice(@_, 0, 2);
if ($k =~ /^test(s)?$/) { $max = $v; }
elsif ($k eq 'todo' or
$k eq 'failok') { for (@$v) { $todo{$_}=1; }; }
elsif ($k eq 'onfail') {
ref $v eq 'CODE' or croak "Test::plan(onfail => $v): must be CODE";
$ONFAIL = $v;
}
else { carp "Test::plan(): skipping unrecognized directive '$k'" }
}
my @todo = sort { $a <=> $b } keys %todo;
if (@todo) {
print $TESTOUT "1..$max todo ".join(' ', @todo).";\n";
} else {
print $TESTOUT "1..$max\n";
}
++$planned;
print $TESTOUT "# Running under perl version $] for $^O",
(chr(65) eq 'A') ? "\n" : " in a non-ASCII world\n";
print $TESTOUT "# Win32::BuildNumber ", &Win32::BuildNumber(), "\n"
if defined(&Win32::BuildNumber) and defined &Win32::BuildNumber();
print $TESTOUT "# MacPerl version $MacPerl::Version\n"
if defined $MacPerl::Version;
printf $TESTOUT
"# Current time local: %s\n# Current time GMT: %s\n",
scalar(localtime($^T)), scalar(gmtime($^T));
print $TESTOUT "# Using Test.pm version $VERSION\n";
# Retval never used:
return undef;
}
sub _read_program {
my($file) = shift;
return unless defined $file and length $file
and -e $file and -f _ and -r _;
open(SOURCEFILE, "<$file") || return;
$Program_Lines{$file} = [<SOURCEFILE>];
close(SOURCEFILE);
foreach my $x (@{$Program_Lines{$file}})
{ $x =~ tr/\cm\cj\n\r//d }
unshift @{$Program_Lines{$file}}, '';
return 1;
}
=begin _private
=item B<_to_value>
my $value = _to_value($input);
( run in 1.596 second using v1.01-cache-2.11-cpan-5511b514fd6 )