1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
|
#!/usr/bin/perl
# Main testing for Perl::MinimumVersion
use strict;
BEGIN {
$| = 1;
$^W = 1;
}
use Test::More 0.47 tests => 90;
use version 0.76;
use File::Spec::Functions ':ALL';
use PPI 1.252;
use Perl::MinimumVersion 'PMV';
sub version_is {
local $Test::Builder::Level = $Test::Builder::Level + 1;
my $Document = PPI::Document->new( \$_[0] );
isa_ok( $Document, 'PPI::Document' );
my $v = Perl::MinimumVersion->new( $Document );
isa_ok( $v, 'Perl::MinimumVersion' );
is( $v->minimum_version, $_[1], $_[2] || 'Version matches expected' );
$v;
}
#####################################################################
# Basic Testing
# Test support function _max
is( PMV, 'Perl::MinimumVersion', 'PMV constant exports correctly' );
# Check the _max support function (bad)
is( Perl::MinimumVersion::_max(), '', '_max() returns false' );
is( Perl::MinimumVersion::_max(undef), '', '_max(undef) returns false' );
is( Perl::MinimumVersion::_max(''), '', '_max(undef) returns false' );
# Check the _max support function (good)
is_deeply( Perl::MinimumVersion::_max(version->new(5.004)),
version->new(5.004),
'_max(one) returns the same valud' );
is_deeply( Perl::MinimumVersion::_max(version->new(5.004), undef),
version->new(5.004),
'_max(one, bad) returns the good version' );
is_deeply( Perl::MinimumVersion::_max(version->new(5.004), version->new(5.006)),
version->new(5.006),
'_max(two) returns the higher version' );
is_deeply( Perl::MinimumVersion::_max(version->new(5.006), version->new(5.004)),
version->new(5.006),
'_max(two) returns the higher version' );
is_deeply( Perl::MinimumVersion::_max(version->new(5.006), version->new(5.004), version->new('5.5.3')),
version->new(5.006),
'_max(three) returns the higher version' );
is_deeply( Perl::MinimumVersion::_max(version->new(5.006), version->new('5.8.4'), undef, version->new(5.004), '', version->new('5.5.3')),
version->new('5.8.4'),
'_max(three) returns the higher version' );
# Check the _max support function (bad)
is( PMV->_max(), '', '_max() returns false (as method)' );
is( PMV->_max(undef), '', '_max(undef) returns false (as method)' );
is( PMV->_max(''), '', '_max(undef) returns false (as method)' );
# Check the _max support function (good)
is_deeply( PMV->_max(version->new(5.004)),
version->new(5.004),
'_max(one) returns the same value (as method)' );
is_deeply( PMV->_max(version->new(5.004), undef),
version->new(5.004),
'_max(one, bad) returns the good version (as method)' );
is_deeply( PMV->_max(version->new(5.004), version->new(5.006)),
version->new(5.006),
'_max(two) returns the higher version (as method)' );
is_deeply( PMV->_max(version->new(5.006), version->new(5.004)),
version->new(5.006),
'_max(two) returns the higher version (as method)' );
is_deeply( PMV->_max(version->new(5.006), version->new(5.004), version->new('5.5.3')),
version->new(5.006),
'_max(three) returns the higher version (as method)' );
is_deeply( PMV->_max(version->new(5.006), version->new('5.8.4'), undef, version->new(5.004), '', version->new('5.5.3')),
version->new('5.8.4'),
'_max(three) returns the higher version (as method)' );
# Constructor testing
SCOPE: {
my $v = Perl::MinimumVersion->new( \'print "Hello World!\n";' );
isa_ok( $v, 'Perl::MinimumVersion' );
$v = Perl::MinimumVersion->new( catfile( 't', '02_main.t' ) );
# version_is tests the final method
# Bad things
foreach ( {}, sub { 1 }, undef ) {
is( Perl::MinimumVersion->new( $_ ), undef, '->new(evil) returns undef' );
}
}
# Check with a complex explicit
SCOPE: {
my $v = version_is( <<'END_PERL', '5.008', 'explicit versions are detected' );
sub foo : attribute { 1 };
require 5.006;
use 5.008;
END_PERL
}
# Check with syntax higher than explicit
SCOPE: {
my $v = version_is( <<'END_PERL', '5.010', 'Used syntax higher than low explicit' );
state $foo = 1;
require 5.005;
END_PERL
}
# Regression bug: utf8 mispelled
SCOPE: {
my $v = version_is( <<'END_PERL', '5.008', 'utf8 module makes the version 5.008' );
use utf8;
1;
END_PERL
}
# Regression: binary
SCOPE: {
my $v = version_is( <<'END_PERL', '5.006', 'binary' );
$c=0b10000001;
1;
END_PERL
}
# Check the use of constant hashes
SCOPE: {
my $v = version_is( <<'END_PERL', '5.008', 'constant hash adds a 5.008 dep' );
use constant {
FOO => 1,
};
1;
END_PERL
}
# Check regular use of constants
SCOPE: {
my $v = version_is( <<'END_PERL', '5.006', 'normal constant use has no dep' );
use constant FOO => 1;
1;
END_PERL
}
# Check 'mro' pragma
SCOPE: {
my $v = version_is( <<'END_PERL', '5.010', '"use mro" matches expected version' );
use mro 'c3';
END_PERL
ok( $v->_perl_5010_pragmas, '->_perl_5010_pragmas returns true' );
}
# Check the localized soft refernence pragma
SCOPE: {
my $v = version_is( <<'END_PERL', '5.008', 'Localized soft reference matched expected version' );
local ${ "${class}::DIE" } = 1;
END_PERL
ok( $v->_local_soft_reference, '->_local_soft_reference returns true' );
}
# Check $^E + $!
SCOPE: {
my $v = version_is( <<'END_PERL', '5.008.003', '$^E + $!' );
$! + $^E;
END_PERL
is( $v->_bugfix_magic_errno->symbol, '$^E','->_bugfix_magic_errno returns $^E' );
}
# Check that minimum_syntax_version's limit param is respected
SCOPE: {
my $doc = PPI::Document->new(\'state $x'); # requires 5.010 syntax
my $minver = Perl::MinimumVersion->new($doc);
is(
$minver->minimum_syntax_version,
'5.010',
"5.006 syntax found when no limit supplied",
);
is(
$minver->minimum_syntax_version(5.008),
'5.010',
"5.006 syntax found when 5.005 limit supplied",
);
is(
$minver->minimum_syntax_version(version->new(5.018)),
'',
"no syntax constraints found when 5.008 limit supplied",
);
is(
Perl::MinimumVersion->minimum_syntax_version($doc, version->new(5.018)),
'',
"also works as object method with limit: no constraints found",
);
}
# Check feature bundle
SCOPE: {
my $v = version_is( <<'END_PERL', '5.12.0', 'use feature :5.12 matches expected version' );
use feature ':5.12';
END_PERL
}
SCOPE: {
my $v = version_is( <<'END_PERL', '5.10.0', 'use feature :5.10 along with older feature' );
use feature ':5.10';open A,'<','test.txt';
END_PERL
}
SCOPE: {
my $v = version_is( <<'END_PERL', '5.012', 'use feature :5.10 along with newer feature' );
use feature ':5.10';
sub foo { ... };
END_PERL
}
# Check regexes
SCOPE: {
my $v = version_is( <<'END_PERL', '5.006', '\z in regex matches expected version' );
m/a\z/
END_PERL
}
SCOPE: {
my $v = version_is( <<'END_PERL', '5.006', '\z along with newer feature' );
m/a\z/;open A,'<','test.txt';
END_PERL
}
SCOPE: {
my $v = version_is( <<'END_PERL', '5.015008', '\F' );
s/\Fa//;
END_PERL
}
SCOPE: {
my $v = version_is( <<'END_PERL', '5.015008', '\F and use feature' );
use feature ':5.10';
s/\Fa//;
END_PERL
}
SCOPE: {
my $v = version_is( <<'END_PERL', '5.16.0', '\F and use feature' );
use feature ':5.16';
s/\Fa//;
END_PERL
}
#check binmode
SCOPE: {
my $v = version_is( <<'END_PERL', '5.008', '2-arg binmode with utf' );
binmode($fh, ':utf');
END_PERL
}
# test version_markers
SCOPE: {
my $perl = <<'END_PERL';
use 5.005;
use mro 'dfs';
END_PERL
my @result = PMV->version_markers(\$perl);
is(@result, 4, "we find three versioned marked in the result");
my @expect = (
'5.010' => [ qw(_perl_5010_pragmas) ],
'5.005' => [ qw(explicit) ],
);
for my $i (map { $_ * 2 } 0 .. $#result / 2) {
is_deeply(
[ "$result[$i]", [ sort @{ $result[$i + 1] } ] ],
[ $expect[$i], [ sort @{ $expect[$i + 1] } ] ],
"correct data in results pos $i",
);
}
}
#check _checks2skip
SCOPE: {
my $doc = PPI::Document->new(\'s/a//u;');
my $minver = Perl::MinimumVersion->new($doc);
$minver->_set_checks2skip([qw/_regex/]);
is(
$minver->minimum_syntax_version,
'',
"5.6 checks not run when _checks2skip was used",
);
}
#check _checks2skip
SCOPE: {
my $doc = PPI::Document->new(\'s/a//u;');
my $minver = Perl::MinimumVersion->new($doc);
$minver->_set_collect_all_reasons();
like(
$minver->minimum_syntax_version,
qr/^5\.013010?$/,
"correct version",
);
is(
scalar(@{ $minver->{_all_reasons} }),
1,
"1 check met",
);
}
1;
|