Subject: | t/*.t: Adapt test files for strictures and warnings |
The test files in this distribution (which also ships with the Perl 5 core distribution) do not contain 'use strict', 'use warnings' or similar use of pragmas. That's appropriate, as this module predates some aspects of these pragmas.
A future version of Perl may have strictures and warnings on by default. The patch attached adapts the test files for this environment. They have been tested on perl-5.6.2, perl-5.32.0 and an environment where strict and warnings are on by default ("Perl 7").
Should you want to move this distribution into git version control, see:
https://github.com/jkeenan/Text-Balanced/tree/master.
Thank you very much.
Jim Keenan
Subject: | Text-Balanced.diff |
diff --git a/cpan/Text-Balanced/t/02_extbrk.t b/cpan/Text-Balanced/t/02_extbrk.t
index a36025ddb0..1947e97542 100644
--- a/cpan/Text-Balanced/t/02_extbrk.t
+++ b/cpan/Text-Balanced/t/02_extbrk.t
@@ -6,20 +6,22 @@
# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)
+my $loaded;
BEGIN { $| = 1; print "1..19\n"; }
END {print "not ok 1\n" unless $loaded;}
use Text::Balanced qw ( extract_bracketed );
$loaded = 1;
print "ok 1\n";
-$count=2;
+my $count=2;
use vars qw( $DEBUG );
sub debug { print "\t>>>",@_ if $DEBUG }
######################### End of black magic.
-$cmd = "print";
-$neg = 0;
+my $cmd = "print";
+my $neg = 0;
+my $str;
while (defined($str = <DATA>))
{
chomp $str;
@@ -30,7 +32,7 @@ while (defined($str = <DATA>))
debug "\tUsing: $cmd\n";
debug "\t on: [$str]\n";
- $var = eval "() = $cmd";
+ my $var = eval "() = $cmd";
debug "\t list got: [$var]\n";
debug "\t list left: [$str]\n";
print "not " if (substr($str,pos($str),1) eq ';')==$neg;
diff --git a/cpan/Text-Balanced/t/03_extcbk.t b/cpan/Text-Balanced/t/03_extcbk.t
index 83081ae28d..d0b73a2964 100644
--- a/cpan/Text-Balanced/t/03_extcbk.t
+++ b/cpan/Text-Balanced/t/03_extcbk.t
@@ -6,20 +6,22 @@
# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)
+my $loaded;
BEGIN { $| = 1; print "1..41\n"; }
END {print "not ok 1\n" unless $loaded;}
use Text::Balanced qw ( extract_codeblock );
$loaded = 1;
print "ok 1\n";
-$count=2;
+my $count=2;
use vars qw( $DEBUG );
sub debug { print "\t>>>",@_ if $DEBUG }
######################### End of black magic.
-$cmd = "print";
-$neg = 0;
+my $cmd = "print";
+my $neg = 0;
+my $str;
while (defined($str = <DATA>))
{
chomp $str;
@@ -31,7 +33,7 @@ while (defined($str = <DATA>))
debug "\t on: [$str]\n";
my @res;
- $var = eval "\@res = $cmd";
+ my $var = eval "\@res = $cmd";
debug "\t Failed: $@ at " . $@+0 .")" if $@;
debug "\t list got: [" . join("|", map {defined $_ ? $_ : '<undef>'} @res) . "]\n";
debug "\t list left: [$str]\n";
diff --git a/cpan/Text-Balanced/t/04_extdel.t b/cpan/Text-Balanced/t/04_extdel.t
index c5ca88eebf..0e8583a7a3 100644
--- a/cpan/Text-Balanced/t/04_extdel.t
+++ b/cpan/Text-Balanced/t/04_extdel.t
@@ -6,20 +6,22 @@
# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)
+my $loaded;
BEGIN { $| = 1; print "1..45\n"; }
END {print "not ok 1\n" unless $loaded;}
use Text::Balanced qw ( extract_delimited );
$loaded = 1;
print "ok 1\n";
-$count=2;
+my $count=2;
use vars qw( $DEBUG );
sub debug { print "\t>>>",@_ if $DEBUG }
######################### End of black magic.
-$cmd = "print";
-$neg = 0;
+my $cmd = "print";
+my $neg = 0;
+my $str;
while (defined($str = <DATA>))
{
chomp $str;
@@ -30,7 +32,7 @@ while (defined($str = <DATA>))
debug "\tUsing: $cmd\n";
debug "\t on: [$str]\n";
- $var = eval "() = $cmd";
+ my $var = eval "() = $cmd";
debug "\t list got: [$var]\n";
debug "\t list left: [$str]\n";
print "not " if (substr($str,pos($str)||0,1) eq ';')==$neg;
diff --git a/cpan/Text-Balanced/t/05_extmul.t b/cpan/Text-Balanced/t/05_extmul.t
index 2ac1b19ffd..7646c09566 100644
--- a/cpan/Text-Balanced/t/05_extmul.t
+++ b/cpan/Text-Balanced/t/05_extmul.t
@@ -6,12 +6,13 @@
# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)
+my $loaded;
BEGIN { $| = 1; print "1..86\n"; }
END {print "not ok 1\n" unless $loaded;}
use Text::Balanced qw ( :ALL );
$loaded = 1;
print "ok 1\n";
-$count=2;
+my $count=2;
use vars qw( $DEBUG );
sub debug { print "\t>>>",@_ if $DEBUG }
@@ -61,10 +62,10 @@ sub divide
}
-$stdtext1 = q{$var = do {"val" && $val;};};
+my $stdtext1 = q{$var = do {"val" && $val;};};
# TESTS 2-4
-$text = $stdtext1;
+my $text = $stdtext1;
expect [ extract_multiple($text,undef,1) ],
[ divide $stdtext1 => 4 ];
@@ -151,7 +152,7 @@ expect [ $text ], [ substr($stdtext1,4) ];
# TESTS 32-34
-$stdtext2 = q{$var = "val" && (1,2,3);};
+my $stdtext2 = q{$var = "val" && (1,2,3);};
$text = $stdtext2;
expect [ extract_multiple($text) ],
diff --git a/cpan/Text-Balanced/t/06_extqlk.t b/cpan/Text-Balanced/t/06_extqlk.t
index 6badc0ee18..8ec31d4743 100644
--- a/cpan/Text-Balanced/t/06_extqlk.t
+++ b/cpan/Text-Balanced/t/06_extqlk.t
@@ -7,12 +7,13 @@
# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)
+my $loaded;
BEGIN { $| = 1; print "1..95\n"; }
END {print "not ok 1\n" unless $loaded;}
use Text::Balanced qw ( extract_quotelike );
$loaded = 1;
print "ok 1\n";
-$count=2;
+my $count=2;
use vars qw( $DEBUG );
#$DEBUG=1;
sub debug { print "\t>>>",@_ if $ENV{DEBUG} }
@@ -21,8 +22,9 @@ sub esc { my $x = shift||'<undef>'; $x =~ s/\n/\\n/gs; $x }
######################### End of black magic.
-$cmd = "print";
-$neg = 0;
+my $cmd = "print";
+my $neg = 0;
+my $str;
while (defined($str = <DATA>))
{
chomp $str;
@@ -53,7 +55,7 @@ while (defined($str = <DATA>))
$str = $orig;
debug "\tUsing: scalar $cmd\n";
debug "\t on: [" . esc($str) . "]\n";
- $var = eval $cmd;
+ my $var = eval $cmd;
print " ($@)" if $@ && $DEBUG;
$var = "<undef>" unless defined $var;
debug "\t scalar got: [" . esc($var) . "]\n";
diff --git a/cpan/Text-Balanced/t/07_exttag.t b/cpan/Text-Balanced/t/07_exttag.t
index 16a48b2ae3..e297f7f9f2 100644
--- a/cpan/Text-Balanced/t/07_exttag.t
+++ b/cpan/Text-Balanced/t/07_exttag.t
@@ -6,20 +6,22 @@
# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)
+my $loaded;
BEGIN { $| = 1; print "1..53\n"; }
END {print "not ok 1\n" unless $loaded;}
use Text::Balanced qw ( extract_tagged gen_extract_tagged );
$loaded = 1;
print "ok 1\n";
-$count=2;
+my $count=2;
use vars qw( $DEBUG );
sub debug { print "\t>>>",@_ if $DEBUG }
######################### End of black magic.
-$cmd = "print";
-$neg = 0;
+my $cmd = "print";
+my $neg = 0;
+my $str;
while (defined($str = <DATA>))
{
chomp $str;
@@ -31,7 +33,7 @@ while (defined($str = <DATA>))
debug "\t on: [$str]\n";
my @res;
- $var = eval "\@res = $cmd";
+ my $var = eval "\@res = $cmd";
debug "\t list got: [" . join("|",map {defined $_ ? $_ : '<undef>'} @res) . "]\n";
debug "\t list left: [$str]\n";
print "not " if (substr($str,pos($str)||0,1) eq ';')==$neg;
diff --git a/cpan/Text-Balanced/t/08_extvar.t b/cpan/Text-Balanced/t/08_extvar.t
index a33ac919ec..99ff4965be 100644
--- a/cpan/Text-Balanced/t/08_extvar.t
+++ b/cpan/Text-Balanced/t/08_extvar.t
@@ -6,20 +6,22 @@
# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)
+my $loaded;
BEGIN { $| = 1; print "1..183\n"; }
END {print "not ok 1\n" unless $loaded;}
use Text::Balanced qw ( extract_variable );
$loaded = 1;
print "ok 1\n";
-$count=2;
+my $count=2;
use vars qw( $DEBUG );
sub debug { print "\t>>>",@_ if $DEBUG }
######################### End of black magic.
-$cmd = "print";
-$neg = 0;
+my $cmd = "print";
+my $neg = 0;
+my $str;
while (defined($str = <DATA>))
{
chomp $str;
@@ -31,7 +33,7 @@ while (defined($str = <DATA>))
debug "\t on: [$str]\n";
my @res;
- $var = eval "\@res = $cmd";
+ my $var = eval "\@res = $cmd";
debug "\t list got: [" . join("|",map {defined $_ ? $_ : '<undef>'} @res) . "]\n";
debug "\t list left: [$str]\n";
print "not " if (substr($str,pos($str)||0,1) eq ';')==$neg;
diff --git a/cpan/Text-Balanced/t/09_gentag.t b/cpan/Text-Balanced/t/09_gentag.t
index 0dd55a5f3f..882d799bd7 100644
--- a/cpan/Text-Balanced/t/09_gentag.t
+++ b/cpan/Text-Balanced/t/09_gentag.t
@@ -6,20 +6,21 @@
# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)
+my $loaded;
BEGIN { $| = 1; print "1..37\n"; }
END {print "not ok 1\n" unless $loaded;}
use Text::Balanced qw ( gen_extract_tagged );
$loaded = 1;
print "ok 1\n";
-$count=2;
+my $count=2;
use vars qw( $DEBUG );
sub debug { print "\t>>>",@_ if $DEBUG }
-
######################### End of black magic.
-$cmd = "print";
-$neg = 0;
+my $cmd = "print";
+my $neg = 0;
+my $str;
while (defined($str = <DATA>))
{
chomp $str;
@@ -27,7 +28,12 @@ while (defined($str = <DATA>))
if ($str =~ s/\A# USING://)
{
$neg = 0;
- eval{local$^W;*f = eval $str || die};
+ eval {
+ # Capture "Subroutine main::f redefined" warning
+ my @warnings;
+ local $SIG{__WARN__} = sub { push @warnings, shift; };
+ *f = eval $str || die;
+ };
next;
}
elsif ($str =~ /\A# TH[EI]SE? SHOULD FAIL/) { $neg = 1; next; }
@@ -37,7 +43,7 @@ while (defined($str = <DATA>))
debug "\t on: [$str]\n";
my @res;
- $var = eval { @res = f($str) };
+ my $var = eval { @res = f($str) };
debug "\t list got: [" . join("|",map {defined $_ ? $_ : '<undef>'} @res) . "]\n";
debug "\t list left: [$str]\n";
print "not " if (substr($str,pos($str)||0,1) eq ';')==$neg;