App-makefilepl2cpanfile
view release on metacpan or search on metacpan
t/edge_cases.t view on Meta::CPAN
for my $case (@EXTREME_NONZERO_VERS) {
my ($ver, $expected, $label) = @{$case};
is !!App::makefilepl2cpanfile::_has_version($ver), !!$expected, $label;
}
for my $case (@EXTREME_ZERO_VERS) {
my ($ver, $expected, $label) = @{$case};
is !!App::makefilepl2cpanfile::_has_version($ver), !!$expected, $label;
}
# Inf, -Inf and NaN are numbers to Perl but not versions. _has_version
# only ever sees validated versions, so prove they are stopped upstream:
# none of them may reach the output as a requirement.
for my $ver ('Inf', '-Inf', 'NaN', 'inf', 'nan') {
my $d = App::makefilepl2cpanfile::parse_prereqs("PREREQ_PM => { 'M' => '$ver' },");
is $d->{runtime}{requires}{M}{version}, 0, "'$ver' is rejected before it could reach _has_version";
}
};
subtest 'parse_prereqs: 1 MB of noise with embedded PREREQ_PM - completes without crashing' => sub {
# Defensive performance test: a megabyte of random-ish content must not
# cause catastrophic regex backtracking. [^{}] and \{...\} are mutually
# exclusive at each position, so no backtracking occurs.
# Strategy: embed a valid PREREQ_PM block inside 500 KB of ASCII noise on
t/edge_cases.t view on Meta::CPAN
# source of Makefile.PL must NEVER be evaluated. The regex captures only
# the leading digit sequence; 9**9**9 becomes version '9', not Inf or error.
my $content = "PREREQ_PM => { \x27Module\x27 => 9**9**9 },";
my $result;
lives_ok { $result = App::makefilepl2cpanfile::parse_prereqs($content) }
'Perl expression as version does not crash or eval';
my $ver = $result->{runtime}{requires}{'Module'}{version} // 'undef';
ok defined $ver, 'version field is defined (regex captured leading digits)';
unlike "$ver", qr/Inf|NaN/i, 'captured version is not Inf/NaN (no eval occurred)';
ok $ver =~ /^\d/, 'captured version starts with a digit - just the literal text';
diag "Captured version for 9**9**9: $ver" if $ENV{TEST_VERBOSE};
};
subtest 'generate: reference as existing arg - no crash, no spurious develop merge' => sub {
# A reference passed as existing stringifies silently to e.g. "ARRAY(0x...)"
# which the develop-block regex cannot match. No warnings are emitted and
# no develop block should appear in the output.
my $g = empty_home();
Readonly my %CFG => (
header => '# Generated from Makefile.PL using makefilepl2cpanfile',
cfg_dir => '.config',
cfg_file => 'makefilepl2cpanfile.yml',
);
# Version tokens chosen to hit every branch of every validator: valid,
# zero, empty, no digit, trailing junk, non-ASCII digits, code, ranges.
Readonly my @VERSION_CORPUS => (
'0', '1', '1.60', 'v1.2.3', '1.23_01', '0.0', 'v0', '', '.', '_', 'v',
'1e3', '1.0-TRIAL', '>= 1.2', "\x{0661}", '1\\', '$x', 'Inf', 'NaN', ' 1',
);
# Comment tails: printable, blank, and made only of stripped characters.
Readonly my @COMMENT_CORPUS => (
'#', '# ', "#\t", '# text', "# \x{202E}", "# \r", "# a\x{202E}b", "# \x{1F680}",
);
sub use_home {
my $data = $_[0];
my $home = path(tempdir(CLEANUP => 1));
( run in 1.325 second using v1.01-cache-2.11-cpan-e7c6538aa59 )