6 $INC{"feature.pm"} = 1; # so we don't attempt to load feature.pm
11 # Can't require test.pl, as we're testing the use/require mechanism here.
16 my ($type, $got, $expected, $name) = @_;
20 $result = $got eq $expected;
21 } elsif ($type eq 'isnt') {
22 $result = $got ne $expected;
23 } elsif ($type eq 'like') {
24 $result = $got =~ $expected;
26 die "Unexpected type '$type'$name";
30 print "ok $test - $name\n";
36 print "not ok $test - $name\n";
38 print "not ok $test\n";
40 my @caller = caller(2);
41 print "# Failed test at $caller[1] line $caller[2]\n";
42 print "# Got '$got'\n";
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";
65 eval "use 5.000"; # implicit semicolon
72 like ($@, qr/Perl v6\.0\.0 required--this is only \Q$^V\E, stopped/);
78 like ($@, qr/Perls since v5\.0\.0 too modern--this is \Q$^V\E, stopped/);
81 like ($@, qr/Perl v5\.600\.0 required \(did you mean v5\.6\.0\?\)--this is only \Q$^V\E, stopped/);
84 like ($@, qr/Perl v5\.800\.0 required \(did you mean v5\.8\.0\?\)--this is only \Q$^V\E, stopped/);
87 like ($@, qr/Perl v5\.900\.0 required \(did you mean v5\.9\.0\?\)--this is only \Q$^V\E, stopped/);
90 like ($@, qr/Perl v5\.100\.0 required \(did you mean v5\.10\.0\?\)--this is only \Q$^V\E, stopped/);
93 like ($@, qr/Perl v5\.110\.0 required \(did you mean v5\.11\.0\?\)--this is only \Q$^V\E, stopped/);
95 eval sprintf "use %.6f;", $];
99 eval sprintf "use %.6f;", $] - 0.000001;
102 eval sprintf("use %.6f;", $] + 1);
103 like ($@, qr/Perl v6.\d+.\d+ required--this is only \Q$^V\E, stopped/);
105 eval sprintf "use %.6f;", $] + 0.00001;
106 like ($@, qr/Perl v5.\d+.\d+ required--this is only \Q$^V\E, stopped/);
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/);
111 # but that they can be disabled
112 eval 'use 5.11.0; no strict "refs"; ${"foo"} = "bar";';
114 # and they are properly scoped
115 eval '{use 5.11.0;} ${"foo"} = "bar";';
117 # and this doesn't happen with require
118 eval 'require 5.11.0; ${"foo"} = "bar";';
121 { use lib } # check that subparse saves pending tokens
123 local $lib::VERSION = 1.0;
134 eval "use lib 0.9 qw(fred)";
139 eval "use lib 1.0 qw(joe)";
144 eval "use lib 1.01 qw(freda)";
147 isnt($INC[0], "freda");
150 local $lib::VERSION = 35.36;
151 eval "use lib v33.55";
154 eval "use lib v100.105";
155 like ($@, qr/lib version v100.105.0 required--this is only version v35\.360\.0/);
157 eval "use lib 33.55";
160 eval "use lib 100.105";
161 like ($@, qr/lib version 100.105 required--this is only version 35.36/);
163 local $lib::VERSION = '35.36';
164 eval "use lib v33.55";
167 eval "use lib v100.105";
168 like ($@, qr/lib version v100.105.0 required--this is only version v35\.360\.0/);
170 eval "use lib 33.55";
173 eval "use lib 100.105";
174 like ($@, qr/lib version 100.105 required--this is only version 35.36/);
176 local $lib::VERSION = v35.36;
177 eval "use lib v33.55";
180 eval "use lib v100.105";
181 like ($@, qr/lib version v100.105.0 required--this is only version v35\.36\.0/);
183 eval "use lib 33.55";
186 eval "use lib 100.105";
187 like ($@, qr/lib version 100.105 required--this is only version v35.36/);
192 # Regression test for patch 14937:
193 # Check that a .pm file with no package or VERSION doesn't core.
194 open F, ">xxx$$.pm" or die "Cannot open xxx$$.pm: $!\n";
197 eval "use lib '.'; use xxx$$ 3;";
198 like ($@, qr/^xxx$$ defines neither package nor VERSION--version check failed at/);
202 my @ver = split /\./, sprintf "%vd", $^V;
204 foreach my $index (-3..+3) {
205 foreach my $v (0, 1) {
209 # Jiggle one of the parts down
210 --$parts[-$index - 1];
211 if ($parts[-$index - 1] < 0) {
212 # perl's version number ends with '.0'
213 $parts[-$index - 1] = 0;
214 $parts[-$index - 2] -= 2;
217 # Jiggle one of the parts up
218 ++$parts[$index - 1];
221 my $v_version = sprintf "v%d.%d.%d", @parts;
224 $version = $v_version;
226 $version = $parts[0] + $parts[1] / 1000 + $parts[2] / 1000000;
233 qr/Perl $v_version required--this is only \Q$^V\E, stopped/,
236 # The present or past
237 is ($@, '', "use $version");
242 # The present or past
244 qr/Perls since $v_version too modern--this is \Q$^V\E, stopped/,
248 is ($@, '', "no $version");