From f15ac5f09c8d957f7da8209c80491cb524d740b7 Mon Sep 17 00:00:00 2001 From: Nicolas R Date: Tue, 18 Aug 2020 14:19:03 -0600 Subject: [PATCH] Enforce strict on testsuite --- t/00impl-pp.t | 1 + t/01base.t | 5 +++-- t/02derived.t | 1 + t/03require.t | 1 + t/04strict_lax.t | 3 ++- t/05sigdie.t | 1 + t/06noop.t | 1 + t/07locale.t | 4 +++- t/08_corelist.t | 1 + t/10_lyon.t | 1 + t/11_taint.t | 2 ++ t/coretests.pm | 54 +++++++++++++++++++++++++++++++----------------- 12 files changed, 52 insertions(+), 23 deletions(-) diff --git a/t/00impl-pp.t b/t/00impl-pp.t index 157491b..f82cc28 100644 --- a/t/00impl-pp.t +++ b/t/00impl-pp.t @@ -4,6 +4,7 @@ ######################### +use strict; use Test::More qw/no_plan/; use File::Spec; diff --git a/t/01base.t b/t/01base.t index 65f4aa3..ac7aa7d 100644 --- a/t/01base.t +++ b/t/01base.t @@ -4,6 +4,7 @@ ######################### +use strict; use Test::More qw/no_plan/; use File::Spec; @@ -40,10 +41,10 @@ ok defined($v), 'Fix for RT #47980'; eval { version::new() }; like $@, qr'Usage: version::new\(class, version\)', 'No bus err when called as function'; - eval { $x = 1; print version::new }; + eval { my $x = 1; print version::new }; like $@, qr'Usage: version::new\(class, version\)', 'No implicit object creation when called as function'; - eval { $x = "version"; print version::new }; + eval { my $x = "version"; print version::new }; like $@, qr'Usage: version::new\(class, version\)', 'No implicit object creation when called as function'; } diff --git a/t/02derived.t b/t/02derived.t index 4bab2a2..44996ce 100644 --- a/t/02derived.t +++ b/t/02derived.t @@ -4,6 +4,7 @@ ######################### +use strict; use Test::More qw/no_plan/; use File::Spec; use File::Temp qw/tempfile/; diff --git a/t/03require.t b/t/03require.t index 35efa7b..8b25267 100644 --- a/t/03require.t +++ b/t/03require.t @@ -4,6 +4,7 @@ ######################### +use strict; use Test::More qw/no_plan/; use File::Spec; diff --git a/t/04strict_lax.t b/t/04strict_lax.t index ee14a2f..60926aa 100644 --- a/t/04strict_lax.t +++ b/t/04strict_lax.t @@ -4,6 +4,7 @@ ######################### +use strict; use Test::More qw/no_plan/; # do strict lax tests in a sub to isolate a package to test importing @@ -27,7 +28,7 @@ SKIP: { is ref($version::STRICT_DECIMAL_VERSION), 'Regexp', 'Can see $version::STRICT_DECIMAL_VERSION '.$version::STRICT_DECIMAL_VERSION; is ref($version::STRICT_DOTTED_DECIMAL_VERSION), 'Regexp', 'Can see $version::STRICT_DOTTED_DECIMAL_VERSION '.$version::STRICT_DOTTED_DECIMAL_VERSION; { # https://rt.cpan.org/Ticket/Display.html?id=119669 - ($v) = ( "snapshot-1.2.3ga-001-432" =~ /($version::LAX_DOTTED_DECIMAL_VERSION)/ ); + my ($v) = ( "snapshot-1.2.3ga-001-432" =~ /($version::LAX_DOTTED_DECIMAL_VERSION)/ ); is $v, '1.2.3', "Extract just the version: $v"; ($v) = ( "snapshot-1.2ga-001-432" =~ /($version::LAX_DECIMAL_VERSION)/ ); is $v, '1.2', "Extract just the version: $v"; diff --git a/t/05sigdie.t b/t/05sigdie.t index 5429731..305ac53 100644 --- a/t/05sigdie.t +++ b/t/05sigdie.t @@ -4,6 +4,7 @@ ######################### +use strict; use Test::More tests => 1; BEGIN { diff --git a/t/06noop.t b/t/06noop.t index eb0a45e..0c664dc 100644 --- a/t/06noop.t +++ b/t/06noop.t @@ -4,6 +4,7 @@ ######################### +use strict; use Test::More qw/no_plan/; BEGIN { diff --git a/t/07locale.t b/t/07locale.t index ad63e78..e0adc1e 100644 --- a/t/07locale.t +++ b/t/07locale.t @@ -4,6 +4,8 @@ ######################### +use strict; + use File::Basename; use File::Temp qw/tempfile/; use POSIX qw/locale_h/; @@ -44,7 +46,7 @@ SKIP: { setlocale(LC_NUMERIC, $loc); $ver = 1.23; # has to be floating point number ok ($ver eq "1,23", "Using locale: $loc"); - $v = 'version'->new($ver); + my $v = 'version'->new($ver); unlike($warning, qr/Version string '1,23' contains invalid data/, "Process locale-dependent floating point"); ok ($v eq "1.23", "Locale doesn't apply to version objects"); diff --git a/t/08_corelist.t b/t/08_corelist.t index 886b23c..81e95d2 100644 --- a/t/08_corelist.t +++ b/t/08_corelist.t @@ -4,6 +4,7 @@ ######################### +use strict; use Test::More tests => 3; use_ok("version", 0.9928); diff --git a/t/10_lyon.t b/t/10_lyon.t index e4a52b4..cd2db4c 100644 --- a/t/10_lyon.t +++ b/t/10_lyon.t @@ -1,5 +1,6 @@ #! perl +use strict; use Test::More qw/no_plan/; use version; diff --git a/t/11_taint.t b/t/11_taint.t index 5307b01..b090a76 100644 --- a/t/11_taint.t +++ b/t/11_taint.t @@ -1,4 +1,6 @@ #!perl -T + +use strict; use Test::More; use version; diff --git a/t/coretests.pm b/t/coretests.pm index b38b275..f9baec0 100644 --- a/t/coretests.pm +++ b/t/coretests.pm @@ -1,5 +1,7 @@ #! /usr/local/perl -w package main; + +use strict; require Test::Harness; use Data::Dumper; use File::Temp qw/tempfile/; @@ -10,7 +12,10 @@ if ($Test::More::VERSION < 0.48) { # Fix for RT#48268 *main::use_ok = sub ($;@) { my ($pkg, $req, @args) = @_; eval "use $pkg $req ".join(' ',@args); - is ${"$pkg\::VERSION"}, eval($req), 'Had to manually use version'; + { + no strict 'refs'; + is ${"$pkg\::VERSION"}, eval($req), 'Had to manually use version'; + } # If we made it this far, we are ok. }; } @@ -25,7 +30,7 @@ sub BaseTests { # its man page ( perldoc Test ) for help writing this test script. # Test bare number processing - $version = $CLASS->$method(5.005_03); + my $version = $CLASS->$method(5.005_03); is ( "$version" , "5.00503" , '5.005_03 eq 5.00503' ); $version = $CLASS->$method(1.23); is ( "$version" , "1.23" , '1.23 eq "1.23"' ); @@ -97,7 +102,7 @@ sub BaseTests { # Test Numeric Comparison operators # test first with non-object $version = $CLASS->$method("5.006.001"); - $new_version = "5.8.0"; + my $new_version = "5.8.0"; ok ( $version == $version, '$version == $version' ); ok ( $version < $new_version, '$version < $new_version' ); ok ( $new_version > $version, '$new_version > $version' ); @@ -303,7 +308,7 @@ SKIP: { { # dummy up some variously broken modules for testing my ($fh, $filename) = tempfile('tXXXXXXX', SUFFIX => '.pm', UNLINK => 1); (my $package = basename($filename)) =~ s/\.pm$//; - print $fh "package $package;\n\@VERSION = ();\n1;\n"; + print $fh "package $package;\nour \@VERSION = ();\n1;\n"; close $fh; eval "use lib '.'; use $package 3;"; like ($@, qr/$error_regex/, @@ -318,7 +323,7 @@ SKIP: { # https://rt.perl.org/rt3/Ticket/Display.html?id=95544 unless defined $qv_declare; my ($fh, $filename) = tempfile('tXXXXXXX', SUFFIX => '.pm', UNLINK => 1); (my $package = basename($filename)) =~ s/\.pm$//; - print $fh "package $package;\n\$VERSION = '3alpha';\n1;\n"; + print $fh "package $package;\nour \$VERSION = '3alpha';\n1;\n"; close $fh; eval "use lib '.'; use $package; print $package->VERSION"; like ($@, qr/Invalid version format \(non-numeric data\)/, @@ -338,8 +343,12 @@ SKIP: { ok($version == $new_version, '$version == $new_version'); skip "version require'd instead of use'd, cannot test declare", 1 unless defined $qv_declare; - $version = &$qv_declare(1.2.3); - ok("$version" eq "v1.2.3", 'v-string initialized $qv_declare()'); + + { + no strict 'refs'; + $version = &{$qv_declare}(1.2.3); + ok("$version" eq "v1.2.3", 'v-string initialized $qv_declare()'); + } } SKIP: { @@ -400,7 +409,7 @@ SKIP: { (my $package = basename($filename)) =~ s/\.pm$//; print $fh <<"EOF"; package $package; -use $CLASS; \$VERSION = ${CLASS}->new('0.0.4'); +use $CLASS; our \$VERSION = ${CLASS}->new('0.0.4'); 1; EOF close $fh; @@ -429,22 +438,29 @@ EOF } SKIP: { - skip "Cannot test \"use parent $CLASS\" when require is used", 3 + skip "Cannot test \"use base $CLASS\" when require is used", 3 unless defined $qv_declare; my ($fh, $filename) = tempfile('tXXXXXXX', SUFFIX => '.pm', UNLINK => 1); (my $package = basename($filename)) =~ s/\.pm$//; print $fh <<"EOF"; package $package; -use base $CLASS; +use base '$CLASS'; 1; EOF close $fh; # need to eliminate any other $qv_declare()'s - undef *{"main\::$qv_declare"}; - ok(!defined(&{"main\::$qv_declare"}), "make sure we cleared $qv_declare() properly"); + { + no strict 'refs'; + undef *{"main\::$qv_declare"}; + ok(!defined(&{"main\::$qv_declare"}), "make sure we cleared $qv_declare() properly"); + } eval "use lib '.'; use $package qw/declare qv/;"; + die "Error from test: $@" if $@; ok(defined(&{"main\::$qv_declare"}), "make sure we exported $qv_declare() properly"); - isa_ok( &$qv_declare(1.2), $package); + { + no strict 'refs'; + isa_ok( main->can($qv_declare)->(1.2), $package); + } unlink $filename; } @@ -456,7 +472,7 @@ SKIP: { (my $package = basename($filename)) =~ s/\.pm$//; print $fh <<"EOF"; package $package; -\$VERSION = 1.0; +our \$VERSION = 1.0; 1; EOF close $fh; @@ -614,23 +630,23 @@ SKIP: { } { # now as a number - $two31 = 2**31; - $v = $CLASS->new($two31); + my $two31 = 2**31; + my $v = $CLASS->new($two31); is "$v", 'v.Inf', 'Element Exceeds VERSION_MAX'; like $warning, qr/Integer overflow in version/, 'Overflow warning'; } { # https://rt.cpan.org/Ticket/Display.html?id=101628 undef $warning; - $v = $CLASS->new('1.1.00000000010'); + my $v = $CLASS->new('1.1.00000000010'); is $v->normal, "v1.1.10", 'Ignore leading zeros'; unlike $warning, qr/Integer overflow in version/, 'No overflow warning'; } { # https://rt.cpan.org/Ticket/Display.html?id=93340 - $v = $CLASS->parse(q[2.6_01]); + my $v = $CLASS->parse(q[2.6_01]); is $v->normal, 'v2.601.0', 'Normal strips underscores from alphas' } { # https://rt.cpan.org/Ticket/Display.html?id=98744 - $v = $CLASS->new("1.02_003"); + my $v = $CLASS->new("1.02_003"); is $v->numify, '1.020030', 'Ignore underscores for numify'; } }