A.17. Answers for Chapter 18A.17.1. Exercise 1Since you're starting with your distribution from the last chapter, we don't have much code to show you. To add a POD test, create a t/pod.t file (or whatever you want to call it). In there, put the code you lift for Test::Pod : use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok( );
This code is clever: it only runs tests if the
If you are
Depending on which module creation tool you used, you might already have these files, too. A.17.2. Exercise 2
You could create a new distribution for your test module, but you don't have to. You can include it with the distribution that you already made. You just have to put the module file in the right place and ensure that
Makefile.PL
or
Build.PL
We'll just show you the code, though. This is a long way to go to test $n = = $m , but we wanted to make it as uncomplicated as possible so you could focus on the Test::Builder part. You can lift most of the code directly from the example in the chapter and then write the sum_ok function.
package Test::My::List::Util;
use strict;
use base qw(Exporter);
use vars qw(@EXPORT $VERSION);
use Exporter;
use Test::Builder;
my $Test = Test::Builder->new( );
$VERSION = '0.10';
@EXPORT = qw(sum_ok);
sub sum_ok {
my( $actual, $expected ) = @_;
if( $actual = = $expected ) {
$Test->ok( 1 )
}
else {
$Test->diag(
"The sum is not right\n",
"\tGot: $actual\n",
"\tExpected: $expected\n"
);
$Test->ok( 0 )
}
}
1;
|
A.18. Answer for Chapter 19A.18.1. Exercise
Were you able to solve the halting problem? We didn't really expect you to solve this problem since, in 1936, Alan Turing proved you couldn't create a general solution. You can read about the
There's not much we can show you as an answer to an exercise about distributions. You know about testing now, so as long as your tests pass, you know you're doing the right thing (or the tests don't work!). We're kicking you out into the real world now. We don't have anything left to tell you in this book. Go back and read the footnotes now. Good luck! |
|
About the Author
Randal L. Schwartz
is a renowned expert on the Perl programming language. In addition to writing
Learning Perl
and the first two editions of
Programming Perl
, he has been the Perl columnist for
UNIX Review
,
Web Techniques
,
Sys Admin
, and
Linux Magazine
. He has
brian d foy
has been an instructor for Stonehenge Consulting Services since 1998. He founded the first Perl user
Tom Phoenix
has been working in the field of education since 1982. After more than 13
|