This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
bring '*' prototype closer to how it behaves internally
[perl5.git] / t / comp / require.t
1 #!./perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     unshift @INC, ('.', '../lib');
6 }
7
8 # don't make this lexical
9 $i = 1;
10 print "1..4\n";
11
12 sub do_require {
13     %INC = ();
14     write_file('bleah.pm',@_);
15     eval { require "bleah.pm" };
16     my @a; # magic guard for scope violations (must be first lexical in file)
17 }
18
19 sub write_file {
20     my $f = shift;
21     open(REQ,">$f") or die "Can't write '$f': $!";
22     print REQ @_;
23     close REQ;
24 }
25
26 # interaction with pod (see the eof)
27 write_file('bleah.pm', "print 'ok $i\n'; 1;\n");
28 require "bleah.pm";
29 $i++;
30
31 # run-time failure in require
32 do_require "0;\n";
33 print "# $@\nnot " unless $@ =~ /did not return a true/;
34 print "ok ",$i++,"\n";
35
36 # compile-time failure in require
37 do_require "1)\n";
38 # bison says 'parse error' instead of 'syntax error',
39 # various yaccs may or may not capitalize 'syntax'.
40 print "# $@\nnot " unless $@ =~ /(syntax|parse) error/mi;
41 print "ok ",$i++,"\n";
42
43 # successful require
44 do_require "1";
45 print "# $@\nnot " if $@;
46 print "ok ",$i++,"\n";
47
48 END { unlink 'bleah.pm'; }
49
50 # ***interaction with pod (don't put any thing after here)***
51
52 =pod