require 5.004;
package Test;
use strict;
use Carp;
our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, $ntest, $TestLevel); #public-is
our ($TESTOUT, $TESTERR, %Program_Lines, $told_about_diff,
$ONFAIL, %todo, %history, $planned, @FAILDETAIL); #private-ish
# In case a test is run in a persistent environment.
sub _reset_globals {
%todo = ();
%history = ();
@FAILDETAIL = ();
$ntest = 1;
$TestLevel = 0; # how many extra stack frames to skip
$planned = 0;
}
$VERSION = '1.31';
require Exporter;
@ISA=('Exporter');
@EXPORT = qw(&plan &ok &skip);
@EXPORT_OK = qw($ntest $TESTOUT $TESTERR);
$|=1;
$TESTOUT = *STDOUT{IO};
$TESTERR = *STDERR{IO};
# Use of this variable is strongly discouraged. It is set mainly to
# help test coverage analyzers know which test is running.
$ENV{REGRESSION_TEST} = $0;
=head1 NAME
Test - provides a simple framework for writing test scripts
=head1 SYNOPSIS
use strict;
use Test;
# use a BEGIN block so we print our plan before MyModule is loaded
BEGIN { plan tests => 14, todo => [3,4] }
# load your module...
use MyModule;
# Helpful notes. All note-lines must start with a "#".
print "# I'm testing MyModule version $MyModule::VERSION\n";
ok(0); # failure
ok(1); # success
ok(0); # ok, expected failure (see todo list, above)
ok(1); # surprise success!
ok(0,1); # failure: '0' ne '1'
ok('broke','fixed'); # failure: 'broke' ne 'fixed'
ok('fixed','fixed'); # success: 'fixed' eq 'fixed'
ok('fixed',qr/x/); # success: 'fixed' =~ qr/x/
ok(sub { 1+1 }, 2); # success: '2' eq '2'
ok(sub { 1+1 }, 3); # failure: '2' ne '3'
my @list = (0,0);
ok @list, 3, "\@list=".join(',',@list); #extra notes
ok 'segmentation fault', '/(?i)success/'; #regex match
skip(
$^O =~ m/MSWin/ ? "Skip if MSWin" : 0, # whether to skip
$foo, $bar # arguments just like for ok(...)
);
skip(
$^O =~ m/MSWin/ ? 0 : "Skip unless MSWin", # whether to skip
$foo, $bar # arguments just like for ok(...)
);
=head1 DESCRIPTION
This module simplifies the task of writing test files for Perl modules,
such that their output is in the format that
L expects to see.
=head1 QUICK START GUIDE
To write a test for your new (and probably not even done) module, create
a new file called F (in a new F directory). If you have
multiple test files, to test the "foo", "bar", and "baz" feature sets,
then feel free to call your files F, F, and
F
=head2 Functions
This module defines three public functions, C, C,
and C. By default, all three are exported by
the C