Skip to content

Commit 4e02af9

Browse files
committed
Allow for testing snippets on .pod files
Not just `.pm` files.
1 parent ed6466e commit 4e02af9

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

xt/author/pod-snippets.t

+26-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use strict;
44
use warnings;
55
use Test::More;
66
use Test::Pod::Snippets;
7+
use With::Roles;
78

89
my @modules = qw/
910
AI::TensorFlow::Libtensorflow
@@ -16,6 +17,30 @@ my @modules = qw/
1617

1718
plan tests => 0 + @modules;
1819

20+
package # hide from PAUSE
21+
Test::Pod::Snippets::Role::PodLocatable {
22+
23+
use Moose::Role;
24+
use Pod::Simple::Search;
25+
26+
around _parse => sub {
27+
my $orig = shift;
28+
my ($self, $type, $input) = @_;
29+
30+
my $output = eval { $orig->(@_); };
31+
my $error = $@;
32+
if( $error =~ /not found in \@INC/ && $type eq 'module' ) {
33+
my $pod_file = Pod::Simple::Search->new->find($input);
34+
if( -f $pod_file ) {
35+
return $orig->($self, 'file', $pod_file )
36+
} else {
37+
die "$error\nUnable to find POD file for $input\n";
38+
}
39+
}
40+
41+
return $output;
42+
};
43+
}
1944

2045
package # hide from PAUSE
2146
My::Test::Pod::Snippets::Parser {
@@ -38,7 +63,7 @@ package # hide from PAUSE
3863

3964
for (@modules) {
4065
my $parser = My::Test::Pod::Snippets::Parser->new;
41-
my $tps = Test::Pod::Snippets->new(
66+
my $tps = Test::Pod::Snippets->with::roles('+PodLocatable')->new(
4267
parser => $parser,
4368
);
4469
$parser->{tps} = $tps;

0 commit comments

Comments
 (0)