Commits

Shlomi Fish committed cd49656

Moved the slurp() routines to t/lib/TestHelpers.pm .

Comments (0)

Files changed (6)

     documented in TODO.
         - << suppress_errors option not honored by load_html() method if set in 
         parser object >>
+    - Created t/lib/TestHelpers.pm with slurp(), utf8_slurp() and, in the
+    future, some other routines.
 
 
 1.75            Fri Jun 24 19:00:40 IDT 2011
 t/61error.t
 t/80registryleak.t
 t/90threads.t
+t/lib/TestHelpers.pm
 t/pod.t
 test/relaxng/badschema.rng
 test/relaxng/demo.rng
 
 use Test::More tests => 18;
 
+use lib './t/lib';
+use TestHelpers;
+
 use XML::LibXML;
 
 # TEST
 ok(1, "Loaded");
 
-sub _slurp
-{
-    my $filename = shift;
-
-    open my $in, "<", $filename
-        or die "Cannot open '$filename' for slurping - $!";
-
-    local $/;
-    my $contents = <$in>;
-
-    close($in);
-
-    return $contents;
-}
-
-my $dtdstr = _slurp('example/test.dtd');
+my $dtdstr = slurp('example/test.dtd');
 
 $dtdstr =~ s/\r//g;
 $dtdstr =~ s/[\r\n]*$//;
 use strict;
 use warnings;
 
+use lib './t/lib';
+use TestHelpers;
+
 use Test::More;
 
     use XML::LibXML;
     ok( $@, 'Bad XML::LibXML::Schema throws an exception.' );
 }
 
-sub _slurp
-{
-    my $filename = shift;
-
-    open my $in, '<', $filename
-        or die "Cannot open '$filename' for slurping - $!";
-
-    local $/;
-    my $contents = <$in>;
-
-    close($in);
-
-    return $contents;
-}
-
 # 2 parse schema from a string
 {
-    my $string = _slurp($file);
+    my $string = slurp($file);
 
     my $rngschema = XML::LibXML::Schema->new( string => $string );
     # TEST
     ok ( $rngschema, 'RNG Schema initialized from string.' );
 
-    $string = _slurp($badfile);
+    $string = slurp($badfile);
     eval { $rngschema = XML::LibXML::Schema->new( string => $string ); };
     # TEST
     ok( $@, 'Bad string schema throws an excpetion.' );
 use strict;
 use warnings;
 
+use lib './t/lib';
+use TestHelpers;
+
 use Test::More tests => 1;
 
 use XML::LibXML;
 
-sub _utf8_slurp
-{
-    my $filename = shift;
-
-    open my $in, '<', $filename
-        or die "Cannot open '$filename' for slurping - $!";
-
-    binmode $in, ':utf8';
-
-    local $/;
-    my $contents = <$in>;
-
-    close($in);
-
-    return $contents;
-}
-
 # This is a check for:
 # https://rt.cpan.org/Ticket/Display.html?id=53270
 
 {
-    my $content = _utf8_slurp('example/yahoo-finance-html-with-errors.html');
+    my $content = utf8_slurp('example/yahoo-finance-html-with-errors.html');
 
     my $parser = XML::LibXML->new;
 

t/lib/TestHelpers.pm

+package TestHelpers;
+
+use strict;
+use warnings;
+
+our @EXPORT = (qw(slurp utf8_slurp));
+
+use base 'Exporter';
+
+sub slurp
+{
+    my $filename = shift;
+
+    open my $in, "<", $filename
+        or die "Cannot open '$filename' for slurping - $!";
+
+    local $/;
+    my $contents = <$in>;
+
+    close($in);
+
+    return $contents;
+}
+
+sub utf8_slurp
+{
+    my $filename = shift;
+
+    open my $in, '<', $filename
+        or die "Cannot open '$filename' for slurping - $!";
+
+    binmode $in, ':utf8';
+
+    local $/;
+    my $contents = <$in>;
+
+    close($in);
+
+    return $contents;
+}
+
+
+1;