Commit | Line | Data |
8ebc5c01 |
1 | #!./perl |
2 | |
3 | BEGIN { |
4 | chdir 't' if -d 't'; |
20822f61 |
5 | @INC = '../lib'; |
2246ee03 |
6 | $INC{"feature.pm"} = 1; # so we don't attempt to load feature.pm |
8ebc5c01 |
7 | } |
8 | |
3cacfbb9 |
9 | print "1..59\n"; |
8ebc5c01 |
10 | |
6a4a49dd |
11 | # Can't require test.pl, as we're testing the use/require mechanism here. |
12 | |
13 | my $test = 1; |
14 | |
15 | sub _ok { |
16 | my ($type, $got, $expected, $name) = @_; |
17 | |
6a4a49dd |
18 | my $result; |
19 | if ($type eq 'is') { |
20 | $result = $got eq $expected; |
21 | } elsif ($type eq 'isnt') { |
22 | $result = $got ne $expected; |
23 | } elsif ($type eq 'like') { |
24 | $result = $got =~ $expected; |
25 | } else { |
26 | die "Unexpected type '$type'$name"; |
27 | } |
28 | if ($result) { |
3cacfbb9 |
29 | if ($name) { |
30 | print "ok $test - $name\n"; |
31 | } else { |
32 | print "ok $test\n"; |
33 | } |
6a4a49dd |
34 | } else { |
3cacfbb9 |
35 | if ($name) { |
36 | print "not ok $test - $name\n"; |
37 | } else { |
38 | print "not ok $test\n"; |
39 | } |
40 | my @caller = caller(2); |
41 | print "# Failed test at $caller[1] line $caller[2]\n"; |
6a4a49dd |
42 | print "# Got '$got'\n"; |
43 | if ($type eq 'is') { |
44 | print "# Expected '$expected'\n"; |
45 | } elsif ($type eq 'isnt') { |
46 | print "# Expected not '$expected'\n"; |
47 | } elsif ($type eq 'like') { |
48 | print "# Expected $expected\n"; |
49 | } |
50 | } |
51 | $test = $test + 1; |
52 | $result; |
9f3d182e |
53 | } |
8ebc5c01 |
54 | |
6a4a49dd |
55 | sub like ($$;$) { |
56 | _ok ('like', @_); |
57 | } |
58 | sub is ($$;$) { |
59 | _ok ('is', @_); |
60 | } |
61 | sub isnt ($$;$) { |
62 | _ok ('isnt', @_); |
8ebc5c01 |
63 | } |
6a4a49dd |
64 | |
65 | eval "use 5.000"; # implicit semicolon |
66 | is ($@, ''); |
67 | |
68 | eval "use 5.000;"; |
69 | is ($@, ''); |
8ebc5c01 |
70 | |
468aa647 |
71 | eval "use 6.000;"; |
6a4a49dd |
72 | like ($@, qr/Perl v6\.0\.0 required--this is only \Q$^V\E, stopped/); |
468aa647 |
73 | |
74 | eval "no 6.000;"; |
6a4a49dd |
75 | is ($@, ''); |
468aa647 |
76 | |
77 | eval "no 5.000;"; |
6a4a49dd |
78 | like ($@, qr/Perls since v5\.0\.0 too modern--this is \Q$^V\E, stopped/); |
468aa647 |
79 | |
6d2c9499 |
80 | eval sprintf "use %.6f;", $]; |
6a4a49dd |
81 | is ($@, ''); |
8ebc5c01 |
82 | |
83 | |
6d2c9499 |
84 | eval sprintf "use %.6f;", $] - 0.000001; |
6a4a49dd |
85 | is ($@, ''); |
8ebc5c01 |
86 | |
6d2c9499 |
87 | eval sprintf("use %.6f;", $] + 1); |
6a4a49dd |
88 | like ($@, qr/Perl v6.\d+.\d+ required--this is only \Q$^V\E, stopped/); |
8ebc5c01 |
89 | |
6d2c9499 |
90 | eval sprintf "use %.6f;", $] + 0.00001; |
6a4a49dd |
91 | like ($@, qr/Perl v5.\d+.\d+ required--this is only \Q$^V\E, stopped/); |
8ebc5c01 |
92 | |
18b09519 |
93 | { use lib } # check that subparse saves pending tokens |
8ebc5c01 |
94 | |
95 | local $lib::VERSION = 1.0; |
96 | |
97 | eval "use lib 0.9"; |
6a4a49dd |
98 | is ($@, ''); |
8ebc5c01 |
99 | |
100 | eval "use lib 1.0"; |
6a4a49dd |
101 | is ($@, ''); |
8ebc5c01 |
102 | |
103 | eval "use lib 1.01"; |
6a4a49dd |
104 | isnt ($@, ''); |
8ebc5c01 |
105 | |
106 | |
107 | eval "use lib 0.9 qw(fred)"; |
6a4a49dd |
108 | is ($@, ''); |
8ebc5c01 |
109 | |
6a4a49dd |
110 | if ($^O eq 'MacOS') { |
111 | is($INC[0], ":fred:"); |
112 | } else { |
113 | is($INC[0], "fred"); |
114 | } |
8ebc5c01 |
115 | |
116 | eval "use lib 1.0 qw(joe)"; |
6a4a49dd |
117 | is ($@, ''); |
118 | |
119 | |
120 | if ($^O eq 'MacOS') { |
121 | is($INC[0], ":joe:"); |
122 | } else { |
123 | is($INC[0], "joe"); |
8ebc5c01 |
124 | } |
8ebc5c01 |
125 | |
8ebc5c01 |
126 | |
127 | eval "use lib 1.01 qw(freda)"; |
6a4a49dd |
128 | isnt($@, ''); |
8ebc5c01 |
129 | |
6a4a49dd |
130 | if ($^O eq 'MacOS') { |
131 | isnt($INC[0], ":freda:"); |
132 | } else { |
133 | isnt($INC[0], "freda"); |
134 | } |
1571675a |
135 | |
136 | { |
137 | local $lib::VERSION = 35.36; |
138 | eval "use lib v33.55"; |
6a4a49dd |
139 | is ($@, ''); |
1571675a |
140 | |
141 | eval "use lib v100.105"; |
ac0e6a2f |
142 | like ($@, qr/lib version v100.105.0 required--this is only version v35\.360\.0/); |
1571675a |
143 | |
144 | eval "use lib 33.55"; |
6a4a49dd |
145 | is ($@, ''); |
1571675a |
146 | |
147 | eval "use lib 100.105"; |
8cb289bd |
148 | like ($@, qr/lib version 100.105 required--this is only version 35.36/); |
1571675a |
149 | |
150 | local $lib::VERSION = '35.36'; |
151 | eval "use lib v33.55"; |
6a4a49dd |
152 | like ($@, ''); |
1571675a |
153 | |
154 | eval "use lib v100.105"; |
ac0e6a2f |
155 | like ($@, qr/lib version v100.105.0 required--this is only version v35\.360\.0/); |
1571675a |
156 | |
157 | eval "use lib 33.55"; |
6a4a49dd |
158 | is ($@, ''); |
1571675a |
159 | |
160 | eval "use lib 100.105"; |
8cb289bd |
161 | like ($@, qr/lib version 100.105 required--this is only version 35.36/); |
1571675a |
162 | |
163 | local $lib::VERSION = v35.36; |
164 | eval "use lib v33.55"; |
6a4a49dd |
165 | is ($@, ''); |
1571675a |
166 | |
167 | eval "use lib v100.105"; |
ac0e6a2f |
168 | like ($@, qr/lib version v100.105.0 required--this is only version v35\.36\.0/); |
1571675a |
169 | |
170 | eval "use lib 33.55"; |
6a4a49dd |
171 | is ($@, ''); |
1571675a |
172 | |
173 | eval "use lib 100.105"; |
8cb289bd |
174 | like ($@, qr/lib version 100.105 required--this is only version v35.36/); |
1571675a |
175 | } |
8312d5ee |
176 | |
177 | |
178 | { |
179 | # Regression test for patch 14937: |
180 | # Check that a .pm file with no package or VERSION doesn't core. |
181 | open F, ">xxx.pm" or die "Cannot open xxx.pm: $!\n"; |
182 | print F "1;\n"; |
183 | close F; |
184 | eval "use lib '.'; use xxx 3;"; |
6a4a49dd |
185 | like ($@, qr/^xxx defines neither package nor VERSION--version check failed at/); |
8312d5ee |
186 | unlink 'xxx.pm'; |
187 | } |
3cacfbb9 |
188 | |
189 | my @ver = split /\./, sprintf "%vd", $^V; |
190 | |
191 | foreach my $index (-3..+3) { |
192 | foreach my $v (0, 1) { |
193 | my @parts = @ver; |
194 | if ($index) { |
195 | if ($index < 0) { |
196 | # Jiggle one of the parts down |
197 | --$parts[-$index - 1]; |
198 | } else { |
199 | # Jiggle one of the parts up |
200 | ++$parts[$index - 1]; |
201 | } |
202 | } |
203 | my $v_version = sprintf "v%d.%d.%d", @parts; |
204 | my $version; |
205 | if ($v) { |
206 | $version = $v_version; |
207 | } else { |
208 | $version = $parts[0] + $parts[1] / 1000 + $parts[2] / 1000000; |
209 | } |
210 | |
211 | eval "use $version"; |
212 | if ($index > 0) { |
213 | # The future |
214 | like ($@, |
215 | qr/Perl $v_version required--this is only \Q$^V\E, stopped/, |
216 | "use $version"); |
217 | } else { |
218 | # The present or past |
219 | is ($@, '', "use $version"); |
220 | } |
221 | |
222 | eval "no $version"; |
223 | if ($index <= 0) { |
224 | # The present or past |
225 | like ($@, |
226 | qr/Perls since $v_version too modern--this is \Q$^V\E, stopped/, |
227 | "no $version"); |
228 | } else { |
229 | # future |
230 | is ($@, '', "no $version"); |
231 | } |
232 | } |
233 | } |
234 | |