June 2002
Beginner
759 pages
80h 42m
English
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");