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 @fjles_to_delete = qw (bleah.pm bleah.do bleah.flg urkkk.pm urkkk.pmc
20 krunch.pm krunch.pmc whap.pm whap.pmc);
23 my $Is_EBCDIC = (ord('A') == 193) ? 1 : 0;
24 my $Is_UTF8 = (${^OPEN} || "") =~ /:utf8/;
26 if ($Is_EBCDIC || $Is_UTF8) { $total_tests -= 3; }
27 print "1..$total_tests\n";
31 open(REQ,">$f") or die "Can't write '$f': $!";
34 close REQ or die "Could not close $f: $!";
38 print "# $@\nnot " if $@;
39 print "ok ",$i++,"\n";
41 eval { require 5.005 };
42 print "# $@\nnot " if $@;
43 print "ok ",$i++,"\n";
45 eval { require 5.005; };
46 print "# $@\nnot " if $@;
47 print "ok ",$i++,"\n";
52 print "# $@\nnot " if $@;
53 print "ok ",$i++,"\n";
55 # new style version numbers
57 eval { require v5.5.630; };
58 print "# $@\nnot " if $@;
59 print "ok ",$i++,"\n";
63 print "# $@\nnot " if $@;
64 print "ok ",$i++," - require v5 ignores sub named v5\n";
66 eval { require 10.0.2; };
67 print "# $@\nnot " unless $@ =~ /^Perl v10\.0\.2 required/;
68 print "ok ",$i++,"\n";
71 eval { require $ver; };
72 print "# $@\nnot " if $@;
73 print "ok ",$i++,"\n";
77 eval { require $ver; };
78 print "# $@\nnot " unless $@ =~ /^Perl v10\.200.0 required/;
79 print "ok ",$i++,"\n";
82 eval { require $ver; };
83 print "# $@\nnot " unless $@ =~ /^Perl v10\.0\.20 required/;
84 print "ok ",$i++,"\n";
86 print "not " unless 5.5.1 gt v5.5;
87 print "ok ",$i++,"\n";
90 print "not " unless v5.5.640 eq "\x{5}\x{5}\x{280}";
91 print "ok ",$i++,"\n";
93 print "not " unless v7.15 eq "\x{7}\x{f}";
94 print "ok ",$i++,"\n";
97 unless v1.20.300.4000.50000.600000 eq "\x{1}\x{14}\x{12c}\x{fa0}\x{c350}\x{927c0}";
98 print "ok ",$i++,"\n";
101 # "use 5.11.0" (and higher) loads strictures.
102 # check that this doesn't happen with require
103 eval 'require 5.11.0; ${"foo"} = "bar";';
104 print "# $@\nnot " if $@;
105 print "ok ",$i++,"\n";
106 eval 'BEGIN {require 5.11.0} ${"foo"} = "bar";';
107 print "# $@\nnot " if $@;
108 print "ok ",$i++,"\n";
110 # interaction with pod (see the eof)
111 write_file('bleah.pm', "print 'ok $i\n'; 1;\n");
115 # run-time failure in require
117 print "# $@\nnot " unless $@ =~ /did not return a true/;
118 print "ok ",$i++,"\n";
120 print "not " if exists $INC{'bleah.pm'};
121 print "ok ",$i++,"\n";
123 my $flag_file = 'bleah.flg';
124 # run-time error in require
125 for my $expected_compile (1,0) {
126 write_file($flag_file, 1);
127 print "not " unless -e $flag_file;
128 print "ok ",$i++,"\n";
129 write_file('bleah.pm', "unlink '$flag_file' or die; \$a=0; \$b=1/\$a; 1;\n");
130 print "# $@\nnot " if eval { require 'bleah.pm' };
131 print "ok ",$i++,"\n";
132 print "not " unless -e $flag_file xor $expected_compile;
133 print "ok ",$i++,"\n";
134 print "not " unless exists $INC{'bleah.pm'};
135 print "ok ",$i++,"\n";
138 # compile-time failure in require
140 # bison says 'parse error' instead of 'syntax error',
141 # various yaccs may or may not capitalize 'syntax'.
142 print "# $@\nnot " unless $@ =~ /(syntax|parse) error/mi;
143 print "ok ",$i++,"\n";
145 # previous failure cached in %INC
146 print "not " unless exists $INC{'bleah.pm'};
147 print "ok ",$i++,"\n";
148 write_file($flag_file, 1);
149 write_file('bleah.pm', "unlink '$flag_file'; 1");
150 print "# $@\nnot " if eval { require 'bleah.pm' };
151 print "ok ",$i++,"\n";
152 print "# $@\nnot " unless $@ =~ /Compilation failed/i;
153 print "ok ",$i++,"\n";
154 print "not " unless -e $flag_file;
155 print "ok ",$i++,"\n";
156 print "not " unless exists $INC{'bleah.pm'};
157 print "ok ",$i++,"\n";
161 print "# $@\nnot " if $@;
162 print "ok ",$i++,"\n";
164 # do FILE shouldn't see any outside lexicals
166 write_file("bleah.do", <<EOT);
167 \$x = "not ok $i\\n";
169 do "bleah.do" or die $@;
171 sub dofile { do "bleah.do" or die $@; };
174 # Test that scalar context is forced for require
176 write_file('bleah.pm', <<'**BLEAH**'
177 print "not " if !defined wantarray || wantarray ne '';
178 print "ok $i - require() context\n";
182 delete $INC{"bleah.pm"}; ++$::i;
183 $foo = eval q{require bleah}; delete $INC{"bleah.pm"}; ++$::i;
184 @foo = eval q{require bleah}; delete $INC{"bleah.pm"}; ++$::i;
185 eval q{require bleah}; delete $INC{"bleah.pm"}; ++$::i;
186 eval q{$_=$_+2;require bleah}; delete $INC{"bleah.pm"}; ++$::i;
187 eval q{return require bleah}; delete $INC{"bleah.pm"}; ++$::i;
188 $foo = eval {require bleah}; delete $INC{"bleah.pm"}; ++$::i;
189 @foo = eval {require bleah}; delete $INC{"bleah.pm"}; ++$::i;
190 eval {require bleah};
192 # Test for fix of RT #24404 : "require $scalar" may load a directory
196 if($@ =~ /Can't locate threads in \@INC/) {
203 write_file('bleah.pm', qq(die "This is an expected error";\n));
204 delete $INC{"bleah.pm"}; ++$::i;
205 eval { CORE::require bleah; };
206 if ($@ =~ /^This is an expected error/) {
212 sub write_file_not_thing {
213 my ($file, $thing, $test) = @_;
214 write_file($file, <<"EOT");
215 print "not ok $test\n";
216 die "The $thing file should not be loaded";
221 # Right. We really really need Config here.
223 die "Failed to load Config for some reason"
224 unless $Config::Config{version};
225 my $ccflags = $Config::Config{ccflags};
226 die "Failed to get ccflags for some reason" unless defined $ccflags;
229 my $pmc_older = ++$i;
231 if ($ccflags =~ /(?:^|\s)-DPERL_DISABLE_PMC\b/) {
232 print "# .pmc files are ignored, so test that\n";
233 write_file_not_thing('krunch.pmc', '.pmc', $pmc_older);
234 write_file('urkkk.pm', qq(print "ok $simple\n"));
235 write_file('whap.pmc', qq(die "This is not an expected error"));
237 print "# Sleeping for 2 seconds before creating some more files\n";
240 write_file('krunch.pm', qq(print "ok $pmc_older\n"));
241 write_file_not_thing('urkkk.pmc', '.pmc', $simple);
242 write_file('whap.pm', qq(die "This is an expected error"));
244 print "# .pmc files should be loaded, so test that\n";
245 write_file('krunch.pmc', qq(print "ok $pmc_older\n";));
246 write_file_not_thing('urkkk.pm', '.pm', $simple);
247 write_file('whap.pmc', qq(die "This is an expected error"));
249 print "# Sleeping for 2 seconds before creating some more files\n";
252 write_file_not_thing('krunch.pm', '.pm', $pmc_older);
253 write_file('urkkk.pmc', qq(print "ok $simple\n";));
254 write_file_not_thing('whap.pm', '.pm', $pmc_dies);
258 eval {CORE::require whap; 1} and die;
260 if ($@ =~ /^This is an expected error/) {
261 print "ok $pmc_dies\n";
263 print "not ok $pmc_dies\n";
267 # Test "require func()" with abs path when there is no .pmc file.
269 if (defined &DynaLoader::boot_DynaLoader) {
271 require File::Spec::Functions;
273 CORE::require(File::Spec::Functions::catfile(Cwd::getcwd(),"bleah.pm"));
275 if ($@ =~ /^This is an expected error/) {
281 print "ok $i # SKIP Cwd may not be available in miniperl\n";
285 BEGIN { ${^OPEN} = ":utf8\0"; }
287 write_file('bleah.pm',"package F; \$x = '\xD1\x9E';\n");
288 eval { require "bleah.pm" };
290 my $not = $F::x eq "\xD1\x9E" ? "" : "not ";
291 print "${not}ok $i - require ignores I/O layers\n";
295 BEGIN { ${^OPEN} = ":utf8\0"; }
297 write_file('bleah.pm',"require re; re->import('/x'); 1;\n");
298 my $not = eval 'use bleah; "ab" =~ /a b/' ? "" : "not ";
300 print "${not}ok $i - require does not localise %^H at run time\n";
303 ##########################################
304 # What follows are UTF-8 specific tests. #
305 # Add generic tests before this point. #
306 ##########################################
308 # UTF-encoded things - skipped on EBCDIC machines and on UTF-8 input
310 if ($Is_EBCDIC || $Is_UTF8) { exit; }
319 my ($enc, $content, $do_bom) = @_;
320 my $template = $templates{$enc};
321 die "Unsupported encoding $enc" unless $template;
322 return pack "$template*", ($do_bom ? 0xFEFF : ()), unpack "C*", $content;
325 foreach (sort keys %templates) {
326 $i++; do_require(bytes_to_utf($_, qq(print "ok $i # $_\\n"; 1;\n), 1));
327 if ($@ =~ /^(Unsupported script encoding \Q$_\E)/) {
328 print "ok $i # skip $1\n";
333 foreach my $file (@fjles_to_delete) {
334 1 while unlink $file;
338 # ***interaction with pod (don't put any thing after here)***