Commits

Shlomi Fish committed ac3cb6f

Convert t/90threads.t to Test::More.

Comments (0)

Files changed (1)

 use lib './t/lib';
 use TestHelpers;
 
-use Test;
+use Test::More;
 use Config;
 use constant MAX_THREADS => 10;
 use constant MAX_LOOP => 50;
-use constant PLAN => 24;
-BEGIN {
-  plan tests => PLAN;
-  if( $Config{useithreads} ) {
-    if ($ENV{THREAD_TEST}) {
-      require threads;
-      require threads::shared;
-    } else {
-      skip("optional (set THREAD_TEST=1 to run these tests)\n") for (1..PLAN);
-      exit;
+# use constant PLAN => 24;
+BEGIN
+{
+    my $will_run = 0;
+    if ( $Config{useithreads} )
+    {
+        if ($ENV{THREAD_TEST})
+        {
+            require threads;
+            require threads::shared;
+            $will_run = 1;
+        }
+        else
+        {
+            plan skip_all => "optional (set THREAD_TEST=1 to run these tests)";
+        }
     }
-  } else {
-    skip("no ithreads in this Perl\n") for (1..PLAN);
-    exit;
-  }
+    else
+    {
+        plan skip_all => "no ithreads in this Perl";
+    }
+
+    if ($will_run)
+    {
+        plan tests => 24;
+    }
 }
+
 use XML::LibXML qw(:threads_shared);
-ok(1);
+# TEST
+ok(1, 'Loaded');
 
 my $p = XML::LibXML->new();
-ok($p);
+# TEST
+ok($p, 'Parser initted.');
 
-
-
-print "Simple spawn threads with a parser in scope\n";
 {
 for(1..MAX_THREADS)
 {
 	threads->new(sub {});
 }
 $_->join for(threads->list);
-ok(1);
+# TEST
+ok(1,  "Simple spawn threads with a parser in scope");
 }
 
-print "RelaxNG\n";
 {
   my $grammar = <<'EOF';
 <grammar xmlns="http://relaxng.org/ns/structure/1.0">
       threads->new(sub { XML::LibXML::RelaxNG->new(string=>$grammar) });
     }
   $_->join for(threads->list);
-  ok(1);
+  # TEST
+  ok(1, "RelaxNG");
 }
 
-print "XML error\n";
 {
-eval { XML::LibXML->new->parse_string('foo') };
-for(1..40) {
-	threads->new(sub { eval { XML::LibXML->new->parse_string('foo') } for(1..1000);  1; });
-}
-$_->join for(threads->list);
-ok(1);
+    eval { XML::LibXML->new->parse_string('foo') };
+    for(1..40) {
+        threads->new(sub { eval { XML::LibXML->new->parse_string('foo') } for(1..1000);  1; });
+    }
+    $_->join for(threads->list);
+    # TEST
+    ok(1, "XML error\n");
 }
 
 
-print "accessing document elements without lock\n";
 {
   my $doc=XML::LibXML::Document->new;
   $doc->setDocumentElement($doc->createElement('root'));
   }
   $_->join for(threads->list);
 }
-ok(1);
-print "operating on different documents without lock\n";
+# TEST
+ok(1, "accessing document elements without lock");
 {
   my @docs=map {
     my $doc = XML::LibXML::Document->new;
   }
   $_->join for(threads->list);
 }
-ok(1);
-print "operating on the same document with a lock\n";
+# TEST
+ok(1, "operating on different documents without lock\n");
+
+# operating on the same document with a lock
 {
   my $lock : shared;
   my $doc=XML::LibXML::Document->new;
 <root><node><leaf/></node></root>
 EOF
 
-print "Spawn threads with a document in scope\n";
 {
 my $doc = $p->parse_string( $xml );
 for(1..MAX_THREADS)
 }
 $_->join for(threads->list);
 }
-ok(1);
+# TEST
+ok(1, "Spawn threads with a document in scope");
 
-print "Spawn threads that use document that has gone out of scope from where it was created\n";
+
 {
 my $waitfor : shared;
 {
 }
 }
 $_->join for(threads->list);
-ok(1);
+# TEST
+ok(1, "Spawn threads that use document that has gone out of scope from where it was created");
 }
 
-print "Parse a correct XML document\n";
 {
 for(1..MAX_THREADS)
 {
 	threads->new(sub { $p->parse_string($xml) for 1..MAX_LOOP; 1; });
 }
 $_->join for(threads->list);
-ok(1);
+# TEST
+ok(1, "Parse a correct XML document");
 }
 
 my $xml_bad = <<EOF;
 EOF
 
 
