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 | |
5cc917d6 |
9 | print "1..68\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 | |
d1029faa |
80 | eval "use 5.6;"; |
81 | like ($@, qr/Perl v5\.600\.0 required \(did you mean v5\.6\.0\?\)--this is only \Q$^V\E, stopped/); |
82 | |
83 | eval "use 5.8;"; |
84 | like ($@, qr/Perl v5\.800\.0 required \(did you mean v5\.8\.0\?\)--this is only \Q$^V\E, stopped/); |
85 | |
86 | eval "use 5.9;"; |
87 | like ($@, qr/Perl v5\.900\.0 required \(did you mean v5\.9\.0\?\)--this is only \Q$^V\E, stopped/); |
88 | |
89 | eval "use 5.10;"; |
90 | like ($@, qr/Perl v5\.100\.0 required \(did you mean v5\.10\.0\?\)--this is only \Q$^V\E, stopped/); |
91 | |
53eb19dd |
92 | eval "use 5.11;"; |
93 | like ($@, qr/Perl v5\.110\.0 required \(did you mean v5\.11\.0\?\)--this is only \Q$^V\E, stopped/); |
94 | |
6d2c9499 |
95 | eval sprintf "use %.6f;", $]; |
6a4a49dd |
96 | is ($@, ''); |
8ebc5c01 |
97 | |
98 | |
6d2c9499 |
99 | eval sprintf "use %.6f;", $] - 0.000001; |
6a4a49dd |
100 | is ($@, ''); |
8ebc5c01 |
101 | |
6d2c9499 |
102 | eval sprintf("use %.6f;", $] + 1); |
6a4a49dd |
103 | like ($@, qr/Perl v6.\d+.\d+ required--this is only \Q$^V\E, stopped/); |
8ebc5c01 |
104 | |
6d2c9499 |
105 | eval sprintf "use %.6f;", $] + 0.00001; |
6a4a49dd |
106 | like ($@, qr/Perl v5.\d+.\d+ required--this is only \Q$^V\E, stopped/); |
8ebc5c01 |
107 | |
53eb19dd |
108 | # check that "use 5.11.0" (and higher) loads strictures |
109 | eval 'use 5.11.0; ${"foo"} = "bar";'; |
110 | like ($@, qr/Can't use string \("foo"\) as a SCALAR ref while "strict refs" in use/); |
5cc917d6 |
111 | # but that they can be disabled |
112 | eval 'use 5.11.0; no strict "refs"; ${"foo"} = "bar";'; |
113 | is ($@, ""); |
114 | # and they are properly scoped |
115 | eval '{use 5.11.0;} ${"foo"} = "bar";'; |
116 | is ($@, ""); |
117 | # and this doesn't happen with require |
118 | eval 'require 5.11.0; ${"foo"} = "bar";'; |
119 | is ($@, ""); |
53eb19dd |
120 | |
18b09519 |
121 | { use lib } # check that subparse saves pending tokens |
8ebc5c01 |
122 | |
123 | local $lib::VERSION = 1.0; |
124 | |
125 | eval "use lib 0.9"; |
6a4a49dd |
126 | is ($@, ''); |
8ebc5c01 |
127 | |
128 | eval "use lib 1.0"; |
6a4a49dd |
129 | is ($@, ''); |
8ebc5c01 |
130 | |
131 | eval "use lib 1.01"; |
6a4a49dd |
132 | isnt ($@, ''); |
8ebc5c01 |
133 | |
8ebc5c01 |
134 | eval "use lib 0.9 qw(fred)"; |
6a4a49dd |
135 | is ($@, ''); |
8ebc5c01 |
136 | |
7b903762 |
137 | is($INC[0], "fred"); |
8ebc5c01 |
138 | |
139 | eval "use lib 1.0 qw(joe)"; |
6a4a49dd |
140 | is ($@, ''); |
141 | |
7b903762 |
142 | is($INC[0], "joe"); |
8ebc5c01 |
143 | |
144 | eval "use lib 1.01 qw(freda)"; |
6a4a49dd |
145 | isnt($@, ''); |
8ebc5c01 |
146 | |
7b903762 |
147 | isnt($INC[0], "freda"); |
1571675a |
148 | |
149 | { |
150 | local $lib::VERSION = 35.36; |
151 | eval "use lib v33.55"; |
6a4a49dd |
152 | is ($@, ''); |
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 = '35.36'; |
164 | eval "use lib v33.55"; |
6a4a49dd |
165 | like ($@, ''); |
1571675a |
166 | |
167 | eval "use lib v100.105"; |
ac0e6a2f |
168 | like ($@, qr/lib version v100.105.0 required--this is only version v35\.360\.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 35.36/); |
1571675a |
175 | |
176 | local $lib::VERSION = v35.36; |
177 | eval "use lib v33.55"; |
6a4a49dd |
178 | is ($@, ''); |
1571675a |
179 | |
180 | eval "use lib v100.105"; |
ac0e6a2f |
181 | like ($@, qr/lib version v100.105.0 required--this is only version v35\.36\.0/); |
1571675a |
182 | |
183 | eval "use lib 33.55"; |
6a4a49dd |
184 | is ($@, ''); |
1571675a |
185 | |
186 | eval "use lib 100.105"; |
8cb289bd |
187 | like ($@, qr/lib version 100.105 required--this is only version v35.36/); |
1571675a |
188 | } |
8312d5ee |
189 | |
190 | |
191 | { |
192 | # Regression test for patch 14937: |
193 | # Check that a .pm file with no package or VERSION doesn't core. |
2d90ac95 |
194 | open F, ">xxx$$.pm" or die "Cannot open xxx$$.pm: $!\n"; |
8312d5ee |
195 | print F "1;\n"; |
196 | close F; |
2d90ac95 |
197 | eval "use lib '.'; use xxx$$ 3;"; |
198 | like ($@, qr/^xxx$$ defines neither package nor VERSION--version check failed at/); |
199 | unlink "xxx$$.pm"; |
8312d5ee |
200 | } |
3cacfbb9 |
201 | |
202 | my @ver = split /\./, sprintf "%vd", $^V; |
203 | |
204 | foreach my $index (-3..+3) { |
205 | foreach my $v (0, 1) { |
206 | my @parts = @ver; |
207 | if ($index) { |
208 | if ($index < 0) { |
209 | # Jiggle one of the parts down |
210 | --$parts[-$index - 1]; |
8c5f6936 |
211 | if ($parts[-$index - 1] < 0) { |
212 | # perl's version number ends with '.0' |
213 | $parts[-$index - 1] = 0; |
214 | $parts[-$index - 2] -= 2; |
215 | } |
3cacfbb9 |
216 | } else { |
217 | # Jiggle one of the parts up |
218 | ++$parts[$index - 1]; |
219 | } |
220 | } |
221 | my $v_version = sprintf "v%d.%d.%d", @parts; |
222 | my $version; |
223 | if ($v) { |
224 | $version = $v_version; |
225 | } else { |
226 | $version = $parts[0] + $parts[1] / 1000 + $parts[2] / 1000000; |
227 | } |
228 | |
229 | eval "use $version"; |
230 | if ($index > 0) { |
231 | # The future |
232 | like ($@, |
233 | qr/Perl $v_version required--this is only \Q$^V\E, stopped/, |
234 | "use $version"); |
235 | } else { |
236 | # The present or past |
237 | is ($@, '', "use $version"); |
238 | } |
239 | |
240 | eval "no $version"; |
241 | if ($index <= 0) { |
242 | # The present or past |
243 | like ($@, |
244 | qr/Perls since $v_version too modern--this is \Q$^V\E, stopped/, |
245 | "no $version"); |
246 | } else { |
247 | # future |
248 | is ($@, '', "no $version"); |
249 | } |
250 | } |
251 | } |
252 | |