Shlomi Fish avatar Shlomi Fish committed fc3d465

Convert t/03input.t to Test::More.

Comments (0)

Files changed (2)

 Revision history for Perl extension XML::LibXSLT.
 
+    - Convert the following test scripts from Test.pm to Test::More :
+        - t/03input.t
+
 1.74            Tue Oct 25 21:48:48 IST 2011
     - Convert the following test scripts from Test.pm to Test::More :
         - t/01basic.t
-use Test;
-BEGIN { plan tests => 25 }
+use strict;
+use warnings;
+
+# Should be 25.
+use Test::More tests => 25;
 use XML::LibXSLT;
 use XML::LibXML 1.59;
 
 my $parser = XML::LibXML->new();
-print "# parser\n";
-ok($parser);
+# parser
+# TEST
+ok ($parser, 'Parser was initted.');
 
 my $doc = $parser->parse_string(<<'EOT');
 <xml>random contents</xml>
 EOT
 
-print "# doc\n";
-ok($doc);
+# doc
+# TEST
+ok ($doc, 'Doc was initted.');
 
 my $xslt = XML::LibXSLT->new();
-print "# xslt\n";
-ok($xslt);
+# xslt
+# TEST
+ok ($xslt, 'xslt was initted.');
 
 my $stylsheetstring = <<'EOT';
 <xsl:stylesheet version="1.0"
 EOT
 
 my $icb = XML::LibXML::InputCallback->new();
-ok($icb);
+# TEST
+ok ($icb, 'icb was initted.');
 
-print "# registering callbacks\n";
+# registering callbacks
 $icb->register_callbacks( [ \&match_cb, \&open_cb,
                             \&read_cb, \&close_cb ] );
 
 $xslt->input_callbacks($icb);
                 
 my $stylesheet = $xslt->parse_stylesheet($parser->parse_string($stylsheetstring));
-print "# stylesheet\n";
-ok($stylesheet);
+# stylesheet
+# TEST
+ok ($stylesheet, 'stylesheet is OK.');
 
 #$stylesheet->input_callbacks($icb);
 
 # warn "transforming\n";
 my $results = $stylesheet->transform($doc);
-print "# results\n";
-ok($results);
+# results
+# TEST
+ok ($results, 'results is OK.');
 
 my $output = $stylesheet->output_string($results);
 # warn "output: $output\n";
-print "# output\n";
-ok($output);
+# TEST
+ok ($output, 'output is OK.');
 
 # test a dying close callback
 # callbacks can only be registered as a callback group
 $stylesheet->close_callback( \&close_cb );
 
 # check if transform throws an exception
-print "# dying callback test\n";
+# dying callback test
 eval {
     $stylesheet->transform($doc);
 };
-if ($@) {
-    ok(1, 1, "Threw: $@");
-}
-else {
-    ok(0, 1, "No error");
+{
+    my $E = $@;
+    # TEST
+    ok ($E, "Threw: $E");
 }
 
 #
 $xslt = XML::LibXSLT->new();
 $stylesheet = $xslt->parse_stylesheet($parser->parse_string($stylsheetstring));
 
-print "# setting callbacks\n";
+# setting callbacks
 local $XML::LibXML::match_cb = \&match_cb;
 local $XML::LibXML::open_cb = \&open_cb;
 local $XML::LibXML::close_cb = \&close_cb;
 # warn "transform!\n";
 $results = $stylesheet->transform($doc);
 
-print "# results\n";
-ok($results);
+# results
+# TEST
+ok ($results, 'results is OK - 2.');
 
 $output = $stylesheet->output_string($results);
 
 # warn "output: $output\n";
-print "# output\n";
-ok($output);
+# output
+# TEST
+ok ($output, 'output is OK - 2.');
 
 $XML::LibXML::open_cb = \&dying_open_cb;
 
 eval {
     $stylesheet->transform($doc);
 };
-if ($@) {
-    ok(1, 1, "Threw: $@");
-}
-else {
-    ok(0, 1, "No error");
+{
+    my $E = $@;
+    # TEST
+    ok ($E, "Transform Threw: $E");
 }
 
 #
 $xslt = XML::LibXSLT->new();
 $icb = XML::LibXML::InputCallback->new();
 
-print "# registering callbacks\n";
+# registering callbacks
 $icb->register_callbacks( [ \&match_cb, \&stylesheet_open_cb,
                             \&read_cb, \&close_cb ] );
 
 EOT
 
 $stylesheet = $xslt->parse_stylesheet($parser->parse_string($stylsheetstring));
-print "# stylesheet\n";
-ok($stylesheet);
+# stylesheet
+# TEST
+ok ($stylesheet, 'stylesheet is OK - 2.');
 
 #
 # input callback functions
 
 sub match_cb {
     my $uri = shift;
-    print "# match_cb: $uri\n";
+    # match_cb
     if ($uri eq "foo.xml") {
-        ok(1);
+        # TEST*5
+        ok(1, 'URI is OK in match_cb.');
         return 1;
     }
     return 0;
 
 sub open_cb {
     my $uri = shift;
-    print "# open_cb: $uri\n";
-    ok($uri, "foo.xml");
+    # TEST*2
+    is ($uri, 'foo.xml', 'URI is OK in open_cb.');
     my $str ="<foo>Text here</foo>";
     return \$str;
 }
 
 sub dying_open_cb {
     my $uri = shift;
-    print "# dying_open_cb: $uri\n";
-    ok($uri, "foo.xml");
+    # dying_open_cb: $uri
+    # TEST*2
+    is ($uri, 'foo.xml', 'dying_open_cb');
     die "Test a die from open_cb";
 }
 
 sub stylesheet_open_cb {
     my $uri = shift;
-    print "# open_cb: $uri\n";
-    ok($uri, "foo.xml");
+    # TEST
+    is ($uri, 'foo.xml', 'stylesheet_open_cb uri compare.');
     my $str = '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>';
     return \$str;
 }
 
 sub close_cb {
-    print "# close_cb\n";
     # warn("close\n");
-    ok(1);
+    # TEST*3
+    ok(1, 'close_cb()');
 }
 
 sub read_cb {
-    print "# read_cb\n";
 #    warn("read\n");
     return substr(${$_[0]}, 0, $_[1], "");
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.