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.
Start your free trial

You might also like

Perl Debugged

Perl Debugged

Peter Scott, Ed Wright
Think Perl 6

Think Perl 6

Laurent Rosenfeld, Allen B. Downey
Beginning Perl

Beginning Perl

Curtis Ovid Poe
Pro Perl

Pro Perl

Peter Wainwright

Publisher Resources

ISBN: 0596102062Supplemental ContentErrata Page