Skip to content

Enforce strict on testsuite #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions t/00impl-pp.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#########################

use strict;
use Test::More qw/no_plan/;
use File::Spec;

Expand Down
5 changes: 3 additions & 2 deletions t/01base.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#########################

use strict;
use Test::More qw/no_plan/;
use File::Spec;

Expand Down Expand Up @@ -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';
}
Expand Down
1 change: 1 addition & 0 deletions t/02derived.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#########################

use strict;
use Test::More qw/no_plan/;
use File::Spec;
use File::Temp qw/tempfile/;
Expand Down
1 change: 1 addition & 0 deletions t/03require.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#########################

use strict;
use Test::More qw/no_plan/;
use File::Spec;

Expand Down
3 changes: 2 additions & 1 deletion t/04strict_lax.t
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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";
Expand Down
1 change: 1 addition & 0 deletions t/05sigdie.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#########################

use strict;
use Test::More tests => 1;

BEGIN {
Expand Down
1 change: 1 addition & 0 deletions t/06noop.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#########################

use strict;
use Test::More qw/no_plan/;

BEGIN {
Expand Down
4 changes: 3 additions & 1 deletion t/07locale.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#########################

use strict;

use File::Basename;
use File::Temp qw/tempfile/;
use POSIX qw/locale_h/;
Expand Down Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions t/08_corelist.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#########################

use strict;
use Test::More tests => 3;
use_ok("version", 0.9928);

Expand Down
1 change: 1 addition & 0 deletions t/10_lyon.t
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#! perl

use strict;
use Test::More qw/no_plan/;

use version;
Expand Down
2 changes: 2 additions & 0 deletions t/11_taint.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!perl -T

use strict;
use Test::More;
use version;

Expand Down
54 changes: 35 additions & 19 deletions t/coretests.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#! /usr/local/perl -w
package main;

use strict;
require Test::Harness;
use Data::Dumper;
use File::Temp qw/tempfile/;
Expand All @@ -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.
};
}
Expand All @@ -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"' );
Expand Down Expand Up @@ -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' );
Expand Down Expand Up @@ -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/,
Expand All @@ -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\)/,
Expand All @@ -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: {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down Expand Up @@ -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';
}
}
Expand Down