Commit | Line | Data |
bb4e9162 |
1 | #!/usr/bin/perl -w |
2 | |
3 | use strict; |
4 | use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib'; |
5 | use MBTest tests => 18; |
6 | |
7 | use Cwd (); |
8 | my $cwd = Cwd::cwd; |
7a827510 |
9 | my $tmp = MBTest->tmpdir; |
bb4e9162 |
10 | |
11 | use Module::Build; |
12 | use Module::Build::ConfigData; |
13 | use DistGen; |
14 | |
15 | |
16 | ############################## ACTION distmeta works without a MANIFEST file |
17 | |
18 | SKIP: { |
19 | skip( 'YAML_support feature is not enabled', 4 ) |
20 | unless Module::Build::ConfigData->feature('YAML_support'); |
21 | |
22 | my $dist = DistGen->new( dir => $tmp, skip_manifest => 1 ); |
23 | $dist->regen; |
24 | |
25 | chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!"; |
26 | |
27 | ok ! -e 'MANIFEST'; |
28 | |
29 | my $mb = Module::Build->new_from_context; |
30 | |
31 | my $out; |
32 | $out = eval { stderr_of(sub{$mb->dispatch('distmeta')}) }; |
33 | is $@, ''; |
34 | |
35 | like $out, qr/Nothing to enter for 'provides'/; |
36 | |
37 | ok -e 'META.yml'; |
38 | |
39 | chdir( $cwd ) or die "Can''t chdir to '$cwd': $!"; |
40 | $dist->remove; |
41 | } |
42 | |
43 | |
44 | ############################## Check generation of README file |
45 | |
46 | # TODO: We need to test faking the absence of Pod::Readme when present |
47 | # so Pod::Text will be used. Also fake the absence of both to |
48 | # test that we fail gracefully. |
49 | |
50 | my $provides; # Used a bunch of times below |
51 | |
52 | my $pod_text = <<'---'; |
53 | =pod |
54 | |
55 | =head1 NAME |
56 | |
57 | Simple - A simple module |
58 | |
59 | =head1 AUTHOR |
60 | |
61 | Simple Simon <simon@simple.sim> |
62 | |
63 | =cut |
64 | --- |
65 | |
66 | my $dist = DistGen->new( dir => $tmp ); |
67 | |
7a827510 |
68 | $dist->change_build_pl |
69 | ({ |
70 | module_name => $dist->name, |
bb4e9162 |
71 | dist_version => '3.14159265', |
72 | license => 'perl', |
73 | create_readme => 1, |
7a827510 |
74 | }); |
bb4e9162 |
75 | $dist->regen; |
76 | |
77 | chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!"; |
78 | |
79 | |
80 | # .pm File with pod |
81 | # |
82 | |
83 | $dist->change_file( 'lib/Simple.pm', <<'---' . $pod_text); |
84 | package Simple; |
85 | $VERSION = '1.23'; |
86 | --- |
87 | $dist->regen( clean => 1 ); |
88 | ok( -e "lib/Simple.pm", "Creating Simple.pm" ); |
89 | my $mb = Module::Build->new_from_context; |
90 | $mb->do_create_readme; |
91 | like( slurp("README"), qr/NAME/, |
92 | "Generating README from .pm"); |
93 | is( $mb->dist_author->[0], 'Simple Simon <simon@simple.sim>', |
94 | "Extracting AUTHOR from .pm"); |
95 | is( $mb->dist_abstract, "A simple module", |
96 | "Extracting abstract from .pm"); |
97 | |
98 | # .pm File with pod in separate file |
99 | # |
100 | |
101 | $dist->change_file( 'lib/Simple.pm', <<'---'); |
102 | package Simple; |
103 | $VERSION = '1.23'; |
104 | --- |
105 | $dist->change_file( 'lib/Simple.pod', $pod_text ); |
106 | $dist->regen( clean => 1 ); |
107 | |
108 | ok( -e "lib/Simple.pm", "Creating Simple.pm" ); |
109 | ok( -e "lib/Simple.pod", "Creating Simple.pod" ); |
110 | $mb = Module::Build->new_from_context; |
111 | $mb->do_create_readme; |
112 | like( slurp("README"), qr/NAME/, "Generating README from .pod"); |
113 | is( $mb->dist_author->[0], 'Simple Simon <simon@simple.sim>', |
114 | "Extracting AUTHOR from .pod"); |
115 | is( $mb->dist_abstract, "A simple module", |
116 | "Extracting abstract from .pod"); |
117 | |
118 | # .pm File with pod and separate pod file |
119 | # |
120 | |
121 | $dist->change_file( 'lib/Simple.pm', <<'---' ); |
122 | package Simple; |
123 | $VERSION = '1.23'; |
124 | |
125 | =pod |
126 | |
127 | =head1 DONT USE THIS FILE FOR POD |
128 | |
129 | =cut |
130 | --- |
131 | $dist->change_file( 'lib/Simple.pod', $pod_text ); |
132 | $dist->regen( clean => 1 ); |
133 | ok( -e "lib/Simple.pm", "Creating Simple.pm" ); |
134 | ok( -e "lib/Simple.pod", "Creating Simple.pod" ); |
135 | $mb = Module::Build->new_from_context; |
136 | $mb->do_create_readme; |
137 | like( slurp("README"), qr/NAME/, "Generating README from .pod over .pm"); |
138 | is( $mb->dist_author->[0], 'Simple Simon <simon@simple.sim>', |
139 | "Extracting AUTHOR from .pod over .pm"); |
140 | is( $mb->dist_abstract, "A simple module", |
141 | "Extracting abstract from .pod over .pm"); |
142 | |
143 | |
144 | ############################################################ |
145 | # cleanup |
146 | chdir( $cwd ) or die "Can't chdir to '$cwd': $!"; |
147 | $dist->remove; |
148 | |
149 | use File::Path; |
150 | rmtree( $tmp ); |