On Wed, Aug 18, 2004 at 12:56:17PM -0500, Bryan Baldus wrote:
> Ok, I'll try to provide a test file. However, since I've been using MacPerl
> (and Windows), I don't usually deal with test files (the usual 
> perl Makefile.PL
>    make
>    make test
>    make install
> doesn't usually work for me, though occasionally I will run the tests
> one-by-one). 

How do you typically do the install? MARC::Record is included at the
ActiveState PPM Repository, so it should do these things on a Windows
platform...assuming nmake or some sort of make variant is being used. 

> So, this .t file, should it just be a raw USMARC/MARC21 format
> record exhibiting one of the problems that generates a warning during the
> decode process (probably not, since you said .t rather than .usmarc), or
> does the .t file need to include calling code, and if so, is the Test module
> tutorial (Test::Tutorial) the best place to look for creating such a .t
> file?

Take a look in the t/ subdirectory of the MARC::Record package. These
are the tests that get run automatically during a 'make test'. There are
lots of resources available for learning how to write perl unit tests
[1,2,3].

After your email this morning I added some tests to expose the bug in 
MARC::Batch::next(). 

    ## create a batch object for a file that contains a record
    ## with a bad indicator.
    my $batch = MARC::Batch->new( 'USMARC', 't/badind.usmarc' );
    $batch->warnings_off();
    $batch->strict_off();
    my $r = $batch->next();

    ## check the warnings on the batch
    my @warnings = $batch->warnings();
    is( @warnings, 1, 'got expected amt of warnings off the batch' );
    like( $warnings[0], qr/^Invalid indicator/, 
        'got expected err msg off the batch' );

    ## same exact warning should be available on the record 
    @warnings = $r->warnings();
    is( @warnings, 1, 'got expected amt of warnings off the record' );
    like( $warnings[0], qr/^Invalid indicator/, 
        'got expected err msg off the record' );

Basically just read in a record with some messed up indicators, and made
sure that it could get the warning from the batch object AND the record
object. Sure enough it failed, and after I applied my change it worked
fine. Then I ran the entire test suite and it ran fine as well. Having a
test suite like this lets you make changes without losing too much sleep
worrying about the rippling effects of changes.

//Ed

[1] http://www.wgz.com/chromatic/perl/IntroTestMore.pdf 
[2] http://magnonel.guild.net/~schwern/talks/Test_Tutorial/Test-Tutorial.pdf
[3] http://www.petdance.com/perl/automated-testing/ 

Reply via email to