-print "Parse a bad XML document\n";
 {
 for(1..MAX_THREADS)
 {
 	threads->new(sub { eval { my $x = $p->parse_string($xml_bad)} for(1..MAX_LOOP); 1; });
 }
 $_->join for(threads->list);
-ok(1);
+# TEST
+ok(1, "Parse a bad XML document\n");
 }
 
 
 <root><something/></root>
 EOF
 
-print "Parse an invalid XML document\n";
 {
 for(1..MAX_THREADS)
 {
 	       });
 }
 $_->join for(threads->list);
-ok(1);
+# TEST
+ok(1, "Parse an invalid XML document");
 }
 
 my $rngschema = <<EOF;
 </r:grammar>
 EOF
 
-print "test RNG validation errors are thread safe\n";
 {
 for(1..MAX_THREADS)
 {
     });
 }
 $_->join for(threads->list);
-ok(1);
+# TEST
+ok(1, "test RNG validation errors are thread safe");
 }
 
 my $xsdschema = <<EOF;
 </xsd:schema>
 EOF
 
-print "test Schema validation errors are thread safe\n";
 {
 for(1..MAX_THREADS)
 {
     });
 }
 $_->join for(threads->list);
-ok(1);
+# TEST
+ok(1, "test Schema validation errors are thread safe");
 }
 
 my $bigfile = "docs/libxml.dbk";
 $xml = utf8_slurp($bigfile);
-ok($xml);
+# TEST
+ok($xml, 'bigfile was slurped fine.');
 sub use_dom
 {
 	my $d = shift;
 	threads->new(sub { my $dom = do { $p->parse_string($xml); }; use_dom($dom) for 1..5; 1; });
 }
 $_->join for(threads->list);
-ok(1);
+# TEST
+ok(1, 'Joined all threads.');
 }
 
 {
 package MyHandler;
 
-use base XML::SAX::Base;
+use base 'XML::SAX::Base';
 
 sub AUTOLOAD
 {
 $p = XML::LibXML::SAX->new(
 	Handler=>MyHandler->new(),
 );
-ok($p);
+# TEST
+ok($p, 'XML::LibXML::SAX was initted.');
 
 {
 for(1..MAX_THREADS)
 }
 $_->join for threads->list;
 
-ok(1);
+# TEST
+ok(1, 'After XML::LibXML::SAX - join.');
 }
 
 $p = XML::LibXML->new(
 });
 }
 $_->join for(threads->list);
-ok(1);
+# TEST
+ok(1, 'XML::LibXML thread.');
 }
 
 $p = XML::LibXML->new();
-print "parse a big file using the same parser\n";
+# parse a big file using the same parser
 {
 for(1..MAX_THREADS)
 {
 });
 }
 my @results = $_->join for(threads->list);
-print@results,"\n";
-ok(1);
+# TEST
+ok(1, 'threads->join after opening bigfile.');
 }
 
-print "create elements\n";
+# create elements
 {
 my @n = map XML::LibXML::Element->new('bar'.$_), 1..1000;
 for(1..MAX_THREADS)
 });
 }
 $_->join for(threads->list);
-ok(1);
+# TEST
+ok(1, 'create elements');
 }
 
 {
-print "docfrag\n";
 my $e = XML::LibXML::Element->new('foo');
 for(1..MAX_THREADS) {
   threads->new(sub {
 	       },$_);
 }
 $_->join for(threads->list);
-ok(1);
-print $e->ownerDocument->toString(),"\n";
+# TEST
+ok(1, "docfrag");
 }
 
 {
-print "docfrag2\n";
 my $e = XML::LibXML::Element->new('foo');
 my $d = XML::LibXML::Document->new();
 $d->setDocumentElement($d->createElement('root'));
 	       },$_);
 }
 $_->join for(threads->list);
-ok(1);
-print $e->ownerDocument->toString(),"\n";
+# TEST
+ok(1, "docfrag2");
 }
 
 {
-print "docfrag3\n";
 my $e = XML::LibXML::Element->new('foo');
 for(1..MAX_THREADS) {
   threads->new(sub {
 	       },$_);
 }
 $_->join for(threads->list);
-ok(1);
-print $e->parentNode->toString(),"\n";
+# TEST
+ok(1, "docfrag3");
 }