File: 01..module.t

package info (click to toggle)
libmodule-util-perl 1.09-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 132 kB
  • sloc: perl: 243; makefile: 2
file content (101 lines) | stat: -rw-r--r-- 3,140 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
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
use strict;
use warnings;

use File::Spec::Functions qw( catfile catdir );
use Test::More tests => 44;

our $module;
BEGIN {
    $module = "Module::Util";
    use_ok($module, qw( :all ));
}

my $moduledir = $ENV{AUTOPKGTEST_TMP} ? '/usr/share/perl5' : 'lib';

ok(is_valid_module_name($module), 'is_valid_module_name');
ok(find_installed($module),       "find_installed");

my @expected_parts = qw( Module Util.pm );

my $path = module_path($module);

ok(exists($INC{$path}), 'module_path agress with %INC');
is_deeply([module_path_parts($module)], \@expected_parts,
        'module_path_parts()');

is(module_path($path), undef, 'module_path($path) is undef');
ok(!is_valid_module_name($path), 'a path is not a valid module name');
ok(!find_installed($path),       'a path is not a valid module');
is(path_to_module($path), $module, "path_to_module($path) == $module");

$path = module_fs_path($module);
ok($path, "module_fs_path($module)");
is(fs_path_to_module($path), $module, "fs_path_to_module($path) == $module");

is(canonical_module_name("Acme::Don't"), 'Acme::Don::t', "Acme::Don't");

# Module names mustn't have leading or trailing '::' or leading numbers
my @invalid = qw(
        ::
        ::My::Module
        My::Module::
        3l337::M0d3wl
    );

for my $invalid (@invalid) {
    ok(!is_valid_module_name($invalid), "'$invalid' is not valid");
    ok(!find_installed($invalid),       "'$invalid' is not a module");
    ok(!module_path($invalid),          "'$invalid' has no path");
    ok(!module_fs_path($invalid),       "'$invalid' has no fs path");
}

ok(module_is_loaded($module), "Module::Util is loaded");
ok(!module_is_loaded("::Invalid"), "::Invalid is not loaded");

ok(!find_installed($module, 't/lib'), "Module::Util not found in t/lib");

is(all_installed($module, $moduledir), 1, "Module::Util only found once in lib");
is(all_installed("::Invalid"), 0, "::Invalid is not installed at all");

{
    my @in_ns;
    my $dir = catdir(qw( t data ));
    @in_ns = find_in_namespace('NS', $dir);
    is_deeply(\@in_ns, ['NS::One'], 'find_in_namespace');

    @in_ns = find_in_namespace('', $dir);
    is_deeply([ sort @in_ns ], ['NS2::One', 'NS::One'], 'find_in_namespace');

    for my $invalid (@invalid) {
        ok(!find_in_namespace($invalid), "'$invalid' is not a valid namespace");
    }
}

$path = catfile($moduledir, module_fs_path($module)) || '';
ok(-f $path, "'$path' exists");

# path_to_module should fail when given a module name
ok(!path_to_module($module), "path_to_module($module) fails");

# should fail on an absolute path too.
$path = find_installed($module) || '';
ok(!path_to_module($path), "path_to_module($path) fails");

my @parts = module_name_parts( 'One::Two::Three' );
is_deeply( \@parts, [qw(One Two Three)] );

SKIP: {
    skip "No warnings suppression on perl < 5.8", 1 unless $] >= 5.008;

    my @warnings;
    local $SIG{__WARN__} = sub { push @warnings, @_ };

    find_in_namespace('', catdir(qw( fake path )));
    ok !@warnings, 'no warnings generated when searching in missing path'
        or diag join("\n", @warnings);
}


__END__

vim: ft=perl ts=8 sts=4 sw=4 sr et