Test::Simple

Provides basic utilities for writing tests. It is shipped with the Perl source kit as of 5.8. For example:

my $name = 'Inigo Montoya';
my $quote = 'Prepare to die';
ok($name eq $quote, 'name is quote');

The ok function is given an expression to evaluate. ok() prints out 'ok' or 'not ok' along with the number of the test.

Here’s another example that tests if you can use CGI.pm:

#!/usr/local/bin/perl -w
use Test::Simple tests => 2;
use CGI; # Test this
 
my $cgi = CGI->new();

# Test #1—this will be ok
ok(defined($cgi) and ref $cgi eq 'CGI', 'I have your CGI right here!');

my $header = $cgi->header(-type => `text/plain');

# Test #2—this will not be ok
ok($header eq "Content-Type: text/mex");

Get Perl in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.