This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
make global symbol exports AIX-specific
[perl5.git] / t / comp / require.t
CommitLineData
f46d017c
GS
1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
93430cb4 5 unshift @INC, ('.', '../lib');
f46d017c
GS
6}
7
8# don't make this lexical
9$i = 1;
a7cb1f99 10print "1..16\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
a7cb1f99
GS
26# new style version numbers
27
28eval { require v5.5.630; };
29print "# $@\nnot " if $@;
30print "ok ",$i++,"\n";
31
32eval { require v10.0.2; };
33print "# $@\nnot " unless $@ =~ /^Perl v10\.0\.2 required/;
34print "ok ",$i++,"\n";
35
36eval q{ use v5.5.630; };
37print "# $@\nnot " if $@;
38print "ok ",$i++,"\n";
39
40eval q{ use v10.0.2; };
41print "# $@\nnot " unless $@ =~ /^Perl v10\.0\.2 required/;
42print "ok ",$i++,"\n";
43
44my $ver = v5.5.630;
45eval { require $ver; };
46print "# $@\nnot " if $@;
47print "ok ",$i++,"\n";
48
49$ver = v10.0.2;
50eval { require $ver; };
51print "# $@\nnot " unless $@ =~ /^Perl v10\.0\.2 required/;
52print "ok ",$i++,"\n";
53
54print "not " unless v5.5.1 gt v5.5;
55print "ok ",$i++,"\n";
56
57print "not " unless 5.005_01 > v5.5;
58print "ok ",$i++,"\n";
59
60print "not " unless 5.005_64 - v5.5.640 < 0.0000001;
61print "ok ",$i++,"\n";
62
63{
64 use utf8;
65 print "not " unless v5.5.640 eq "\x{5}\x{5}\x{280}";
66 print "ok ",$i++,"\n";
67
68 print "not " unless v7.15 eq "\x{7}\x{f}";
69 print "ok ",$i++,"\n";
70
71 print "not "
72 unless v1.20.300.4000.50000.600000 eq "\x{1}\x{14}\x{12c}\x{fa0}\x{c350}\x{927c0}";
73 print "ok ",$i++,"\n";
74}
75
4a9ae47a
GS
76# interaction with pod (see the eof)
77write_file('bleah.pm', "print 'ok $i\n'; 1;\n");
78require "bleah.pm";
79$i++;
80
f46d017c
GS
81# run-time failure in require
82do_require "0;\n";
83print "# $@\nnot " unless $@ =~ /did not return a true/;
84print "ok ",$i++,"\n";
85
86# compile-time failure in require
87do_require "1)\n";
f0ec1f9a 88# bison says 'parse error' instead of 'syntax error',
d91e2bdb 89# various yaccs may or may not capitalize 'syntax'.
f0ec1f9a 90print "# $@\nnot " unless $@ =~ /(syntax|parse) error/mi;
f46d017c
GS
91print "ok ",$i++,"\n";
92
93# successful require
94do_require "1";
95print "# $@\nnot " if $@;
96print "ok ",$i++,"\n";
97
562a7b0c 98END { 1 while unlink 'bleah.pm'; }
4a9ae47a
GS
99
100# ***interaction with pod (don't put any thing after here)***
101
102=pod