4 use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
5 use MBTest 'no_plan';#tests => 0;
11 my $tmp = File::Spec->catdir($cwd, 't', '_tmp');
15 my $dist = DistGen->new(dir => $tmp);
23 File::Path::rmtree( $tmp );
24 # we're redefining the same package as we go, so...
25 delete($::{'MyModuleBuilder::'});
26 delete($INC{'MyModuleBuilder.pm'});
28 chdir($dist->dirname) or
29 die "Can't chdir to '@{[$dist->dirname]}': $!";
32 chdir($dist->dirname) or die "Can't chdir to '@{[$dist->dirname]}': $!";
34 use_ok 'Module::Build';
36 ########################################################################
37 { # check the =item style
38 my $mb = Module::Build->subclass(
39 code => join "\n", map {s/^ {4}//; $_} split /\n/, <<' ---',
56 You should probably not be seeing this. That is, we haven't
57 overridden the help action, but we're able to override just the
58 docs? That almost seems reasonable, but is probably wrong.
64 sub ACTION_foo { die "fooey" }
65 sub ACTION_bar { die "barey" }
66 sub ACTION_baz { die "bazey" }
68 # guess we can have extra pod later
82 module_name => $dist->name,
86 can_ok($mb, 'ACTION_foo');
88 foreach my $action (qw(foo bar baz)) { # typical usage
89 my $doc = $mb->get_action_docs($action);
90 ok($doc, "got doc for '$action'");
91 like($doc, qr/^=\w+ $action\n\nDoes the $action thing\./s,
95 { # user typo'd the action name
96 ok( ! eval {$mb->get_action_docs('batz'); 1}, 'slap');
97 like($@, qr/No known action 'batz'/, 'informative error');
100 { # XXX this one needs some thought
102 my $doc = $mb->get_action_docs($action);
103 ok($doc, "got doc for '$action'");
104 0 and warn "help doc >\n$doc<\n";
106 local $TODO = 'Do we allow overrides on just docs?';
107 unlike($doc, qr/^=\w+ $action\n\nDoes the $action thing\./s,
108 'got the right doc');
113 ########################################################################
114 if(0) { # the =item style without spanning =head1 sections
115 my $mb = Module::Build->subclass(
116 code => join "\n", map {s/^ {4}//; $_} split /\n/, <<' ---',
143 sub ACTION_foo { die "fooey" }
144 sub ACTION_bar { die "barey" }
145 sub ACTION_baz { die "bazey" }
149 module_name => $dist->name,
153 can_ok($mb, 'ACTION_foo');
155 foreach my $action (qw(foo bar)) { # typical usage
156 my $doc = $mb->get_action_docs($action);
157 ok($doc, "got doc for '$action'");
158 like($doc, qr/^=\w+ $action\n\nDoes the $action thing\./s,
159 'got the right doc');
161 is($mb->get_action_docs('baz'), undef, 'no jumping =head1 sections');
163 } # end =item style without spanning =head1's
165 ########################################################################
166 TODO: { # the =item style with 'Actions' not 'ACTIONS'
167 local $TODO = 'Support capitalized Actions section';
168 my $mb = Module::Build->subclass(
169 code => join "\n", map {s/^ {4}//; $_} split /\n/, <<' ---',
186 sub ACTION_foo { die "fooey" }
187 sub ACTION_bar { die "barey" }
191 module_name => $dist->name,
194 foreach my $action (qw(foo bar)) { # typical usage
195 my $doc = $mb->get_action_docs($action);
196 ok($doc, "got doc for '$action'");
197 like($doc || 'undef', qr/^=\w+ $action\n\nDoes the $action thing\./s,
198 'got the right doc');
201 } # end =item style with Actions
203 ########################################################################
204 { # check the =head2 style
205 my $mb = Module::Build->subclass(
206 code => join "\n", map {s/^ {4}//; $_} split /\n/, <<' ---',
219 Be careful with bears.
223 sub ACTION_foo { die "fooey" }
224 sub ACTION_bar { die "barey" }
225 sub ACTION_baz { die "bazey" }
226 sub ACTION_batz { die "batzey" }
228 # guess we can have extra pod later
229 # Though, I do wonder whether we should allow them to mix...
230 # maybe everything should have to be head2?
240 This is level 1, so the stuff about baz is done.
246 This is not an action doc.
252 module_name => $dist->name,
257 bar => "\n=head3 bears\n\nBe careful with bears.\n",
258 baz => "\n=head4 What's a baz\\?\n",
261 foreach my $action (qw(foo bar baz)) {
262 my $doc = $mb->get_action_docs($action);
263 ok($doc, "got doc for '$action'");
264 my $and = $also{$action};
265 like($doc || 'undef',
266 qr/^=\w+ $action\n\nDoes the $action thing\.\n$and\n$/s,
267 'got the right doc');
269 is($mb->get_action_docs('batz'), undef, 'nothing after uplevel');
272 ########################################################################
277 File::Path::rmtree( $tmp );
279 # vim:ts=2:sw=2:et:sta