| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use FindBin; |
| 4 |
use File::Find; |
| 5 |
use Test::More; |
| 6 |
use File::Temp; |
| 7 |
use File::Basename; |
| 8 |
use File::Path; |
| 9 |
use Module::CoreList; |
| 10 |
use Menlo::CLI::Compat; |
| 11 |
|
| 12 |
my $t_dir = "$FindBin::Bin/../../t"; |
| 13 |
my $local = "$FindBin::Bin/local"; |
| 14 |
my %installed; |
| 15 |
my %dummy = map { ref $_ ? @$_ : ($_ => 1) } ( |
| 16 |
"mojo_base/Mojo::BaseTestTest", |
| 17 |
"only/MyModule", |
| 18 |
"plack/Plack::Middleware::Foo", |
| 19 |
"plack/Foo", |
| 20 |
"test_class_most/My::Test::Class", |
| 21 |
"test_class_most/Tests::For::Foo", |
| 22 |
"test_class_most/Tests::For::Bar", |
| 23 |
"test_class_most/Some::Other::Class::For::Increased::Stupidity", |
| 24 |
"class_autouse/CGI", |
| 25 |
"package_variant/Data::Record::Serialize::Role::Base", |
| 26 |
"package_variant/TestImportableA", |
| 27 |
"moosex_declare/Foo", |
| 28 |
"moosex_declare/Foo::A", |
| 29 |
"moosex_declare/Foo::B", |
| 30 |
"moosex_declare/Foo::C", |
| 31 |
"moosex_declare/Foo::Z", |
| 32 |
"moosex_declare/Foo::Bar::Baz", |
| 33 |
"moosex_declare/Foo::Bar::Fnording", |
| 34 |
"moosex_declare/Foo::Baz", |
| 35 |
"moosex_declare/Corge", |
| 36 |
"moosex_declare/Role", |
| 37 |
"moosex_declare/SecondRole", |
| 38 |
"no_moose/Foo", |
| 39 |
"catalyst/Catalyst::Plugin::My::Module", |
| 40 |
"catalyst/Fully::Qualified::Plugin::Name", |
| 41 |
"catalyst/TestApp::Plugin::FullyQualified", |
| 42 |
"catalyst/Catalyst::Plugin::Test::Plugin", |
| 43 |
"20_parsers/Foo", |
| 44 |
"unless/POE::Kernel", |
| 45 |
"test_requires/Some::Optional::Test::Required::Modules", |
| 46 |
"inline/Tibco::Rv::Inline", |
| 47 |
["core/class/Bar" => "use experimental 'class';\nclass Bar 999;\n1;\n"], |
| 48 |
["core/class/Baz" => "use experimental 'class';\nrole Baz 999;\n1;\n"], |
| 49 |
["core/class/Quux" => "use experimental 'class';\nrole Quux 999;\n1;\n"], |
| 50 |
["object_pad/feature_compat_class/Bar" => "use Feature::Compat::Class;\nclass Bar 999;\n1;\n"], |
| 51 |
["object_pad/feature_compat_class/Baz" => "use Feature::Compat::Class;\nrole Baz 999;\n1;\n"], |
| 52 |
["object_pad/feature_compat_class/Quux" => "use Feature::Compat::Class;\nrole Quux 999;\n1;\n"], |
| 53 |
["object_pad/isa_and_does/Bar" => "use Object::Pad;\nclass Bar;\nour \$VERSION = 999;\n1;\n"], |
| 54 |
["object_pad/isa_and_does/Baz" => "use Object::Pad;\nrole Baz;\nour \$VERSION = 999;\n1;\n"], |
| 55 |
["object_pad/isa_and_does/Quux" => "use Object::Pad;\nrole Quux;\nour \$VERSION = 999;\n1;\n"], |
| 56 |
["object_pad/attr/Bar" => "use Object::Pad;\nclass Bar;\nour \$VERSION = 999;\n1;\n"], |
| 57 |
["object_pad/attr/Baz" => "use Object::Pad;\nrole Baz;\nour \$VERSION = 999;\n1;\n"], |
| 58 |
["object_pad/attr/Quux" => "use Object::Pad;\nrole Quux;\nour \$VERSION = 999;\n1;\n"], |
| 59 |
); |
| 60 |
|
| 61 |
my %ok = map { $_ => 1 } qw( |
| 62 |
10_use |
| 63 |
11_require |
| 64 |
12_no |
| 65 |
15_eval |
| 66 |
20_parsers |
| 67 |
aliased |
| 68 |
autouse |
| 69 |
begin_exit |
| 70 |
catalyst |
| 71 |
class_autouse |
| 72 |
class_load |
| 73 |
core/base |
| 74 |
core/builtin |
| 75 |
core/class |
| 76 |
core/experimental |
| 77 |
core/feature |
| 78 |
core/if |
| 79 |
core/parent |
| 80 |
later |
| 81 |
minimum_version |
| 82 |
mixin |
| 83 |
module_runtime |
| 84 |
mojo_base |
| 85 |
moosex_declare |
| 86 |
moose/any_moose |
| 87 |
moose/class_accessor |
| 88 |
moose/extends_inner_package |
| 89 |
moose/moose |
| 90 |
moose/no_moose |
| 91 |
moose/todo |
| 92 |
moose/with_variable |
| 93 |
object_pad/attr |
| 94 |
object_pad/basic |
| 95 |
object_pad/feature_compat_class |
| 96 |
object_pad/isa_and_does |
| 97 |
only |
| 98 |
package_variant |
| 99 |
plack |
| 100 |
prefork |
| 101 |
syntax_collector |
| 102 |
test_class_most |
| 103 |
test_more |
| 104 |
test_requires |
| 105 |
universal_version |
| 106 |
unless |
| 107 |
); |
| 108 |
|
| 109 |
my %testing = map { $_ => 1 } qw( |
| 110 |
); |
| 111 |
|
| 112 |
my %skip = map { $_ => 1 } qw( |
| 113 |
00_load |
| 114 |
inline |
| 115 |
); |
| 116 |
|
| 117 |
find({ |
| 118 |
wanted => sub { |
| 119 |
my $file = $File::Find::name; |
| 120 |
return unless -f $file && $file =~ /\.t$/; |
| 121 |
return if $file =~ m!t/(?:app|bin|compat|scan)!; |
| 122 |
my ($basename) = $file =~ m!\bt/(.+?)\.t$!; |
| 123 |
return if $skip{$basename}; # TODO: needs finer control |
| 124 |
if (!$ENV{TEST_VERBOSE} && $ok{$basename}) { |
| 125 |
pass $basename; |
| 126 |
return; |
| 127 |
} |
| 128 |
return if $ENV{TEST_ONLY} && $ENV{TEST_ONLY} ne $basename; |
| 129 |
subtest "$basename" => sub { |
| 130 |
open my $fh, '<', $file; |
| 131 |
my $flag; |
| 132 |
my $code = ''; |
| 133 |
my $test_count = 1; |
| 134 |
my $expected; |
| 135 |
my $expected_nothing; |
| 136 |
my $skip; |
| 137 |
|
| 138 |
while (<$fh>) { |
| 139 |
if ($flag) { |
| 140 |
if (/^END$/) { |
| 141 |
my $tmp = File::Temp->new(DIR => "$FindBin::Bin/local", UNLINK => 0); |
| 142 |
print $tmp "use feature ':all';\n" unless $basename eq 'minimum_version'; |
| 143 |
print $tmp "$code\n;\n1;"; |
| 144 |
my $filename = $tmp->filename; |
| 145 |
close $tmp; |
| 146 |
note "TEST CODE:" . "-" x 30 . "\n$code\n" . "-" x 40 . "\n\n"; |
| 147 |
my $result = `$^X -I$local/$basename/lib/perl5 -c $filename 2>&1`; |
| 148 |
SKIP: { |
| 149 |
skip $skip, 1 if $skip; |
| 150 |
if ($expected_nothing) { |
| 151 |
ok !$result, "$file: expected nothing" or note "RESULT: $result"; |
| 152 |
} elsif ($expected) { |
| 153 |
# probably an erroneous output |
| 154 |
ok $result =~ /$expected/, "$file: expected result" or note "RESULT: $result"; |
| 155 |
} else { |
| 156 |
ok $result =~ /syntax OK/, "$file: test $test_count" or note "RESULT: $result"; |
| 157 |
} |
| 158 |
} |
| 159 |
$flag = 0; |
| 160 |
$test_count++; |
| 161 |
$code = $expected = $expected_nothing = $skip = ''; |
| 162 |
} else { |
| 163 |
$code .= $_; |
| 164 |
} |
| 165 |
} else { |
| 166 |
|
| 167 |
last if /^done_testing/; |
| 168 |
if (/^#SKIP: (.*)$/) { |
| 169 |
$skip = $1; |
| 170 |
next; |
| 171 |
} |
| 172 |
if (/^#SKIP_IF: (.*)$/) { |
| 173 |
my $condition = $1; |
| 174 |
$skip = $condition if eval $condition; |
| 175 |
next; |
| 176 |
} |
| 177 |
if (/^#SKIP_ALL_IF: (.*)$/) { |
| 178 |
my $condition = $1; |
| 179 |
if (eval $condition) { |
| 180 |
TODO: { |
| 181 |
local $TODO = $condition; |
| 182 |
fail "skipped"; |
| 183 |
} |
| 184 |
return; |
| 185 |
} |
| 186 |
next; |
| 187 |
} |
| 188 |
if (/^#EXPECTED: (.*)$/) { |
| 189 |
$expected = $1; |
| 190 |
next; |
| 191 |
} |
| 192 |
if (/^#EXPECTED_NOTHING$/) { |
| 193 |
$expected_nothing = 1; |
| 194 |
next; |
| 195 |
} |
| 196 |
if (/^#EXPECTED_NOTHING_IF: (.*)$/) { |
| 197 |
my $condition = $1; |
| 198 |
$expected_nothing = 1 if eval $condition; |
| 199 |
next; |
| 200 |
} |
| 201 |
if (/^#REQUIRES: (.*)$/) { |
| 202 |
my $module = $1; |
| 203 |
my $menlo = Menlo::CLI::Compat->new; |
| 204 |
$menlo->parse_options(('-L', "$local/$basename", '-n', ($ENV{TEST_VERBOSE} ? '-v' : ()), $module)); |
| 205 |
$menlo->run; |
| 206 |
$module =~ s!\@.+$!!; |
| 207 |
$installed{"$basename/$module"} = 1; |
| 208 |
next; |
| 209 |
} |
| 210 |
if (/^test\(/) { |
| 211 |
$flag = 1; |
| 212 |
my ($requires, $recommends, $suggests) = $_ =~ /<<'END',\s*(\{.*?\})(?:,\s*(\{.*?\}))?(?:,\s*(\{.*?\}))?/; |
| 213 |
my $packages = eval $requires; |
| 214 |
if ($recommends) { |
| 215 |
%$packages = (%{ eval($recommends) }, %$packages); |
| 216 |
} |
| 217 |
if ($suggests) { |
| 218 |
%$packages = (%{ eval($suggests) }, %$packages); |
| 219 |
} |
| 220 |
for my $module (keys %$packages) { |
| 221 |
next if $module eq 'perl'; |
| 222 |
next if Module::CoreList::is_core($module); |
| 223 |
next if $installed{"$basename/$module"}; |
| 224 |
if (my $content = $dummy{"$basename/$module"}) { |
| 225 |
my $dummy_file = "$local/$basename/lib/perl5/$module.pm"; |
| 226 |
$dummy_file =~ s!::!/!g; |
| 227 |
my $parent = dirname($dummy_file); |
| 228 |
mkpath $parent unless -d $parent; |
| 229 |
open my $out, '>', $dummy_file or die "$!: $dummy_file"; |
| 230 |
if ($content ne "1") { |
| 231 |
print $out $content; |
| 232 |
} else { |
| 233 |
print $out "package $module; our \$VERSION = '9999.99'\n; 1;\n"; |
| 234 |
} |
| 235 |
close $out; |
| 236 |
} else { |
| 237 |
my $menlo = Menlo::CLI::Compat->new; |
| 238 |
$menlo->parse_options(('-L', "$local/$basename", '-n', ($ENV{TEST_VERBOSE} ? '-v' : ()), $module)); |
| 239 |
$menlo->run; |
| 240 |
$installed{"$basename/$module"}++; |
| 241 |
} |
| 242 |
} |
| 243 |
} |
| 244 |
} |
| 245 |
} |
| 246 |
} |
| 247 |
}, |
| 248 |
no_chdir => 1, |
| 249 |
}, |
| 250 |
$t_dir |
| 251 |
); |
| 252 |
|
| 253 |
done_testing; |