File: 24_ignore_error.t

package info (click to toggle)
libxml-treepp-perl 0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 680 kB
  • sloc: perl: 810; xml: 58; sh: 41; makefile: 2
file content (37 lines) | stat: -rwxr-xr-x 810 bytes parent folder | download | duplicates (4)
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
    use strict;
    use Test::More tests => 7;
    BEGIN { use_ok('XML::TreePP') };

    &no_carp( \&invalid_tag, qr{Invalid tag sequence}i );
    &no_carp( \&no_such_file, qr{file-not-found}i );
    &no_carp( \&invalid_tree, qr{Invalid tree}i );

sub no_carp {
    my $sub = shift;
    my $err = shift;
    local $@;
    &$sub( ignore_error => 1 );
    ok( ! $@, 'ignore error' );
    eval {
        &$sub();
    };
    like( $@, $err, 'raise error' );
}

sub invalid_tag {
    my $tpp = XML::TreePP->new( @_ );
    my $xml = '<root><not_closed></invalid></root>';
    return $tpp->parse( $xml );
}

sub no_such_file {
    my $tpp = XML::TreePP->new( @_ );
    return $tpp->parsefile( 'file-not-found-'.$$ );
}

sub invalid_tree {
    my $tpp = XML::TreePP->new( @_ );
    return $tpp->write( undef );
}

;1;