File: ivms.t

package info (click to toggle)
libmodule-runtime-perl 0.018-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 292 kB
  • sloc: perl: 264; makefile: 2
file content (82 lines) | stat: -rw-r--r-- 2,193 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
use warnings;
use strict;

use Test::More tests => 140;

BEGIN { use_ok "Module::Runtime", qw(
    $top_module_spec_rx $sub_module_spec_rx
    is_module_spec is_valid_module_spec check_module_spec
); }

ok \&is_valid_module_spec == \&is_module_spec;

foreach my $spec (
    undef,
    *STDOUT,
    \"Foo",
    [],
    {},
    sub{},
) {
    ok(!is_module_spec(0, $spec), "non-string is bad (function)");
    eval { check_module_spec(0, $spec) }; isnt $@, "";
    ok(!is_module_spec(1, $spec), "non-string is bad (function)");
    eval { check_module_spec(1, $spec) }; isnt $@, "";
}

foreach my $spec (qw(
    Foo
    foo::bar
    foo::123::x_0
    foo/bar
    foo/123::x_0
    foo::123/x_0
    foo/123/x_0
    /Foo
    /foo/bar
    ::foo/bar
)) {
    ok(is_module_spec(0, $spec), "`$spec' is always good (function)");
    eval { check_module_spec(0, $spec) }; is $@, "";
    ok($spec =~ qr/\A$top_module_spec_rx\z/,
        "`$spec' is always good (regexp)");
    ok(is_module_spec(1, $spec), "`$spec' is always good (function)");
    eval { check_module_spec(1, $spec) }; is $@, "";
    ok($spec =~ qr/\A$sub_module_spec_rx\z/,
        "`$spec' is always good (regexp)");
}

foreach my $spec (qw(
    foo'bar
    IO::
    foo::::bar
    /foo/
    /1foo
    ::foo::
    ::1foo
)) {
    ok(!is_module_spec(0, $spec), "`$spec' is always bad (function)");
    eval { check_module_spec(0, $spec) }; isnt $@, "";
    ok($spec !~ qr/\A$top_module_spec_rx\z/,
        "`$spec' is always bad (regexp)");
    ok(!is_module_spec(1, $spec), "`$spec' is always bad (function)");
    eval { check_module_spec(1, $spec) }; isnt $@, "";
    ok($spec !~ qr/\A$sub_module_spec_rx\z/,
        "`$spec' is always bad (regexp)");
}

foreach my $spec (qw(
    1foo
    0/1
)) {
    ok(!is_module_spec(0, $spec), "`$spec' needs a prefix (function)");
    eval { check_module_spec(0, $spec) }; isnt $@, "";
    ok($spec !~ qr/\A$top_module_spec_rx\z/,
        "`$spec' needs a prefix (regexp)");
    ok(is_module_spec(1, $spec), "`$spec' needs a prefix (function)");
    eval { check_module_spec(1, $spec) }; is $@, "";
    ok($spec =~ qr/\A$sub_module_spec_rx\z/,
        "`$spec' needs a prefix (regexp)");
}

1;