File: 22_eval.t

package info (click to toggle)
libmodule-extractuse-perl 0.344-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 868 kB
  • sloc: perl: 11,270; makefile: 17
file content (148 lines) | stat: -rw-r--r-- 4,448 bytes parent folder | download | duplicates (4)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
use Test::More tests => 48;

use strict;
use warnings;

use Module::ExtractUse;

{
    my $semi   = 'eval "use Test::Pod 1.00;";';
    my $p = Module::ExtractUse->new;
    $p->extract_use( \$semi );

    ok( $p->used( 'Test::Pod' ) );
    ok( $p->used_in_eval( 'Test::Pod' ) );
    ok(!$p->used_out_of_eval( 'Test::Pod' ) );
}

{
    my $nosemi = "eval 'use Test::Pod 1.00';";
    my $p = Module::ExtractUse->new;
    $p->extract_use( \$nosemi );

    ok( $p->used( 'Test::Pod' ) );
    ok( $p->used_in_eval( 'Test::Pod' ) );
    ok(!$p->used_out_of_eval( 'Test::Pod' ) );
}

{
    my $qq = "eval qq{use Test::Pod 1.00}";
    my $p = Module::ExtractUse->new;
    $p->extract_use( \$qq );
    ok( $p->used( 'Test::Pod' ), 'qq brace' );
    ok( $p->used_in_eval( 'Test::Pod' ), 'qq brace' );
    ok(!$p->used_out_of_eval( 'Test::Pod' ), 'qq brace' );
}

{
    my $qq = "eval qq+use Test::Pod+";
    my $p = Module::ExtractUse->new;
    $p->extract_use( \$qq );
    ok( $p->used( 'Test::Pod' ), 'qq plus' );
    ok( $p->used_in_eval( 'Test::Pod' ), 'qq plus' );
    ok(!$p->used_out_of_eval( 'Test::Pod' ), 'qq plus' );
}

{
    my $qq = "eval qq(use Test::Pod)";
    my $p = Module::ExtractUse->new;
    $p->extract_use( \$qq );
    ok( $p->used( 'Test::Pod' ), 'qq paren' );
    ok( $p->used_in_eval( 'Test::Pod' ), 'qq paren' );
    ok(!$p->used_out_of_eval( 'Test::Pod' ), 'qq paren' );
}

{
    my $q = "eval q< use Test::Pod>";
    my $p = Module::ExtractUse->new;
    $p->extract_use( \$q );
    ok( $p->used( 'Test::Pod' ), 'q angle' );
    ok( $p->used_in_eval( 'Test::Pod' ), 'q angle' );
    ok(!$p->used_out_of_eval( 'Test::Pod' ), 'q angle' );
}

{
    my $q = "eval  q/use Test::Pod/";
    my $p = Module::ExtractUse->new;
    $p->extract_use( \$q );
    ok( $p->used( 'Test::Pod' ), 'q slash' );
    ok( $p->used_in_eval( 'Test::Pod' ), 'q slash' );
    ok(!$p->used_out_of_eval( 'Test::Pod' ), 'q slash' );
}

# reported by DAGOLDEN@cpan.org as [rt.cpan.org #19302]
{
    my $varversion = q{my $ver=1.22;
eval "use Test::Pod $ver;"};
    my $p = Module::ExtractUse->new;
    $p->extract_use( \$varversion );

    ok( $p->used( 'Test::Pod' ) );
    ok( $p->used_in_eval( 'Test::Pod' ) );
    ok(!$p->used_out_of_eval( 'Test::Pod' ) );
}

{
    my $varversion = q{my $ver=1.22;
eval 'use Test::Pod $ver';};
    my $p = Module::ExtractUse->new;
    $p->extract_use( \$varversion );

    ok( $p->used( 'Test::Pod' ) );
    ok( $p->used_in_eval( 'Test::Pod' ) );
    ok(!$p->used_out_of_eval( 'Test::Pod' ) );
}


{
    my $semi   = 'eval"use Test::Pod 1.00;";';
    my $p = Module::ExtractUse->new;
    $p->extract_use( \$semi );

    ok( $p->used( 'Test::Pod' ), 'no spaces between eval and expr with semicolon' );
    ok( $p->used_in_eval( 'Test::Pod' ) );
    ok(!$p->used_out_of_eval( 'Test::Pod' ) );
}

{
    my $nosemi = "eval'use Test::Pod 1.00';";
    my $p = Module::ExtractUse->new;
    $p->extract_use( \$nosemi );

    ok( $p->used( 'Test::Pod' ), 'no spaces between eval and expr w/o semicolon' );
    ok( $p->used_in_eval( 'Test::Pod' ) );
    ok(!$p->used_out_of_eval( 'Test::Pod' ) );
}

{
    my $q = "eval { use Test::Pod }";
    my $p = Module::ExtractUse->new;
    $p->extract_use( \$q );
    ok( $p->used( 'Test::Pod' ), 'block' );
    ok( $p->used_in_eval( 'Test::Pod' ), 'block' );
    ok(!$p->used_out_of_eval( 'Test::Pod' ), 'block' );
}

{
    my $q = "eval { use Test::Pod; { use Test::Pod::Coverage; } }";
    my $p = Module::ExtractUse->new;
    $p->extract_use( \$q );
    ok( $p->used( 'Test::Pod' ), 'block in block 1' );
    ok( $p->used_in_eval( 'Test::Pod' ), 'block in block 1' );
    ok(!$p->used_out_of_eval( 'Test::Pod' ), 'block in block 1' );
    ok( $p->used( 'Test::Pod::Coverage' ), 'block in block 1' );
    ok( $p->used_in_eval( 'Test::Pod::Coverage' ), 'block in block 1' );
    ok(!$p->used_out_of_eval( 'Test::Pod::Coverage' ), 'block in block 1' );
}

{
    my $q = "eval { { use Test::Pod; } use Test::Pod::Coverage }";
    my $p = Module::ExtractUse->new;
    $p->extract_use( \$q );
    ok( $p->used( 'Test::Pod' ), 'block in block 2' );
    ok( $p->used_in_eval( 'Test::Pod' ), 'block in block 2' );
    ok(!$p->used_out_of_eval( 'Test::Pod' ), 'block in block 2' );
    ok( $p->used( 'Test::Pod::Coverage' ), 'block in block 2' );
    ok( $p->used_in_eval( 'Test::Pod::Coverage' ), 'block in block 2' );
    ok(!$p->used_out_of_eval( 'Test::Pod::Coverage' ), 'block in block 2' );
}