Skip to Content
Intermediate Perl
book

Intermediate Perl

by Randal L. Schwartz, brian d foy, Tom Phoenix
March 2006
Intermediate to advanced
278 pages
6h 49m
English
O'Reilly Media, Inc.
Content preview from Intermediate Perl

Chapter 18. Advanced Testing

The Test::More module provides some simple and general functions, but other Test::* modules provide more specific tests for particular problem domains so that we don’t have to write much code to do what we need. If we use it once, we’ll probably use it again, anyway.

In this chapter, we give you a taste of some of the more popular test modules. Unless we say otherwise, these modules are not part of the Perl standard distribution (unlike Test::More) and you’ll need to install them yourself. You might feel a bit cheated by this chapter since we’re going to say “See the module documentation” quite a bit, but we’re gently nudging you out into the Perl world. For much more detail, you can also check out Perl Testing: A Developer’s Notebook, which covers the subject further.

Testing Large Strings

We showed in Chapter 17 that when a test fails, Test::More can show us what we expected and what we actually got.

#!/usr/bin/perl
use Test::More 'no_plan';
is( "Hello Perl", "Hello perl" );

When I run this program, Test::More shows me what went wrong.

$ perl test.pl
not ok 1
#     Failed test (test.pl at line 5)
#          got: 'Hello Perl'
#     expected: 'Hello perl'
1..1
# Looks like you failed 1 test of 1.

What if that string is really long? We don’t want to see the whole string, which might be hundreds or thousands of characters long. We just want to see where they start to be different.

#!/usr/bin/perl use Test::More 'no_plan'; use Test::LongString; is_string( "The quick brown fox ...
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

Perl Debugged

Perl Debugged

Peter Scott, Ed Wright
Higher-Order Perl

Higher-Order Perl

Mark Jason Dominus
Learning Perl 6

Learning Perl 6

brian d foy
Perl & LWP

Perl & LWP

Sean M. Burke

Publisher Resources

ISBN: 0596102062Errata Page