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 | |
d1029faa |
9 | print "1..63\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 | |
6d2c9499 |
92 | eval sprintf "use %.6f;", $]; |
6a4a49dd |
93 | is ($@, ''); |
8ebc5c01 |
94 | |
95 | |
6d2c9499 |
96 | eval sprintf "use %.6f;", $] - 0.000001; |
6a4a49dd |
97 | is ($@, ''); |
8ebc5c01 |
98 | |
6d2c9499 |
99 | eval sprintf("use %.6f;", $] + 1); |
6a4a49dd |
100 | like ($@, qr/Perl v6.\d+.\d+ required--this is only \Q$^V\E, stopped/); |
8ebc5c01 |
101 | |
6d2c9499 |
102 | eval sprintf "use %.6f;", $] + 0.00001; |
6a4a49dd |
103 | like ($@, qr/Perl v5.\d+.\d+ required--this is only \Q$^V\E, stopped/); |
8ebc5c01 |
104 | |
18b09519 |
105 | { use lib } # check that subparse saves pending tokens |
8ebc5c01 |
106 | |
107 | local $lib::VERSION = 1.0; |
108 | |
109 | eval "use lib 0.9"; |
6a4a49dd |
110 | is ($@, ''); |
8ebc5c01 |
111 | |
112 | eval "use lib 1.0"; |
6a4a49dd |
113 | is ($@, ''); |
8ebc5c01 |
114 | |
115 | eval "use lib 1.01"; |
6a4a49dd |
116 | isnt ($@, ''); |
8ebc5c01 |
117 | |
118 | |
119 | eval "use lib 0.9 qw(fred)"; |
6a4a49dd |
120 | is ($@, ''); |
8ebc5c01 |
121 | |
6a4a49dd |
122 | if ($^O eq 'MacOS') { |
123 | is($INC[0], ":fred:"); |
124 | } else { |
125 | is($INC[0], "fred"); |
126 | } |
8ebc5c01 |
127 | |
128 | eval "use lib 1.0 qw(joe)"; |
6a4a49dd |
129 | is ($@, ''); |
130 | |
131 | |
132 | if ($^O eq 'MacOS') { |
133 | is($INC[0], ":joe:"); |
134 | } else { |
135 | is($INC[0], "joe"); |
8ebc5c01 |
136 | } |
8ebc5c01 |
137 | |
8ebc5c01 |
138 | |
139 | eval "use lib 1.01 qw(freda)"; |
6a4a49dd |
140 | isnt($@, ''); |
8ebc5c01 |
141 | |
6a4a49dd |
142 | if ($^O eq 'MacOS') { |
143 | isnt($INC[0], ":freda:"); |
144 | } else { |
145 | isnt($INC[0], "freda"); |
146 | } |
1571675a |
147 | |
148 | { |
149 | local $lib::VERSION = 35.36; |
150 | eval "use lib v33.55"; |
6a4a49dd |
151 | is ($@, ''); |
1571675a |
152 | |
153 | eval "use lib v100.105"; |
ac0e6a2f |
154 | like ($@, qr/lib version v100.105.0 required--this is only version v35\.360\.0/); |
1571675a |
155 | |
156 | eval "use lib 33.55"; |
6a4a49dd |
157 | is ($@, ''); |
1571675a |
158 | |
159 | eval "use lib 100.105"; |
8cb289bd |
160 | like ($@, qr/lib version 100.105 required--this is only version 35.36/); |
1571675a |
161 | |
162 | local $lib::VERSION = '35.36'; |
163 | eval "use lib v33.55"; |
6a4a49dd |
164 | like ($@, ''); |
1571675a |
165 | |
166 | eval "use lib v100.105"; |
ac0e6a2f |
167 | like ($@, qr/lib version v100.105.0 required--this is only version v35\.360\.0/); |
1571675a |
168 | |
169 | eval "use lib 33.55"; |
6a4a49dd |
170 | is ($@, ''); |
1571675a |
171 | |
172 | eval "use lib 100.105"; |
8cb289bd |
173 | like ($@, qr/lib version 100.105 required--this is only version 35.36/); |
1571675a |
174 | |
175 | local $lib::VERSION = v35.36; |
176 | eval "use lib v33.55"; |
6a4a49dd |
177 | is ($@, ''); |
1571675a |
178 | |
179 | eval "use lib v100.105"; |
ac0e6a2f |
180 | like ($@, qr/lib version v100.105.0 required--this is only version v35\.36\.0/); |
1571675a |
181 | |
182 | eval "use lib 33.55"; |
6a4a49dd |
183 | is ($@, ''); |
1571675a |
184 | |
185 | eval "use lib 100.105"; |
8cb289bd |
186 | like ($@, qr/lib version 100.105 required--this is only version v35.36/); |
1571675a |
187 | } |
8312d5ee |
188 | |
189 | |
190 | { |
191 | # Regression test for patch 14937: |
192 | # Check that a .pm file with no package or VERSION doesn't core. |
2d90ac95 |
193 | open F, ">xxx$$.pm" or die "Cannot open xxx$$.pm: $!\n"; |
8312d5ee |
194 | print F "1;\n"; |
195 | close F; |
2d90ac95 |
196 | eval "use lib '.'; use xxx$$ 3;"; |
197 | like ($@, qr/^xxx$$ defines neither package nor VERSION--version check failed at/); |
198 | unlink "xxx$$.pm"; |
8312d5ee |
199 | } |
3cacfbb9 |
200 | |
201 | my @ver = split /\./, sprintf "%vd", $^V; |
202 | |
203 | foreach my $index (-3..+3) { |
204 | foreach my $v (0, 1) { |
205 | my @parts = @ver; |
206 | if ($index) { |
207 | if ($index < 0) { |
208 | # Jiggle one of the parts down |
209 | --$parts[-$index - 1]; |
8c5f6936 |
210 | if ($parts[-$index - 1] < 0) { |
211 | # perl's version number ends with '.0' |
212 | $parts[-$index - 1] = 0; |
213 | $parts[-$index - 2] -= 2; |
214 | } |
3cacfbb9 |
215 | } else { |
216 | # Jiggle one of the parts up |
217 | ++$parts[$index - 1]; |
218 | } |
219 | } |
220 | my $v_version = sprintf "v%d.%d.%d", @parts; |
221 | my $version; |
222 | if ($v) { |
223 | $version = $v_version; |
224 | } else { |
225 | $version = $parts[0] + $parts[1] / 1000 + $parts[2] / 1000000; |
226 | } |
227 | |
228 | eval "use $version"; |
229 | if ($index > 0) { |
230 | # The future |
231 | like ($@, |
232 | qr/Perl $v_version required--this is only \Q$^V\E, stopped/, |
233 | "use $version"); |
234 | } else { |
235 | # The present or past |
236 | is ($@, '', "use $version"); |
237 | } |
238 | |
239 | eval "no $version"; |
240 | if ($index <= 0) { |
241 | # The present or past |
242 | like ($@, |
243 | qr/Perls since $v_version too modern--this is \Q$^V\E, stopped/, |
244 | "no $version"); |
245 | } else { |
246 | # future |
247 | is ($@, '', "no $version"); |
248 | } |
249 | } |
250 | } |
251 | |