File: 43exc-xml-libxml.t

package info (click to toggle)
liblog-report-perl 1.40-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 568 kB
  • sloc: perl: 2,905; makefile: 8
file content (48 lines) | stat: -rw-r--r-- 1,153 bytes parent folder | download
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
#!/usr/bin/env perl
# Convert XML::LibXML exceptions into report

use warnings;
use strict;

use Log::Report;
use Log::Report::Die 'exception_decode';
use Test::More;

#use Data::Dumper;

BEGIN {
    eval 'require XML::LibXML::Error';
    plan skip_all => 'XML::LibXML::Error not available' if $@;

    eval 'require XML::LibXML';
    plan skip_all => 'Your installation of XML::LibXML is broken' if $@;
}

# The XML::LibXML::Error object does not have a constructor, so we
# need to trigger one.
my $xml = eval { XML::LibXML->load_xml(string => \'<bad-xml>') };
ok ! defined $xml, 'parse broken xml';
my $error = $@;
isa_ok $error, 'XML::LibXML::Error';

#warn Dumper exception_decode($error);
my @dec = exception_decode($error);
my $msg = pop @dec;

# error code changed from libxml2 2.9.9 to 2.9.10
my $rc = delete $dec[0]{errno};
$dec[0]{errno} = 'RC';
cmp_ok $rc, '>', 13000, 'error code';

is_deeply \@dec,
  , [ { location => [ 'libxml', '', '1', 'parser' ], errno => 'RC' }
    , 'ERROR'
    ], 'error 1';

# the message may vary over libxml2 versions
$msg =~ s/\r?\n\s*/ /g;
like $msg, qr/bad\-xml|Start tag expected/, $msg;

done_testing;

1;