File: versions.t

package info (click to toggle)
libmodule-extract-use-perl 1.047-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 184 kB
  • sloc: perl: 572; makefile: 2
file content (70 lines) | stat: -rwxr-xr-x 1,733 bytes parent folder | download
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
#!/usr/bin/perl
use strict;

use Test::More 1.0;
use File::Basename;
use File::Spec::Functions qw(catfile);

my $class = "Module::Extract::Use";
use_ok( $class );

my $extor = $class->new;
isa_ok( $extor, $class );
can_ok( $extor, 'get_modules_with_details' );


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Try it with a file that has repeated use lines
# I should only get unique names
{
my $file = catfile( qw(corpus PackageVersion.pm) );
ok( -e $file, "Test file [$file] is there" );

my $details = $extor->get_modules_with_details( $file );
is( scalar @$details, 3 );

my $first = $details->[0];
foreach my $key ( keys %$first ) {
	can_ok( $first, $key );
	}
is( $first->direct,     1            );
like( $first->content,  qr/\Ause\b/  );
ok( ! $first->pragma                 );
is( $first->version,    '1.23'       );
is( $first->module,     'HTTP::Size' );

is_deeply( $details, expected() );
}


sub expected {
	return  [
          {
            'direct'  => 1,
            'content' => 'use HTTP::Size 1.23;',
            'pragma'  => '',
            'version' => '1.23',
            'imports' => [],
            'module'  => 'HTTP::Size'
          },
          {
            'direct'  => 1,
            'content' => 'use YAML::Syck 1.54 qw(LoadFile);',
            'pragma'  => '',
            'version' => '1.54',
            'imports' => [ qw(LoadFile) ],
            'module'  => 'YAML::Syck'
          },
          {
            'direct'  => 1,
            'content' => 'use LWP::Simple 6.1 qw(getstore);',
            'pragma'  => '',
            'version' => '6.1',
            'imports' => [ qw(getstore) ],
            'module'  => 'LWP::Simple'
          }
        ];

	}

done_testing();