summaryrefslogtreecommitdiff
path: root/t/60struct_error.t
blob: 1b156d30620070b2ca12c30549e468e0a3f90ec5 (plain)
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
# $Id: 29_struct_errors.t,v 1.1.2.2 2006/06/22 14:34:47 pajas Exp $
# First version of the new structured error test suite

use strict;
use warnings;

use Test::More;
use XML::LibXML;

if (! XML::LibXML::HAVE_STRUCT_ERRORS() )
{
    plan skip_all => 'Does not have struct errors - skipping';
}
else
{
    plan tests => 7;
}

use XML::LibXML::Error;
use XML::LibXML::ErrNo;

{
    my $p = XML::LibXML->new();
    my $xmlstr = '<X></Y>';

    eval {
        my $doc = $p->parse_string( $xmlstr );
    };
    my $err = $@;
    # TEST
    ok (defined($err), 'Error is defined.');
    # TEST
    isa_ok ($err, "XML::LibXML::Error", '$err is an XML::LibXML::Error');
    # TEST
    is ($err->domain(), "parser", 'domain');
    # TEST
    is ($err->line(), 1, 'line');
    # TEST
    ok ($err->code == XML::LibXML::ErrNo::ERR_TAG_NAME_MISMATCH, ' TODO : Add test name');

    my $fake_err = XML::LibXML::Error->new('fake error');
    my $domain_num = @XML::LibXML::Error::error_domains;      # too big
    $fake_err->{domain} = $domain_num;                        # white-box test
    # TEST
    is($fake_err->domain, "domain_$domain_num",
        '$err->domain is reasonable on unknown domain');
    {
        my $warnings = 0;
        local $SIG{__WARN__} = sub { $warnings++; warn "@_\n" };
        my $s = $fake_err->as_string;
        # TEST
        is($warnings, 0,
            'No warnings when stringifying unknown-domain error',
        );
    }
}