Skip to content

Commit 52e17f7

Browse files
committed
add File method to detect test directories
1 parent cdad695 commit 52e17f7

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/MetaCPAN/Document/File.pm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,17 @@ sub is_pod_file {
623623
shift->name =~ /\.pod$/i;
624624
}
625625

626+
=head2 in_test_directory
627+
628+
Returns true if the file is below a t directory.
629+
630+
=cut
631+
632+
sub in_test_directory {
633+
my $self = shift;
634+
return ( $self->path =~ /(^|\/)t($|\/)/ ? 1 : 0 );
635+
}
636+
626637
=head2 add_module
627638
628639
Requires at least one parameter which can be either a HashRef or

t/document/file.t

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@ my %stub = (
1212
name => 'module.pm',
1313
);
1414

15+
{
16+
my %paths = (
17+
't/whomp' => 1,
18+
'foo/t/bar' => 1,
19+
'cuppa/t' => 1,
20+
'foo/bart/shorts' => 0,
21+
'tit/mouse' => 0,
22+
'say/wat' => 0,
23+
);
24+
25+
foreach my $path ( keys %paths ) {
26+
my $file = MetaCPAN::Document::File->new( %stub, path => $path );
27+
my $bool = $paths{$path} ? 'is' : 'is not';
28+
is( $file->in_test_directory(),
29+
$paths{$path}, "$path $bool in a test directory" );
30+
}
31+
}
32+
1533
{
1634
my $content = <<'END';
1735
package Foo;

0 commit comments

Comments
 (0)