Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine


by root (Scribe)
on Dec 23, 1999 at 00:49 UTC ( #1129=perlfunc: print w/ replies, xml ) Need Help??


See the current Perl documentation for lib:Test.

Here is our local, out-dated (pre-5.6) version:

  Test - provides a simple framework for writing test scripts

  use strict;
  use Test;
  BEGIN { plan tests => 13, todo => [3,4] }

  ok(0); # failure
  ok(1); # success

  ok(0); # ok, expected failure (see todo list, above)
  ok(1); # surprise success!

Test::Harness expects to see particular output when it executes tests. This module aims to make writing proper test scripts just a little bit easier (and less error prone :-).



    These tests are expected to succeed. If they don't, something's screwed up!

  • SKIPPED TESTS Skip tests need a platform specific feature that might or might not be available. The first argument should evaluate to true if the required feature is NOT available. After the first argument, skip tests work exactly the same way as do normal tests.

  • TODO TESTS TODO tests are designed for maintaining an executable TODO list. These tests are expected NOT to succeed (otherwise the feature they test would be on the new feature list, not the TODO list).

    Packages should NOT be released with successful TODO tests. As soon as a TODO test starts working, it should be promoted to a normal test and the newly minted feature should be documented in the release notes.


  BEGIN { plan test => 4, onfail => sub { warn "CALL 911!" } }

The test failures can trigger extra diagnostics at the end of the test run. onfail is passed an array ref of hash refs that describe each test failure. Each hash will contain at least the following fields: package, repetition, and result. (The file, line, and test number are not included because their correspondance to a particular test is fairly weak.) If the test had an expected value or a diagnostic string, these will also be included.

This optional feature might be used simply to print out the version of your package and/or how to report problems. It might also be used to generate extremely sophisticated diagnostics for a particular test failure. It's not a panacea, however. Core dumps or other unrecoverable errors will prevent the onfail hook from running. (It is run inside an END block.) Besides, onfail is probably over-kill in the majority of cases. (Your test code should be simpler than the code it is testing, yes?)


Test::Harness and various test coverage analysis tools.


Copyright (C) 1998 Joshua Nathaniel Pritikin. All rights reserved.

This package is free software and is provided ``as is'' without express or implied warranty. It may be used, redistributed and/or modified under the terms of the Perl Artistic License (see

Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (13)
As of 2015-10-09 14:15 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (242 votes), past polls