.\" -*- mode: troff; coding: utf-8 -*-
.\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.47)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
.ie n \{\
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds C`
.    ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD.  Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
.    if \nF \{\
.        de IX
.        tm Index:\\$1\t\\n%\t"\\$2"
..
.        if !\nF==2 \{\
.            nr % 0
.            nr F 2
.        \}
.    \}
.\}
.rr rF
.\"
.\" Required to disable full justification in groff 1.23.0.
.if n .ds AD l
.\" ========================================================================
.\"
.IX Title "Test::Simple 3"
.TH Test::Simple 3 2025-07-25 "perl v5.42.0" "User Contributed Perl Documentation"
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH NAME
Test::Simple \- Basic utilities for writing tests.
.SH SYNOPSIS
.IX Header "SYNOPSIS"
.Vb 1
\&  use Test::Simple tests => 1;
\&
\&  ok( $foo eq $bar, \*(Aqfoo is bar\*(Aq );
.Ve
.SH DESCRIPTION
.IX Header "DESCRIPTION"
** If you are unfamiliar with testing \fBread Test::Tutorial first!\fR **
.PP
This is an extremely simple, extremely basic module for writing tests
suitable for CPAN modules and other pursuits.  If you wish to do more
complicated testing, use the Test::More module (a drop\-in replacement
for this one).
.PP
The basic unit of Perl testing is the ok.  For each thing you want to
test your program will print out an "ok" or "not ok" to indicate pass
or fail.  You do this with the \f(CWok()\fR function (see below).
.PP
The only other constraint is you must pre\-declare how many tests you
plan to run.  This is in case something goes horribly wrong during the
test and your test program aborts, or skips a test or whatever.  You
do this like so:
.PP
.Vb 1
\&    use Test::Simple tests => 23;
.Ve
.PP
You must have a plan.
.IP \fBok\fR 4
.IX Item "ok"
.Vb 2
\&  ok( $foo eq $bar, $name );
\&  ok( $foo eq $bar );
.Ve
.Sp
\&\f(CWok()\fR is given an expression (in this case \f(CW\*(C`$foo eq $bar\*(C'\fR).  If it\*(Aqs
true, the test passed.  If it\*(Aqs false, it didn\*(Aqt.  That\*(Aqs about it.
.Sp
\&\f(CWok()\fR prints out either "ok" or "not ok" along with a test number (it
keeps track of that for you).
.Sp
.Vb 2
\&  # This produces "ok 1 \- Hell not yet frozen over" (or not ok)
\&  ok( get_temperature($hell) > 0, \*(AqHell not yet frozen over\*(Aq );
.Ve
.Sp
If you provide a \f(CW$name\fR, that will be printed along with the "ok/not
ok" to make it easier to find your test when if fails (just search for
the name).  It also makes it easier for the next guy to understand
what your test is for.  It\*(Aqs highly recommended you use test names.
.Sp
All tests are run in scalar context.  So this:
.Sp
.Vb 1
\&    ok( @stuff, \*(AqI have some stuff\*(Aq );
.Ve
.Sp
will do what you mean (fail if stuff is empty)
.PP
Test::Simple will start by printing number of tests run in the form
"1..M" (so "1..5" means you\*(Aqre going to run 5 tests).  This strange
format lets Test::Harness know how many tests you plan on running in
case something goes horribly wrong.
.PP
If all your tests passed, Test::Simple will exit with zero (which is
normal).  If anything failed it will exit with how many failed.  If
you run less (or more) tests than you planned, the missing (or extras)
will be considered failures.  If no tests were ever run Test::Simple
will throw a warning and exit with 255.  If the test died, even after
having successfully completed all its tests, it will still be
considered a failure and will exit with 255.
.PP
So the exit codes are...
.PP
.Vb 3
\&    0                   all tests successful
\&    255                 test died or all passed but wrong # of tests run
\&    any other number    how many failed (including missing or extras)
.Ve
.PP
If you fail more than 254 tests, it will be reported as 254.
.PP
This module is by no means trying to be a complete testing system.
It\*(Aqs just to get you started.  Once you\*(Aqre off the ground its
recommended you look at Test::More.
.SH EXAMPLE
.IX Header "EXAMPLE"
Here\*(Aqs an example of a simple .t file for the fictional Film module.
.PP
.Vb 1
\&    use Test::Simple tests => 5;
\&
\&    use Film;  # What you\*(Aqre testing.
\&
\&    my $btaste = Film\->new({ Title    => \*(AqBad Taste\*(Aq,
\&                             Director => \*(AqPeter Jackson\*(Aq,
\&                             Rating   => \*(AqR\*(Aq,
\&                             NumExplodingSheep => 1
\&                           });
\&    ok( defined($btaste) && ref $btaste eq \*(AqFilm\*(Aq,     \*(Aqnew() works\*(Aq );
\&
\&    ok( $btaste\->Title      eq \*(AqBad Taste\*(Aq,     \*(AqTitle() get\*(Aq    );
\&    ok( $btaste\->Director   eq \*(AqPeter Jackson\*(Aq, \*(AqDirector() get\*(Aq );
\&    ok( $btaste\->Rating     eq \*(AqR\*(Aq,             \*(AqRating() get\*(Aq   );
\&    ok( $btaste\->NumExplodingSheep == 1,        \*(AqNumExplodingSheep() get\*(Aq );
.Ve
.PP
It will produce output like this:
.PP
.Vb 9
\&    1..5
\&    ok 1 \- new() works
\&    ok 2 \- Title() get
\&    ok 3 \- Director() get
\&    not ok 4 \- Rating() get
\&    #   Failed test \*(AqRating() get\*(Aq
\&    #   in t/film.t at line 14.
\&    ok 5 \- NumExplodingSheep() get
\&    # Looks like you failed 1 tests of 5
.Ve
.PP
Indicating the \fBFilm::Rating()\fR method is broken.
.SH CAVEATS
.IX Header "CAVEATS"
Test::Simple will only report a maximum of 254 failures in its exit
code.  If this is a problem, you probably have a huge test script.
Split it into multiple files.  (Otherwise blame the Unix folks for
using an unsigned short integer as the exit status).
.PP
Because VMS\*(Aqs exit codes are much, much different than the rest of the
universe, and perl does horrible mangling to them that gets in my way,
it works like this on VMS.
.PP
.Vb 2
\&    0     SS$_NORMAL        all tests successful
\&    4     SS$_ABORT         something went wrong
.Ve
.PP
Unfortunately, I can\*(Aqt differentiate any further.
.SH NOTES
.IX Header "NOTES"
Test::Simple is \fBexplicitly\fR tested all the way back to perl 5.6.0.
.PP
Test::Simple is thread\-safe in perl 5.8.1 and up.
.SH HISTORY
.IX Header "HISTORY"
This module was conceived while talking with Tony Bowden in his
kitchen one night about the problems I was having writing some really
complicated feature into the new Testing module.  He observed that the
main problem is not dealing with these edge cases but that people hate
to write tests \fBat all\fR.  What was needed was a dead simple module
that took all the hard work out of testing and was really, really easy
to learn.  Paul Johnson simultaneously had this idea (unfortunately,
he wasn\*(Aqt in Tony\*(Aqs kitchen).  This is it.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
.IP Test::More 4
.IX Item "Test::More"
More testing functions!  Once you outgrow Test::Simple, look at
Test::More.  Test::Simple is 100% forward compatible with Test::More
(i.e. you can just use Test::More instead of Test::Simple in your
programs and things will still work).
.PP
Look in Test::More\*(Aqs SEE ALSO for more testing modules.
.SH AUTHORS
.IX Header "AUTHORS"
Idea by Tony Bowden and Paul Johnson, code by Michael G Schwern
<schwern@pobox.com>, wardrobe by Calvin Klein.
.SH MAINTAINERS
.IX Header "MAINTAINERS"
.IP "Chad Granum <exodist@cpan.org>" 4
.IX Item "Chad Granum <exodist@cpan.org>"
.SH COPYRIGHT
.IX Header "COPYRIGHT"
Copyright 2001\-2008 by Michael G Schwern <schwern@pobox.com>.
.PP
This program is free software; you can redistribute it and/or 
modify it under the same terms as Perl itself.
.PP
See <https://dev.perl.org/licenses/>
