xref: /openbsd-src/gnu/usr.bin/perl/t/comp/require.t (revision 0a5f61bb653fdff7c29c2275df78c7f019a04c0c)
1#!./perl
2
3BEGIN {
4    chdir 't' if -d 't';
5    @INC = ('.', '../lib');
6}
7
8# don't make this lexical
9$i = 1;
10print "1..4\n";
11
12sub 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
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
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";
38# bison says 'parse error' instead of 'syntax error',
39# various yaccs may or may not capitalize 'syntax'.
40print "# $@\nnot " unless $@ =~ /(syntax|parse) error/mi;
41print "ok ",$i++,"\n";
42
43# successful require
44do_require "1";
45print "# $@\nnot " if $@;
46print "ok ",$i++,"\n";
47
48END { unlink 'bleah.pm'; }
49
50# ***interaction with pod (don't put any thing after here)***
51
52=pod
53