This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
several new tests needed tweaking to work under utf8
[perl5.git] / t / comp / require.t
CommitLineData
f46d017c
GS
1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
342930fb 5 @INC = ('.', '../lib');
f46d017c
GS
6}
7
8# don't make this lexical
9$i = 1;
4a9ae47a 10print "1..4\n";
f46d017c
GS
11
12sub do_require {
13 %INC = ();
4a9ae47a 14 write_file('bleah.pm',@_);
f46d017c
GS
15 eval { require "bleah.pm" };
16 my @a; # magic guard for scope violations (must be first lexical in file)
17}
18
4a9ae47a
GS
19sub 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)
27write_file('bleah.pm', "print 'ok $i\n'; 1;\n");
28require "bleah.pm";
29$i++;
30
f46d017c
GS
31# run-time failure in require
32do_require "0;\n";
33print "# $@\nnot " unless $@ =~ /did not return a true/;
34print "ok ",$i++,"\n";
35
36# compile-time failure in require
37do_require "1)\n";
9d116dd7 38print "# $@\nnot " unless $@ =~ /syntax error/i;
f46d017c
GS
39print "ok ",$i++,"\n";
40
41# successful require
42do_require "1";
43print "# $@\nnot " if $@;
44print "ok ",$i++,"\n";
45
4a9ae47a
GS
46END { unlink 'bleah.pm'; }
47
48# ***interaction with pod (don't put any thing after here)***
49
50=pod