line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::XML; |
2
|
|
|
|
|
|
|
# @(#) $Id$ |
3
|
|
|
|
|
|
|
|
4
|
5
|
|
|
5
|
|
97885
|
use strict; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
203
|
|
5
|
5
|
|
|
5
|
|
29
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
141
|
|
6
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
28
|
use Carp; |
|
5
|
|
|
|
|
17
|
|
|
5
|
|
|
|
|
443
|
|
8
|
5
|
|
|
5
|
|
26
|
use Test::Builder; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
140
|
|
9
|
5
|
|
|
5
|
|
28543
|
use XML::SemanticDiff; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use XML::Parser; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.08'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
15
|
|
|
|
|
|
|
# Import shenanigans. Copied from Test::Pod... |
16
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub import { |
19
|
|
|
|
|
|
|
my $self = shift; |
20
|
|
|
|
|
|
|
my $caller = caller; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
no strict 'refs'; |
23
|
|
|
|
|
|
|
*{ $caller . '::is_xml' } = \&is_xml; |
24
|
|
|
|
|
|
|
*{ $caller . '::isnt_xml' } = \&isnt_xml; |
25
|
|
|
|
|
|
|
*{ $caller . '::is_well_formed_xml' } = \&is_well_formed_xml; |
26
|
|
|
|
|
|
|
*{ $caller . '::is_good_xml' } = \&is_well_formed_xml; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $Test = Test::Builder->new; |
29
|
|
|
|
|
|
|
$Test->exported_to( $caller ); |
30
|
|
|
|
|
|
|
$Test->plan( @_ ); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
34
|
|
|
|
|
|
|
# Tool. |
35
|
|
|
|
|
|
|
#--------------------------------------------------------------------- |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub is_xml { |
38
|
|
|
|
|
|
|
my ($input, $expected, $test_name) = @_; |
39
|
|
|
|
|
|
|
croak "usage: is_xml(input,expected,test_name)" |
40
|
|
|
|
|
|
|
unless defined $input && defined $expected; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $Test = Test::Builder->new; |
43
|
|
|
|
|
|
|
my $differ = XML::SemanticDiff->new; |
44
|
|
|
|
|
|
|
my @diffs = eval { $differ->compare( $expected, $input ) }; |
45
|
|
|
|
|
|
|
if ( @diffs ) { |
46
|
|
|
|
|
|
|
$Test->ok( 0, $test_name ); |
47
|
|
|
|
|
|
|
$Test->diag( "Found " . scalar(@diffs) . " differences with expected:" ); |
48
|
|
|
|
|
|
|
$Test->diag( " $_->{message}" ) foreach @diffs; |
49
|
|
|
|
|
|
|
$Test->diag( "in processed XML:\n $input" ); |
50
|
|
|
|
|
|
|
return 0; |
51
|
|
|
|
|
|
|
} elsif ( $@ ) { |
52
|
|
|
|
|
|
|
$Test->ok( 0, $test_name ); |
53
|
|
|
|
|
|
|
# Make the output a bit more testable. |
54
|
|
|
|
|
|
|
$@ =~ s/ at \/.*//; |
55
|
|
|
|
|
|
|
$Test->diag( "During compare:$@" ); |
56
|
|
|
|
|
|
|
return 0; |
57
|
|
|
|
|
|
|
} else { |
58
|
|
|
|
|
|
|
$Test->ok( 1, $test_name ); |
59
|
|
|
|
|
|
|
return 1; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub isnt_xml { |
64
|
|
|
|
|
|
|
my ($input, $mustnotbe, $test_name) = @_; |
65
|
|
|
|
|
|
|
croak "usage: isnt_xml(input,mustnotbe,test_name)" |
66
|
|
|
|
|
|
|
unless defined $input && defined $mustnotbe; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $Test = Test::Builder->new; |
69
|
|
|
|
|
|
|
my $differ = XML::SemanticDiff->new; |
70
|
|
|
|
|
|
|
my @diffs = eval { $differ->compare( $mustnotbe, $input ) }; |
71
|
|
|
|
|
|
|
if ( $@ ) { |
72
|
|
|
|
|
|
|
$Test->ok( 0, $test_name ); |
73
|
|
|
|
|
|
|
# Make the output a bit more testable. |
74
|
|
|
|
|
|
|
$@ =~ s/ at \/.*//; |
75
|
|
|
|
|
|
|
$Test->diag( "During compare:$@" ); |
76
|
|
|
|
|
|
|
return 0; |
77
|
|
|
|
|
|
|
} elsif ( @diffs == 0 ) { |
78
|
|
|
|
|
|
|
$Test->ok( 0, $test_name ); |
79
|
|
|
|
|
|
|
$Test->diag( "Found no differences in processed XML:\n $input" ); |
80
|
|
|
|
|
|
|
return 0; |
81
|
|
|
|
|
|
|
} else { |
82
|
|
|
|
|
|
|
$Test->ok( 1, $test_name ); |
83
|
|
|
|
|
|
|
return 1; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub is_well_formed_xml { |
88
|
|
|
|
|
|
|
my ($input, $test_name) = @_; |
89
|
|
|
|
|
|
|
croak "usage: is_well_formed_xml(input,test_name)" |
90
|
|
|
|
|
|
|
unless defined $input; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
my $Test = Test::Builder->new; |
93
|
|
|
|
|
|
|
my $parser = XML::Parser->new; |
94
|
|
|
|
|
|
|
eval { $parser->parse($input) }; |
95
|
|
|
|
|
|
|
if ( $@ ) { |
96
|
|
|
|
|
|
|
$Test->ok( 0, $test_name ); |
97
|
|
|
|
|
|
|
# Make the output a bit more testable. |
98
|
|
|
|
|
|
|
$@ =~ s/ at \/.*//; |
99
|
|
|
|
|
|
|
$Test->diag( "During parse: $@" ); |
100
|
|
|
|
|
|
|
return 0; |
101
|
|
|
|
|
|
|
} else { |
102
|
|
|
|
|
|
|
$Test->ok( 1, $test_name ); |
103
|
|
|
|
|
|
|
return 1; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
__END__ |