Документация
HTML CSS PHP PERL другое

Section A.17.  Answers for Chapter 18

 
Previous
Table of Contents
Next

A.17. Answers for Chapter 18

A.17.1. Exercise 1

Since 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 user has installed Test::Pod, and doesn't cause any problems if she hasn't.

If you are especially motivated, you can do the same thing with Test::Pod::Coverage. Create a t/pod_coverage.t file and lift the code directly from the module documentation.

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 knows about it.

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;


Previous
Table of Contents
Next
© 2000- NIV