Test::Simple - Online Linux Manual PageSection : 3
Updated : 2022-03-05
Source : perl v5.34.0
Note : User Contributed Perl Documentation
NAMETest::Simple − Basic utilities for writing tests.
SYNOPSIS use Test::Simple tests => 1;
ok( $foo eq $bar, 'foo is bar' );
DESCRIPTION** If you are unfamiliar with testing read Test::Tutorial first! ** 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). 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 ok() function (see below). 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: use Test::Simple tests => 23;
You must have a plan. ok ok( $foo eq $bar, $name );
ok( $foo eq $bar );
ok() is given an expression (in this case $foo eq $bar). If it's true, the test passed. If it's false, it didn't. That's about it. ok() prints out either ‟ok” or ‟not ok” along with a test number (it keeps track of that for you). # This produces "ok 1 − Hell not yet frozen over" (or not ok)
ok( get_temperature($hell) > 0, 'Hell not yet frozen over' );
If you provide a $name, 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's highly recommended you use test names. All tests are run in scalar context. So this: ok( @stuff, 'I have some stuff' );
will do what you mean (fail if stuff is empty) Test::Simple will start by printing number of tests run in the form ‟1..M” (so ‟1..5” means you're 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. 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. So the exit codes are... 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)
If you fail more than 254 tests, it will be reported as 254. This module is by no means trying to be a complete testing system. It's just to get you started. Once you're off the ground its recommended you look at Test::More.
EXAMPLEHere's an example of a simple .t file for the fictional Film module. use Test::Simple tests => 5;
use Film; # What you're testing.
my $btaste = Film−>new({ Title => 'Bad Taste',
Director => 'Peter Jackson',
Rating => 'R',
NumExplodingSheep => 1
});
ok( defined($btaste) && ref $btaste eq 'Film', 'new() works' );
ok( $btaste−>Title eq 'Bad Taste', 'Title() get' );
ok( $btaste−>Director eq 'Peter Jackson', 'Director() get' );
ok( $btaste−>Rating eq 'R', 'Rating() get' );
ok( $btaste−>NumExplodingSheep == 1, 'NumExplodingSheep() get' );
It will produce output like this: 1..5
ok 1 − new() works
ok 2 − Title() get
ok 3 − Director() get
not ok 4 − Rating() get
# Failed test 'Rating() get'
# in t/film.t at line 14.
ok 5 − NumExplodingSheep() get
# Looks like you failed 1 tests of 5
Indicating the Film::Rating() method is broken.
CAVEATSTest::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). Because VMS's 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. 0 SS$_NORMAL all tests successful
4 SS$_ABORT something went wrong
Unfortunately, I can't differentiate any further.
NOTESTest::Simple is explicitly tested all the way back to perl 5.6.0. Test::Simple is thread-safe in perl 5.8.1 and up.
HISTORYThis 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 at all. 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't in Tony's kitchen). This is it.
SEE ALSOTest::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). Look in Test::More's SEE ALSO for more testing modules.
AUTHORSIdea by Tony Bowden and Paul Johnson, code by Michael G Schwern <schwern@pobox.com>, wardrobe by Calvin Klein.
MAINTAINERSChad Granum <exodist@cpan.org>
COPYRIGHTCopyright 2001−2008 by Michael G Schwern <schwern@pobox.com>. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html 0
Johanes Gumabo
Data Size : 18,647 byte
man-Test::Simple.3pmBuild : 2024-12-05, 20:55 :
Visitor Screen : x
Visitor Counter ( page / site ) : 2 / 164,999
Visitor ID : :
Visitor IP : 3.21.105.46 :
Visitor Provider : AMAZON-02 :
Provider Position ( lat x lon ) : 39.962500 x -83.006100 : x
Provider Accuracy Radius ( km ) : 1000 :
Provider City : Columbus :
Provider Province : Ohio , : ,
Provider Country : United States :
Provider Continent : North America :
Visitor Recorder : Version :
Visitor Recorder : Library :
Online Linux Manual Page : Version : Online Linux Manual Page - Fedora.40 - march=x86-64 - mtune=generic - 24.12.05
Online Linux Manual Page : Library : lib_c - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Online Linux Manual Page : Library : lib_m - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Data Base : Version : Online Linux Manual Page Database - 24.04.13 - march=x86-64 - mtune=generic - fedora-38
Data Base : Library : lib_c - 23.02.07 - march=x86-64 - mtune=generic - fedora.36
Very long time ago, I have the best tutor, Wenzel Svojanovsky . If someone knows the email address of Wenzel Svojanovsky , please send an email to johanes_gumabo@yahoo.co.id .
If error, please print screen and send to johanes_gumabo@yahoo.co.id
Under development. Support me via PayPal.
ERROR : Need New Coding : (parse_manual_page_|249|Test::Simple.3pm|36/37|el══─{─══.|.el══─{─══. ds -- \|\(em\|
) (htmlprn|149|Test::Simple.3pm|36/37|.el══─{─══. ds -- — |.el══─{─══. ds -- \|\(em\|
) (parse_manual_page_|249|Test::Simple.3pm|43|br══─}─══|'br══─}─══
) (htmlprn|149|Test::Simple.3pm|43|'br══─}─══ |'br══─}─══
)