- Notifications
You must be signed in to change notification settings - Fork 194
/
Copy pathmodule.t
118 lines (94 loc) · 4 KB
/
module.t
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
use strict;
use warnings;
use lib 't/lib';
use MetaCPAN::Document::Module ();
use Test::More;
subtest hide_from_pause=>sub {
foreachmy$test (
# The original:
[ 'No::CommentNL'=>"package # hide\n No::CommentNL;" ],
# I'm not sure how PAUSE handles this one but currently we ignore it.
[ 'No::JustNL'=>"package \n No::JustNL;" ],
# The good ones:
[ 'Pkg'=>'package Pkg;' ],
[ 'Pkg::Ver'=>'package Pkg::Ver v1.2.3;' ],
[ 'Pkg::Block'=>'package Pkg::Block { our $var = 1 }' ],
[
'Pkg::VerBlock'=>'package Pkg::VerBlock 1.203 { our $var = 1 }'
],
[ 'Pkg::SemiColons'=>'; package Pkg::SemiColons; $var' ],
[ 'Pkg::InABlock'=>'{ package Pkg::InABlock; $var }' ],
# This doesn't work as a BOM can only appear at the start of a file.
#[ 'Pkg::AfterABOM' => "\xef\xbb\xbfpackage Pkg::AfterABOM" ],
[ 'No::JustVar'=>qq["\n\$package No::JustVar;\n"] ],
# This shouldn't match, but there's only so much we can do...
# we're not going to eval the whole file to figure it out.
[ 'Pkg::InsideStr'=>qq["\n package Pkg::InsideStr;\n"] ],
[ 'No::Comment'=>qq[# package No::Comment;\n] ],
[ 'No::Different'=>q[package No::Different::Pkg;] ],
[ 'No::PkgWithNum'=>qq["\npackage No::PkgWithNumv2.3;\n"] ],
[ 'No::CrazyChars'=>qq["\npackage No::CrazyChars\[0\];\n"] ],
)
{
my ( $name, $content ) = @$test;
subtest $name=>sub {
my$module = MetaCPAN::Document::Module->new( name=>$name );
SKIP: {
skip( 'Perl 5.14 needed for package block compilation', 1 )
if$] < 5.014;
## no critic
ok eval"sub { no strict; $content }", "code compiles"
or diag $@;
}
my ($hidden) = ( $name =~ /^No::/ ? 1 : 0 );
is $module->hide_from_pause($content), $hidden,
"hide_from_pause is $hidden";
};
}
};
subtest set_associated_pod=>sub {
test_associated_pod( 'Squirrel', [qw( lib/Squirrel.pod )],
'lib/Squirrel.pod' );
test_associated_pod( 'Squirrel::Face', [qw( lib/Face.pm )],
'lib/Face.pm' );
test_associated_pod( 'Squirrel::Face', [qw( bin/sf.pl )], 'bin/sf.pl' );
test_associated_pod( 'Squirrel::Face', [qw( bin/sf.pl lib/Face.pm )],
'lib/Face.pm', 'prefer .pm', );
test_associated_pod( 'Squirrel::Face',
[qw( bin/sf.pl lib/Face.pm lib/Squirrel.pod )],
'lib/Squirrel.pod', 'prefer .pod', );
test_associated_pod(
'Squirrel::Face', [qw( bin/sf.pl lib/Face.pm README.pod )],
'lib/Face.pm', 'prefer .pm to README.pod',
);
test_associated_pod(
'Squirrel::Face', [qw( Zoob.pod README.pod )],
'Zoob.pod', 'prefer any .pod to README.pod',
);
test_associated_pod(
'Squirrel::Face', [qw( narf.pl README.pod )],
'narf.pl', 'prefer .pl to README.pod',
);
# This goes along with the Pod::With::Generator tests.
# Since file order is not reliable (there) we can't get a reliable failure
# so test here so that we can ensure the order.
test_associated_pod(
'Foo::Bar', [qw( a/b.pm x/Foo/Bar.pm lib/Foo/Bar.pm )],
'lib/Foo/Bar.pm', 'prefer lib/ with matching name to other files',
);
};
{
packagePodFile; ## no critic
subnew { bless { path=>$_[1] }, $_[0]; }
subpath { $_[0]->{path} }
subname { $_[0]->{name} ||= ( $_[0]->{path} =~ m{([^\/]+)$} )[0] }
subfull_path { '.../' . $_[0]->{path} }
}
subtest_associated_pod {
my ( $name, $files, $exp, $desc ) = @_;
my$module = MetaCPAN::Document::Module->new( name=>$name );
$module->set_associated_pod(
{ $name=> [ map { PodFile->new($_) } @$files ] } );
is $module->associated_pod, ".../$exp", $desc || 'Best pod file selected';
}
done_testing;