4 use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
5 use MBTest tests => 25;
7 use_ok 'Module::Build';
8 ensure_blib('Module::Build');
14 my $tmp = MBTest->tmpdir;
18 my $dist = DistGen->new(dir => $tmp);
26 File::Path::rmtree( $tmp );
27 # we're redefining the same package as we go, so...
28 delete($::{'MyModuleBuilder::'});
29 delete($INC{'MyModuleBuilder.pm'});
31 chdir($dist->dirname) or
32 die "Can't chdir to '@{[$dist->dirname]}': $!";
35 chdir($dist->dirname) or die "Can't chdir to '@{[$dist->dirname]}': $!";
37 ########################################################################
38 { # check the =item style
39 my $mb = Module::Build->subclass(
40 code => join "\n", map {s/^ {4}//; $_} split /\n/, <<' ---',
57 You should probably not be seeing this. That is, we haven't
58 overridden the help action, but we're able to override just the
59 docs? That almost seems reasonable, but is probably wrong.
65 sub ACTION_foo { die "fooey" }
66 sub ACTION_bar { die "barey" }
67 sub ACTION_baz { die "bazey" }
69 # guess we can have extra pod later
83 module_name => $dist->name,
87 can_ok($mb, 'ACTION_foo');
89 foreach my $action (qw(foo bar baz)) { # typical usage
90 my $doc = $mb->get_action_docs($action);
91 ok($doc, "got doc for '$action'");
92 like($doc, qr/^=\w+ $action\n\nDoes the $action thing\./s,
96 { # user typo'd the action name
97 ok( ! eval {$mb->get_action_docs('batz'); 1}, 'slap');
98 like($@, qr/No known action 'batz'/, 'informative error');
101 { # XXX this one needs some thought
103 my $doc = $mb->get_action_docs($action);
104 ok($doc, "got doc for '$action'");
105 0 and warn "help doc >\n$doc<\n";
107 local $TODO = 'Do we allow overrides on just docs?';
108 unlike($doc, qr/^=\w+ $action\n\nDoes the $action thing\./s,
109 'got the right doc');
114 ########################################################################
115 if(0) { # the =item style without spanning =head1 sections
116 my $mb = Module::Build->subclass(
117 code => join "\n", map {s/^ {4}//; $_} split /\n/, <<' ---',
144 sub ACTION_foo { die "fooey" }
145 sub ACTION_bar { die "barey" }
146 sub ACTION_baz { die "bazey" }
150 module_name => $dist->name,
154 can_ok($mb, 'ACTION_foo');
156 foreach my $action (qw(foo bar)) { # typical usage
157 my $doc = $mb->get_action_docs($action);
158 ok($doc, "got doc for '$action'");
159 like($doc, qr/^=\w+ $action\n\nDoes the $action thing\./s,
160 'got the right doc');
162 is($mb->get_action_docs('baz'), undef, 'no jumping =head1 sections');
164 } # end =item style without spanning =head1's
166 ########################################################################
167 TODO: { # the =item style with 'Actions' not 'ACTIONS'
168 local $TODO = 'Support capitalized Actions section';
169 my $mb = Module::Build->subclass(
170 code => join "\n", map {s/^ {4}//; $_} split /\n/, <<' ---',
187 sub ACTION_foo { die "fooey" }
188 sub ACTION_bar { die "barey" }
192 module_name => $dist->name,
195 foreach my $action (qw(foo bar)) { # typical usage
196 my $doc = $mb->get_action_docs($action);
197 ok($doc, "got doc for '$action'");
198 like($doc || 'undef', qr/^=\w+ $action\n\nDoes the $action thing\./s,
199 'got the right doc');
202 } # end =item style with Actions
204 ########################################################################
205 { # check the =head2 style
206 my $mb = Module::Build->subclass(
207 code => join "\n", map {s/^ {4}//; $_} split /\n/, <<' ---',
220 Be careful with bears.
224 sub ACTION_foo { die "fooey" }
225 sub ACTION_bar { die "barey" }
226 sub ACTION_baz { die "bazey" }
227 sub ACTION_batz { die "batzey" }
229 # guess we can have extra pod later
230 # Though, I do wonder whether we should allow them to mix...
231 # maybe everything should have to be head2?
241 This is level 1, so the stuff about baz is done.
247 This is not an action doc.
253 module_name => $dist->name,
258 bar => "\n=head3 bears\n\nBe careful with bears.\n",
259 baz => "\n=head4 What's a baz\\?\n",
262 foreach my $action (qw(foo bar baz)) {
263 my $doc = $mb->get_action_docs($action);
264 ok($doc, "got doc for '$action'");
265 my $and = $also{$action};
266 like($doc || 'undef',
267 qr/^=\w+ $action\n\nDoes the $action thing\.\n$and\n$/s,
268 'got the right doc');
270 is($mb->get_action_docs('batz'), undef, 'nothing after uplevel');
273 ########################################################################
278 File::Path::rmtree( $tmp );
280 # vim:ts=2:sw=2:et:sta