File: lexically.t

package info (click to toggle)
libdevel-hide-perl 0.0015-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 152 kB
  • sloc: perl: 211; makefile: 2
file content (66 lines) | stat: -rw-r--r-- 1,583 bytes parent folder | download | duplicates (2)
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
use strict;
use warnings;

BEGIN {
    require Test::More;
    $] < 5.010
        ? Test::More->import(skip_all => "perl too old")
        : Test::More->import(tests => 9);
}

use lib 't';

my @expected_warnings;
BEGIN {
    push @expected_warnings,
        'Devel::Hide hides R.pm',
        'Devel::Hide hides Q.pm';
    $SIG{__WARN__} = sub {
        if(!@expected_warnings) {
            fail("Got unexpected warning '$_[0]'")
        } else {
            is($_[0], shift(@expected_warnings)."\n",
                "got expected warning: $_[0]");
        }
    }
}
END { ok(!@expected_warnings, "got all expected warnings") }

# hide R globally
use Devel::Hide qw(R);
note("R hidden globally, and noisily");

eval { require R }; 
like($@, qr/^Can't locate R\.pm in \@INC/,
    "correctly moaned about hiding R (globally)");

{
    use Devel::Hide qw(-lexically -quiet Q.pm);
    note("Q hidden lexically, quietly");

    eval { require Q }; 
    like($@, qr/^Can't locate Q\.pm in \@INC/,
        "correctly moaned about loading Q");

    eval { require R }; 
    like($@, qr/^Can't locate R\.pm in \@INC/,
        "still can't load R which is globally hidden");
}

{
    use Devel::Hide qw(-lexically Q);
    note("Q hidden in a different scope, noisily");

    eval { require Q }; 
    like($@, qr/^Can't locate Q\.pm in \@INC/,
        "correctly moaned about loading Q");
}

note("Now we're outside that lexical scope");

eval { require Q };
ok(!$@, "nothing moaned about loading Q");

eval { require R }; 
like($@, qr/^Can't locate R\.pm in \@INC/,
    "still can't load R");