File Coverage

lib/XML/Schema/Test.pm
Criterion Covered Total %
statement 34 40 85.0
branch 11 14 78.5
condition 0 2 0.0
subroutine 10 10 100.0
pod 3 5 60.0
total 58 71 81.6


line stmt bran cond sub pod time code
1             #============================================================= -*-perl-*-
2             #
3             # XML::Schema::Test
4             #
5             # DESCRIPTION
6             # Module for testing XML::Schema modules.
7             #
8             # AUTHOR
9             # Andy Wardley
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     28   75646 use strict;
  28         64  
  28         1196  
26 28     28   12284 use XML::Schema;
  28         79  
  28         938  
27 28     28   164 use base qw( Exporter );
  28         52  
  28         2078  
28 28     28   142 use vars qw( $VERSION $DEBUG $ERROR @EXPORT );
  28         53  
  28         16370  
29              
30             $VERSION = sprintf("%d.%02d", q$Revision: 1.1.1.1 $ =~ /(\d+)\.(\d+)/);
31             $DEBUG = 0 unless defined $DEBUG;
32             $ERROR = '';
33              
34             @EXPORT = qw( ntests ok match assert );
35              
36             my $ok_count;
37             my @results;
38              
39             sub ntests {
40 28     28 1 153 my $ntests = shift;
41             # add the number of any cached results to $ntests
42 28         90 $ntests += scalar @results;
43 28         70 $ok_count = 1;
44 28         543 print "1..$ntests\n";
45             # flush cached results
46 28         98 foreach (@results) { ok(@$_) };
  933         1748  
47             }
48              
49             sub ok {
50 2374     2374 1 3951 my ($ok, $msg) = @_;
51              
52             # cache results if ntests() not yet called
53 2374 100       4433 unless ($ok_count) {
54 933         2335 push(@results, [ $ok, $msg ]);
55 933         4213 return $ok;
56             }
57              
58 1441 100       2221 if ($ok) {
59 1440         5860 print "ok ", $ok_count++, "\n";
60             }
61             else {
62 1 50       7 print "FAILED $ok_count: $msg\n" if defined $msg;
63 1         0 print "not ok ", $ok_count++, "\n";
64             }
65             }
66              
67             sub assert {
68 22     22 0 50 my ($ok, $err) = @_;
69 22 50       78 return ok(1) if $ok;
70              
71             # failed
72 0         0 my ($pkg, $file, $line) = caller();
73 0   0     0 $err ||= "assert failed";
74 0         0 $err .= " at $file line $line\n";
75 0         0 ok(0);
76 0         0 die $err;
77             }
78              
79            
80             sub match {
81 669     669 1 1415 my ($result, $expect) = @_;
82              
83             # force stringification of $result to avoid 'no eq method' overload errors
84 669 100       1313 $result = "$result" if ref $result;
85              
86 669 50       1396 if ($result eq $expect) {
87 669         1131 ok(1);
88             }
89             else {
90 0         0 ok(0, "match failed:\n expect: [$expect]\n result: [$result]\n");
91             }
92             }
93              
94             sub flush {
95 28 100   28 0 162 ntests(0) unless $ok_count;
96             }
97              
98             sub END {
99 28     28   137 flush(); # ensure any cached results get flushed
100             }
101              
102              
103             1;
104              
105             __END__