Skip to Main Content
Perl in a Nutshell, 2nd Edition
book

Perl in a Nutshell, 2nd Edition

by Nathan Patwardhan, Ellen Siever, Stephen Spainhour
June 2002
Beginner content levelBeginner
759 pages
80h 42m
English
O'Reilly Media, Inc.
Content preview from Perl in a Nutshell, 2nd Edition

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");
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Perl by Example, Fourth Edition

Perl by Example, Fourth Edition

Ellie Quigley
Perl Cookbook, 2nd Edition

Perl Cookbook, 2nd Edition

Tom Christiansen, Nathan Torkington
Perl in a Nutshell

Perl in a Nutshell

Nathan Patwardhan, Ellen Siever, Stephen Spainhour
Learning Perl, 7th Edition

Learning Perl, 7th Edition

Randal L. Schwartz, brian d foy, Tom Phoenix

Publisher Resources

ISBN: 0596002416Errata Page