Debian Codegraph @

t/rt/79273.t

raw
1 #!/usr/bin/perl
2 use strict;
3
4 use Test::More tests => 6;
5 use File::Basename;
6 use File::Spec::Functions qw(catfile);
7
8 my $class = "Module::Extract::Use";
9 use_ok( $class );
10
11 my $extor = $class->new;
12 isa_ok( $extor, $class );
13 can_ok( $extor, 'get_modules_with_details' );
14
15
16 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
17 # Try it with a file that has repeated use lines
18 # I should only get unique names
19 {
20 my $file = catfile( qw(corpus RT79273.pm) );
21 ok( -e $file, "Test file [$file] is there" );
22
23 my $details = $extor->get_modules_with_details( $file );
24 is( scalar @$details, 3, 'There are the right number of hits' );
25
26 is_deeply( $details, expected(), 'The data structures match' );
27 }
28
29 sub expected {
30 return [
31 {
32 'direct' => 1,
33 'content' => q(use parent 'CGI::Snapp';),
34 'pragma' => 'parent',
35 'version' => undef,
36 'imports' => [qw(CGI::Snapp)],
37 'module' => 'parent'
38 },
39 {
40 'direct' => 1,
41 'content' => q(use Capture::Tiny 'capture';),
42 'pragma' => '',
43 'version' => undef,
44 'imports' => [qw(capture)],
45 'module' => 'Capture::Tiny'
46 },
47 {
48 'direct' => 0,
49 'content' => 'use parent \'CGI::Snapp\';',
50 'pragma' => '',
51 'version' => undef,
52 'imports' => [],
53 'module' => 'CGI::Snapp'
54 },
55 ];
56 }