Skip to Main Content
Perl Hacks
book

Perl Hacks

by Chromatic, Damian Conway, Curtis Ovid Poe, Curtis (Ovid) Poe
May 2006
Beginner content levelBeginner
298 pages
6h 51m
English
O'Reilly Media, Inc.
Content preview from Perl Hacks

Hack #64. See Test Failure Diagnostics — in Color!

Highlight the unexpected.

If you follow good development practices and write comprehensive unit tests for your programs, you'll be able to develop faster and more reliably. You'll also eventually run into the problem of too many successes hiding the failures—that is, if you keep your tests always succeeding, you only need to know about the tests that fail.

Why not make them stand out?

Perl's standard testing harness, Test::Harness is actually a nice wrapper around Test::Harness::Straps, which is a parser for the TAP format that standard tests follow. If and when the report that Test::Harness writes isn't sufficient, use Test::Harness::Straps to write your own.

The Hack

There are two barriers to this approach. First, the default behavior of Perl's standard testing tools is to write diagnostic output to STDERR. Test::Harness doesn't capture this. Second, Test::Harness goes to a bit of trouble to set up the appropriate command line paths to run tests appropriately.

The first problem is tractable, at least if you can use a module such as IPC::Open3 to capture STDERR and STDOUT. The second problem is a little trickier. The current version of Test::Harness::Straps, which ships with Test::Harness 2.48, doesn't quite provide everything publicly that you need to run tests well. Hopefully a future version will correct this, but for now, the hack is to use a private method, _command_line( ), to generate the appropriate command for running the ...

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 Testing: A Developer's Notebook

Perl Testing: A Developer's Notebook

Ian Langworth, Chromatic
Perl 6 Deep Dive

Perl 6 Deep Dive

Andrew Shitov
Advanced Perl Programming

Advanced Perl Programming

Sriram Srinivasan
Perl Debugged

Perl Debugged

Peter Scott, Ed Wright

Publisher Resources

ISBN: 0596526741Supplemental ContentErrata Page