lib/XML/Schema/Test.pm

filter: Statementstmt 86.9% 40 / 46 Branchbran 75.0% 12 / 16 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 10 / 10 Podpod 60.0% 3 / 5 totaltotal 81.2% 65 / 80 CC 10 SCAR 11.1
CC
10
Cov
81%
assert
6.5
ok
4.0
match
3.1
CRAP 3.0
« lib/XML/Schema/Handler/Simple.pm ↑ Summary lib/XML/Schema/Type/Union.pm »
1 #============================================================= -*-perl-*-
2 #
3 # XML::Schema::Test
4 #
5 # DESCRIPTION
6 # Module for testing XML::Schema modules.
7 #
8 # AUTHOR
9 # Andy Wardley <abw@kfs.org>
10 #
11 # COPYRIGHT
12 # Copyright (C) 2001 Canon Research Centre Europe Ltd.
13 # All Rights Reserved.
14 #
15 # This module is free software; you can redistribute it and/or
16 # modify it under the same terms as Perl itself.
17 #
18 # REVISION
19 # $Id: Test.pm,v 1.1.1.1 2001/08/29 14:30:17 abw Exp $
20 #
21 #========================================================================
22  
23 package XML::Schema::Test;
24  
25 28 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 28 ▶use XML::Schema;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 28 ▶use base qw( Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
28 28 ▶use vars qw( $VERSION $DEBUG $ERROR @EXPORT );
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 28 $VERSION = sprintf("%d.%02d", q$Revision: 1.1.1.1 $ =~ /(\d+)\.(\d+)/);
31 28 ▶$DEBUG = 0 unless defined $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $XML::Schema::Test::DEBUG 28 0 28
32 28 $ERROR = '';
33  
34 28 @EXPORT = qw( ntests ok match assert );
35  
36 28 my $ok_count;
37 my @results;
38  
39 28 ▶sub ntests {
Subroutine ntests: called CC=2 SCAR=6.9
Pod documented
40 28 my $ntests = shift;
41 # add the number of any cached results to $ntests
42 28 $ntests += scalar @results;
43 28 $ok_count = 1;
44 28 print "1..$ntests\n";
45 # flush cached results
46 28 foreach (@results) { ok(@$_) };
47 }
48  
49 2374 ▶sub ok {
Subroutine ok: called CC=4 SCAR=13.9
Pod documented
50 2374 my ($ok, $msg) = @_;
51  
52 # cache results if ntests() not yet called
53 2374 ▶ unless ($ok_count) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok_count) 933 1441 2374
54 933 push(@results, [ $ok, $msg ]);
55 933 return $ok;
56 }
57  
58 1441 ▶ if ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) { } 1440 1 1441
59 1440 print "ok ", $ok_count++, "\n";
60 }
61 else {
62 1 ▶ print "FAILED $ok_count: $msg\n" if defined $msg;
Branch: 1 branch
BranchTrueFalseTotal
if defined $msg 1 0 1
63 1 print "not ok ", $ok_count++, "\n";
64 }
65 }
66  
67 22 ▶sub assert {
Subroutine assert: called CC=3 SCAR=18.7
Pod undocumented
68 22 my ($ok, $err) = @_;
69 22 ▶ return ok(1) if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 22 0 22
70  
71 # failed
72 0 my ($pkg, $file, $line) = caller();
73 0 ▶ $err ||= "assert failed";
Condition0%0/2
$err ||= "assert failed"
l!l
00
MC/DC0%0/1
$err ||= "assert failed"
$err
Truth table0%0/2
A
A= $err
Aresult
11
00
74 0 $err .= " at $file line $line\n";
75 0 ok(0);
76 0 die $err;
77 }
78  
79
80 669 ▶sub match {
Subroutine match: called CC=3 SCAR=11.3
Pod documented
81 669 my ($result, $expect) = @_;
82  
83 # force stringification of $result to avoid 'no eq method' overload errors
84 669 ▶ $result = "$result" if ref $result;
Branch: 1 branch
BranchTrueFalseTotal
if ref $result 15 654 669
85  
86 669 ▶ if ($result eq $expect) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result eq $expect) { } 669 0 669
87 669 ok(1);
88 }
89 else {
90 0 ok(0, "match failed:\n expect: [$expect]\n result: [$result]\n");
91 }
92 }
93  
94 28 ▶sub flush {
Subroutine flush: called CC=2 SCAR=6.9
Pod undocumented
95 28 ▶ ntests(0) unless $ok_count;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok_count 20 8 28
96 }
97  
98 28 ▶sub END {
Subroutine END: called CC=1 SCAR=0.0
99 28 flush(); # ensure any cached results get flushed
100 }
101  
102  
103 28 1;
104  
105 __END__
« lib/XML/Schema/Handler/Simple.pm ↑ Summary lib/XML/Schema/Type/Union.pm »