Permalink
Browse files

Add test for rt#50077

Test case submitted by Knut Arne Bjørndal <bob@cakebox.net> and modified by me to be an actual test

Issue was fixed in v1.03.
  • Loading branch information...
ashb committed Apr 22, 2011
1 parent e323cfd commit 91e4923e1ea0327afd037389f35979314807d06f
Showing with 48 additions and 0 deletions.
  1. +48 −0 t/xml_sax_expat.t
View
@@ -0,0 +1,48 @@
+use strict;
+use warnings;
+use Test::More;
+
+use TryCatch;
+
+
+try {
+ require XML::SAX::Expat;
+}
+catch ($e where { qr{Can't load XML/SAX/Expat} } ) {
+ plan skip_all => 'This test requires XML::SAX::Expat';
+}
+
+# Use an explict plan since the problem was that it didn't behave and catch properly.
+plan tests => 5;
+
+my $parser = XML::SAX::Expat->new(
+ Handler => MyHandler->new(),
+);
+
+$parser->parse_string(<<EOF);
+<foo>
+ <bar id="1">
+ </bar>
+ <bar id="2">
+ </bar>
+ <bar id="3">
+ </bar>
+ <bar id="4">
+ </bar>
+</foo>
+EOF
+
+print "Completed successfully\n";
+
+package MyHandler;
+use base qw(XML::SAX::Base);
+use TryCatch;
+use Test::More;
+
+sub end_element {
+ try {
+ die "error message";
+ } catch( $e where { $_ =~ /message/ } ){
+ ok "caught message\n";
+ }
+}

0 comments on commit 91e4923

Please sign in to comment.