File: 75.warnings.t

package info (click to toggle)
libmarc-record-perl 2.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 516 kB
  • ctags: 120
  • sloc: perl: 2,573; makefile: 2
file content (77 lines) | stat: -rw-r--r-- 2,059 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!perl -Tw

use Test::More tests=>21;
use strict;

use File::Spec;

BEGIN {
    use_ok( 'MARC::Batch' );
}

## when strict is on, errors cause next() to return undef

STRICT_ON: {

    my $filename = File::Spec->catfile( 't', 'badldr.usmarc' );
    my $batch = MARC::Batch->new( 'USMARC', $filename );
    isa_ok( $batch, 'MARC::Batch' );

    $batch->warnings_off(); # avoid clutter on STDERR
    $batch->strict_on(); # the default, but might as well test

    my $count = 0;
    while ( my $r = $batch->next() ) {
	isa_ok( $r, "MARC::Record" );
	$count++;
    }
    
    my @warnings = $batch->warnings();
    is( scalar(@warnings), 1, "warnings() w/ strict on" );
    is( $count, 2, "next() w/ strict on" );

}

## when strict is off you can keep on reading past errors

STRICT_OFF: {

    my $filename = File::Spec->catfile( 't', 'badldr.usmarc' );
    my $batch = MARC::Batch->new( 'USMARC', $filename );
    isa_ok( $batch, 'MARC::Batch' );

    $batch->warnings_off(); # avoid clutter on STDERR
    $batch->strict_off(); # turning off default behavior
    
    my $count = 0;
    while ( my $r = $batch->next() ) {
	isa_ok( $r, "MARC::Record" );
	$count++;
    }


    my @warnings = $batch->warnings();
    is( scalar(@warnings), 2, "warnings() w/ strict off" );
    is( $count, 8, "next() w/ strict off" );
}

WARNINGS_BUFFER_RESET: {

    my $filename = File::Spec->catfile( 't', 'badind.usmarc' );
    my $batch = MARC::Batch->new( 'USMARC', $filename );
    $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' );
}