Skip to Content
Programming Perl, 4th Edition
book

Programming Perl, 4th Edition

by Tom Christiansen, brian d foy, Larry Wall, Jon Orwant
February 2012
Intermediate to advanced
1184 pages
37h 17m
English
O'Reilly Media, Inc.
Content preview from Programming Perl, 4th Edition

Testing Your Modules

Perl’s testing culture is one of its most compelling features. We’ve already told you about CPAN Testers, the people who test all CPAN distributions on a variety of platforms. As an author, it’s up to you to create your own tests. We’re not going to tell you everything involved with that, because it’s already extensively covered in other titles such as Intermediate Perl and Perl Testing: A Developer’s Notebook.

Internal testing

If you are using either of the two standard distribution build tools, you already have a test harness in place. You run the test target:

% make test

% ./Build test

Those both do the same thing: they look for either a test.pl file or a t/ directory. Using a test.pl file is the old way, in which just one file holds all tests. Using a t/ subdirectory is a better approach because it can hold multiple test files, each one ending with .t, and the test harness runs all of the subtests.

Each test file is just a Perl program, most likely using Test::More to do the work. Here’s an example test file that loads your Math::MySum module and tests its my_sum method:

use strict;
use warnings;
use Test::More;

BEGIN { use_ok( "Math::MySum" ) }
can_ok( "Math::MySum", "my_sum" );

my($i, $j) = (1, 3);
my $string = "Amelia";

is($i + $j, Math::MySum–>my_sum( $i, $j ),
    "Sum of $i and $j is 4");

like($string, qr/mel/, "String has mel in it");

done_testing;

These programs output TAP (Test Anywhere Protocol), a simple format that Larry invented and others extended.[

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.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Programming Perl, 3rd Edition

Programming Perl, 3rd Edition

Larry Wall, Tom Christiansen, Jon Orwant
Perl Cookbook, 2nd Edition

Perl Cookbook, 2nd Edition

Tom Christiansen, Nathan Torkington

Publisher Resources

ISBN: 9781449321451Errata Page