6 push @INC, '../lib', '../ext/re';
11 write_file('bleah.pm',@_);
12 eval { require "bleah.pm" };
13 my @a; # magic guard for scope violations (must be first lexical in file)
16 # don't make this lexical
19 my @files_to_delete = qw (bleah.pm bleah.do bleah.flg urkkk.pm urkkk.pmc
20 krunch.pm krunch.pmc whap.pm whap.pmc);
22 # there may be another copy of this test script running, or the files may
23 # just not have been deleted at the end of the last run; if the former, we
24 # wait a while so that creating and unlinking these files won't interfere
25 # with the other process; if the latter, then the delay is harmless. As
26 # to why there might be multiple execution of this test file, I don't
27 # know; but this is an experiment to see if random smoke failures go away.
29 if (grep -e, @files_to_delete) {
30 print "# Sleeping for 20 secs waiting for other process to finish\n";
35 my $Is_EBCDIC = (ord('A') == 193) ? 1 : 0;
36 my $Is_UTF8 = (${^OPEN} || "") =~ /:utf8/;
38 if ($Is_EBCDIC || $Is_UTF8) { $total_tests -= 3; }
39 print "1..$total_tests\n";
43 open(REQ,">$f") or die "Can't write '$f': $!";
46 close REQ or die "Could not close $f: $!";
50 print "# $@\nnot " if $@;
51 print "ok ",$i++," - require 5.005 try 1\n";
53 eval { require 5.005 };
54 print "# $@\nnot " if $@;
55 print "ok ",$i++," - require 5.005 try 2\n";
57 eval { require 5.005; };
58 print "# $@\nnot " if $@;
59 print "ok ",$i++," - require 5.005 try 3\n";
64 print "# $@\nnot " if $@;
65 print "ok ",$i++," - require 5.005 try 4\n";
67 # new style version numbers
69 eval { require v5.5.630; };
70 print "# $@\nnot " if $@;
71 print "ok ",$i++," - require 5.5.630\n";
73 eval { require(v5.5.630); };
74 print "# $@\nnot " if $@;
75 print "ok ",$i++," - require(v5.5.630) with parens [perl #124153]\n";
79 print "# $@\nnot " if $@;
80 print "ok ",$i++," - require v5 ignores sub named v5\n";
82 eval { require 10.0.2; };
83 print "# $@\nnot " unless $@ =~ /^Perl v10\.0\.2 required/;
84 print "ok ",$i++," - require 10.0.2\n";
87 eval { require $ver; };
88 print "# $@\nnot " if $@;
89 print "ok ",$i++," - require 5.005_63\n";
93 eval { require $ver; };
94 print "# $@\nnot " unless $@ =~ /^Perl v10\.200.0 required/;
95 print "ok ",$i++," - require 10.2\n";
98 eval { require $ver; };
99 print "# $@\nnot " unless $@ =~ /^Perl v10\.0\.20 required/;
100 print "ok ",$i++," - require 10.000_02\n";
102 print "not " unless 5.5.1 gt v5.5;
103 print "ok ",$i++," - 5.5.1 gt v5.5\n";
106 print "not " unless v5.5.640 eq "\x{5}\x{5}\x{280}";
107 print "ok ",$i++," - v5.5.640 eq \\x{5}\\x{5}\\x{280}\n";
109 print "not " unless v7.15 eq "\x{7}\x{f}";
110 print "ok ",$i++," - v7.15 eq \\x{7}\\x{f}\n";
113 unless v1.20.300.4000.50000.600000 eq "\x{1}\x{14}\x{12c}\x{fa0}\x{c350}\x{927c0}";
114 print "ok ",$i++," - v1.20.300.4000.50000.600000 eq ...\n";
117 # "use 5.11.0" (and higher) loads strictures.
118 # check that this doesn't happen with require
119 eval 'require 5.11.0; ${"foo"} = "bar";';
120 print "# $@\nnot " if $@;
121 print "ok ",$i++," - require 5.11.0\n";
122 eval 'BEGIN {require 5.11.0} ${"foo"} = "bar";';
123 print "# $@\nnot " if $@;
124 print "ok ",$i++,"\ - BEGIN { require 5.11.0}\n";
126 # interaction with pod (see the eof)
127 write_file('bleah.pm', "print 'ok $i - require bleah.pm\n'; 1;\n");
131 # run-time failure in require
133 print "# $@\nnot " unless $@ =~ /did not return a true/;
134 print "ok ",$i++," - require returning 0\n";
136 print "not " if exists $INC{'bleah.pm'};
137 print "ok ",$i++," - %INC not updated\n";
139 my $flag_file = 'bleah.flg';
140 # run-time error in require
141 for my $expected_compile (1,0) {
142 write_file($flag_file, 1);
143 print "not " unless -e $flag_file;
144 print "ok ",$i++," - exp $expected_compile; bleah.flg\n";
145 write_file('bleah.pm', "unlink '$flag_file' or die; \$a=0; \$b=1/\$a; 1;\n");
146 print "# $@\nnot " if eval { require 'bleah.pm' };
147 print "ok ",$i++," - exp $expected_compile; require bleah.pm with flag file\n";
148 print "not " unless -e $flag_file xor $expected_compile;
149 print "ok ",$i++," - exp $expected_compile; -e flag_file\n";
150 print "not " unless exists $INC{'bleah.pm'};
151 print "ok ",$i++," - exp $expected_compile; exists \$INC{'bleah.pm}\n";
154 # compile-time failure in require
156 # bison says 'parse error' instead of 'syntax error',
157 # various yaccs may or may not capitalize 'syntax'.
158 print "# $@\nnot " unless $@ =~ /(syntax|parse) error/mi;
159 print "ok ",$i++," - syntax error\n";
161 # previous failure cached in %INC
162 print "not " unless exists $INC{'bleah.pm'};
163 print "ok ",$i++," - cached %INC\n";
164 write_file($flag_file, 1);
165 write_file('bleah.pm', "unlink '$flag_file'; 1");
166 print "# $@\nnot " if eval { require 'bleah.pm' };
167 print "ok ",$i++," - eval { require 'bleah.pm' }\n";
168 print "# $@\nnot " unless $@ =~ /Compilation failed/i;
169 print "ok ",$i++," - Compilation failed\n";
170 print "not " unless -e $flag_file;
171 print "ok ",$i++," - -e flag_file\n";
172 print "not " unless exists $INC{'bleah.pm'};
173 print "ok ",$i++," - \$INC{'bleah.pm'}\n";
177 print "# $@\nnot " if $@;
178 print "ok ",$i++," - do_require '1';\n";
180 # do FILE shouldn't see any outside lexicals
181 my $x = "ok $i - bleah.do\n";
182 write_file("bleah.do", <<EOT);
183 \$x = "not ok $i - bleah.do\\n";
185 do "bleah.do" or die $@;
187 sub dofile { do "bleah.do" or die $@; };
190 # Test that scalar context is forced for require
192 write_file('bleah.pm', <<'**BLEAH**'
193 print "not " if !defined wantarray || wantarray ne '';
194 print "ok $i - require() context\n";
198 delete $INC{"bleah.pm"}; ++$::i;
199 $foo = eval q{require bleah}; delete $INC{"bleah.pm"}; ++$::i;
200 @foo = eval q{require bleah}; delete $INC{"bleah.pm"}; ++$::i;
201 eval q{require bleah}; delete $INC{"bleah.pm"}; ++$::i;
202 eval q{$_=$_+2;require bleah}; delete $INC{"bleah.pm"}; ++$::i;
203 eval q{return require bleah}; delete $INC{"bleah.pm"}; ++$::i;
204 $foo = eval {require bleah}; delete $INC{"bleah.pm"}; ++$::i;
205 @foo = eval {require bleah}; delete $INC{"bleah.pm"}; ++$::i;
206 eval {require bleah}; delete $INC{"bleah.pm"}; ++$::i;
208 eval 'require ::bleah;';
209 print "# $@\nnot " unless $@ =~ /^Bareword in require must not start with a double-colon:/;
210 print "ok ", $i," - require ::bleah is banned\n";
212 # Test for fix of RT #24404 : "require $scalar" may load a directory
216 if($@ =~ /Can't locate threads in \@INC/) {
217 print "ok $i - RT #24404\n";
219 print "not ok - RT #24404$i\n";
223 eval ' require CORE::lc "THREADS" ';
225 if($@ =~ /Can't locate threads in \@INC/) {
226 print "ok $i - [perl #24482] require CORE::foo\n";
228 print "not ok - [perl #24482] require CORE::foo\n";
232 write_file('bleah.pm', qq(die "This is an expected error";\n));
233 delete $INC{"bleah.pm"}; ++$::i;
234 eval { CORE::require bleah; };
235 if ($@ =~ /^This is an expected error/) {
236 print "ok $i - expected error\n";
238 print "not ok $i - expected error\n";
241 sub write_file_not_thing {
242 my ($file, $thing, $test) = @_;
243 write_file($file, <<"EOT");
244 print "not ok $test - write_file_not_thing $file\n";
245 die "The $thing file should not be loaded";
250 # Right. We really really need Config here.
252 die "Failed to load Config for some reason"
253 unless $Config::Config{version};
256 my $pmc_older = ++$i;
259 foreach(Config::non_bincompat_options()) {
260 if($_ eq "PERL_DISABLE_PMC"){
266 print "# .pmc files are ignored, so test that\n";
267 write_file_not_thing('krunch.pmc', '.pmc', $pmc_older);
268 write_file('urkkk.pm', qq(print "ok $simple - urkkk.pm branch A\n"));
269 write_file('whap.pmc', qq(die "This is not an expected error"));
271 print "# Sleeping for 2 seconds before creating some more files\n";
274 write_file('krunch.pm', qq(print "ok $pmc_older - krunch.pm branch A\n"));
275 write_file_not_thing('urkkk.pmc', '.pmc', $simple);
276 write_file('whap.pm', qq(die "This is an expected error"));
278 print "# .pmc files should be loaded, so test that\n";
279 write_file('krunch.pmc', qq(print "ok $pmc_older - krunch.pm branch B\n";));
280 write_file_not_thing('urkkk.pm', '.pm', $simple);
281 write_file('whap.pmc', qq(die "This is an expected error"));
283 print "# Sleeping for 2 seconds before creating some more files\n";
286 write_file_not_thing('krunch.pm', '.pm', $pmc_older);
287 write_file('urkkk.pmc', qq(print "ok $simple - urkkk.pm branch B\n";));
288 write_file_not_thing('whap.pm', '.pm', $pmc_dies);
292 eval {CORE::require whap; 1} and die;
294 if ($@ =~ /^This is an expected error/) {
295 print "ok $pmc_dies - pmc_dies\n";
297 print "not ok $pmc_dies - pmc_dies\n";
303 # if we 'require "op"', since we're in the t/ directory and '.' is the
304 # first thing in @INC, it will try to load t/op/; it should fail and
305 # move onto the next path; however, the previous value of $! was
306 # leaking into implementation if it was EACCES and we're accessing a
309 $! = eval 'use Errno qw(EACCES); EACCES' || 0;
310 eval q{require 'op'};
312 print "not " if $@ =~ /Permission denied/;
313 print "ok $i - require op\n";
316 # Test "require func()" with abs path when there is no .pmc file.
318 if (defined &DynaLoader::boot_DynaLoader) {
320 require File::Spec::Functions;
322 CORE::require(File::Spec::Functions::catfile(Cwd::getcwd(),"bleah.pm"));
324 if ($@ =~ /^This is an expected error/) {
325 print "ok $i - require(func())\n";
327 print "not ok $i - require(func())\n";
330 print "ok $i # SKIP Cwd may not be available in miniperl\n";
334 BEGIN { ${^OPEN} = ":utf8\0"; }
336 write_file('bleah.pm',"package F; \$x = '\xD1\x9E';\n");
337 eval { require "bleah.pm" };
339 my $not = $F::x eq "\xD1\x9E" ? "" : "not ";
340 print "${not}ok $i - require ignores I/O layers\n";
344 BEGIN { ${^OPEN} = ":utf8\0"; }
346 write_file('bleah.pm',"require re; re->import('/x'); 1;\n");
347 my $not = eval 'use bleah; "ab" =~ /a b/' ? "" : "not ";
349 print "${not}ok $i - require does not localise %^H at run time\n";
352 ##########################################
353 # What follows are UTF-8 specific tests. #
354 # Add generic tests before this point. #
355 ##########################################
357 # UTF-encoded things - skipped on UTF-8 input
359 if ($Is_UTF8) { exit; }
368 my ($enc, $content, $do_bom) = @_;
369 my $template = $templates{$enc};
370 die "Unsupported encoding $enc" unless $template;
371 return pack "$template*", ($do_bom ? 0xFEFF : ()), unpack "C*", $content;
374 foreach (sort keys %templates) {
375 $i++; do_require(bytes_to_utf($_, qq(print "ok $i # $_\\n"; 1;\n), 1));
376 if ($@ =~ /^(Unsupported script encoding \Q$_\E)/) {
377 print "ok $i # skip $1\n";
382 foreach my $file (@files_to_delete) {
383 1 while unlink $file;
387 # ***interaction with pod (don't put any thing after here)***