summaryrefslogtreecommitdiff
path: root/t/help.t
blob: 0534c92956068fc75b17cefdb8c703e3c37a1f64 (plain)
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#!/usr/bin/perl -w

use strict;
use lib 't/lib';
use MBTest tests => 23;

blib_load('Module::Build');

use DistGen;

my $dist = DistGen->new;
$dist->regen;
$dist->chdir_in;

my $restart = sub {
  # we're redefining the same package as we go, so...
  delete($::{'MyModuleBuilder::'});
  delete($INC{'MyModuleBuilder.pm'});
  $dist->regen( clean => 1 );
};

########################################################################
{ # check the =item style
my $mb = Module::Build->subclass(
  code => join "\n", map {s/^ {4}//; $_} split /\n/, <<'  ---',
    =head1 ACTIONS

    =over

    =item foo

    Does the foo thing.

    =item bar

    Does the bar thing.

    =item help

    Does the help thing.

    You should probably not be seeing this.  That is, we haven't
    overridden the help action, but we're able to override just the
    docs?  That almost seems reasonable, but is probably wrong.

    =back

    =cut

    sub ACTION_foo { die "fooey" }
    sub ACTION_bar { die "barey" }
    sub ACTION_baz { die "bazey" }

    # guess we can have extra pod later

    =over

    =item baz

    Does the baz thing.

    =back

    =cut

  ---
  )->new(
      module_name => $dist->name,
  );

ok $mb;
can_ok($mb, 'ACTION_foo');

foreach my $action (qw(foo bar baz)) { # typical usage
  my $doc = $mb->get_action_docs($action);
  ok($doc, "got doc for '$action'");
  like($doc, qr/^=\w+ $action\n\nDoes the $action thing\./s,
    'got the right doc');
}

{ # user typo'd the action name
  ok( ! eval {$mb->get_action_docs('batz'); 1}, 'slap');
  like($@, qr/No known action 'batz'/, 'informative error');
}

{ # XXX this one needs some thought
  my $action = 'help';
  my $doc = $mb->get_action_docs($action);
  ok($doc, "got doc for '$action'");
  0 and warn "help doc >\n$doc<\n";
  TODO: {
    local $TODO = 'Do we allow overrides on just docs?';
    unlike($doc, qr/^=\w+ $action\n\nDoes the $action thing\./s,
      'got the right doc');
  }
}
} # end =item style
$restart->();
########################################################################
if(0) { # the =item style without spanning =head1 sections
my $mb = Module::Build->subclass(
  code => join "\n", map {s/^ {4}//; $_} split /\n/, <<'  ---',
    =head1 ACTIONS

    =over

    =item foo

    Does the foo thing.

    =item bar

    Does the bar thing.

    =back

    =head1 thbbt

    =over

    =item baz

    Should not see this.

    =back

    =cut

    sub ACTION_foo { die "fooey" }
    sub ACTION_bar { die "barey" }
    sub ACTION_baz { die "bazey" }

  ---
  )->new(
      module_name => $dist->name,
  );

ok $mb;
can_ok($mb, 'ACTION_foo');

foreach my $action (qw(foo bar)) { # typical usage
  my $doc = $mb->get_action_docs($action);
  ok($doc, "got doc for '$action'");
  like($doc, qr/^=\w+ $action\n\nDoes the $action thing\./s,
    'got the right doc');
}
is($mb->get_action_docs('baz'), undef, 'no jumping =head1 sections');

} # end =item style without spanning =head1's
$restart->();
########################################################################
TODO: { # the =item style with 'Actions' not 'ACTIONS'
local $TODO = 'Support capitalized Actions section';
my $mb = Module::Build->subclass(
  code => join "\n", map {s/^ {4}//; $_} split /\n/, <<'  ---',
    =head1 Actions

    =over

    =item foo

    Does the foo thing.

    =item bar

    Does the bar thing.

    =back

    =cut

    sub ACTION_foo { die "fooey" }
    sub ACTION_bar { die "barey" }

  ---
  )->new(
      module_name => $dist->name,
  );

foreach my $action (qw(foo bar)) { # typical usage
  my $doc = $mb->get_action_docs($action);
  ok($doc, "got doc for '$action'");
  like($doc || 'undef', qr/^=\w+ $action\n\nDoes the $action thing\./s,
    'got the right doc');
}

} # end =item style with Actions
$restart->();
########################################################################
{ # check the =head2 style
my $mb = Module::Build->subclass(
  code => join "\n", map {s/^ {4}//; $_} split /\n/, <<'  ---',
    =head1 ACTIONS

    =head2 foo

    Does the foo thing.

    =head2 bar

    Does the bar thing.

    =head3 bears

    Be careful with bears.

    =cut

    sub ACTION_foo { die "fooey" }
    sub ACTION_bar { die "barey" }
    sub ACTION_baz { die "bazey" }
    sub ACTION_batz { die "batzey" }

    # guess we can have extra pod later
    # Though, I do wonder whether we should allow them to mix...
    # maybe everything should have to be head2?

    =head2 baz

    Does the baz thing.

    =head4 What's a baz?

    =head1 not this part

    This is level 1, so the stuff about baz is done.

    =head1 Thing

    =head2 batz

    This is not an action doc.

    =cut

  ---
  )->new(
      module_name => $dist->name,
  );

my %also = (
  foo => '',
  bar => "\n=head3 bears\n\nBe careful with bears.\n",
  baz => "\n=head4 What's a baz\\?\n",
);

foreach my $action (qw(foo bar baz)) {
  my $doc = $mb->get_action_docs($action);
  ok($doc, "got doc for '$action'");
  my $and = $also{$action};
  like($doc || 'undef',
    qr/^=\w+ $action\n\nDoes the $action thing\.\n$and\n$/s,
    'got the right doc');
}
is($mb->get_action_docs('batz'), undef, 'nothing after uplevel');

} # end =head2 style
########################################################################

# cleanup
$dist->clean();

# vim:ts=2:sw=2:et:sta