Document the IVdf UVuf UVof UVxf.
[p5sagit/p5-mst-13.2.git] / t / comp / require.t
CommitLineData
f46d017c 1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
93430cb4 5 unshift @INC, ('.', '../lib');
f46d017c 6}
7
8# don't make this lexical
9$i = 1;
b250498f 10print "1..23\n";
f46d017c 11
12sub do_require {
13 %INC = ();
4a9ae47a 14 write_file('bleah.pm',@_);
f46d017c 15 eval { require "bleah.pm" };
16 my @a; # magic guard for scope violations (must be first lexical in file)
17}
18
4a9ae47a 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
9f3d182e 26eval {require 5.005};
27print "# $@\nnot " if $@;
28print "ok ",$i++,"\n";
29
30eval { require 5.005 };
31print "# $@\nnot " if $@;
32print "ok ",$i++,"\n";
33
34eval { require 5.005; };
35print "# $@\nnot " if $@;
36print "ok ",$i++,"\n";
37
38eval {
39 require 5.005
40};
41print "# $@\nnot " if $@;
42print "ok ",$i++,"\n";
43
a7cb1f99 44# new style version numbers
45
46eval { require v5.5.630; };
47print "# $@\nnot " if $@;
48print "ok ",$i++,"\n";
49
dd629d5b 50eval { require 10.0.2; };
a7cb1f99 51print "# $@\nnot " unless $@ =~ /^Perl v10\.0\.2 required/;
52print "ok ",$i++,"\n";
53
54eval q{ use v5.5.630; };
55print "# $@\nnot " if $@;
56print "ok ",$i++,"\n";
57
dd629d5b 58eval q{ use 10.0.2; };
a7cb1f99 59print "# $@\nnot " unless $@ =~ /^Perl v10\.0\.2 required/;
60print "ok ",$i++,"\n";
61
44dcb63b 62my $ver = 5.005_63;
a7cb1f99 63eval { require $ver; };
64print "# $@\nnot " if $@;
65print "ok ",$i++,"\n";
66
44dcb63b 67# check inaccurate fp
dbe7b177 68$ver = 10.2;
69eval { require $ver; };
70print "# $@\nnot " unless $@ =~ /^Perl v10\.200\.0 required/;
71print "ok ",$i++,"\n";
44dcb63b 72
73$ver = 10.000_02;
a7cb1f99 74eval { require $ver; };
44dcb63b 75print "# $@\nnot " unless $@ =~ /^Perl v10\.0\.20 required/;
a7cb1f99 76print "ok ",$i++,"\n";
77
dd629d5b 78print "not " unless 5.5.1 gt v5.5;
a7cb1f99 79print "ok ",$i++,"\n";
80
a7cb1f99 81{
82 use utf8;
83 print "not " unless v5.5.640 eq "\x{5}\x{5}\x{280}";
84 print "ok ",$i++,"\n";
85
86 print "not " unless v7.15 eq "\x{7}\x{f}";
87 print "ok ",$i++,"\n";
88
89 print "not "
90 unless v1.20.300.4000.50000.600000 eq "\x{1}\x{14}\x{12c}\x{fa0}\x{c350}\x{927c0}";
91 print "ok ",$i++,"\n";
92}
93
4a9ae47a 94# interaction with pod (see the eof)
95write_file('bleah.pm', "print 'ok $i\n'; 1;\n");
96require "bleah.pm";
97$i++;
98
f46d017c 99# run-time failure in require
100do_require "0;\n";
101print "# $@\nnot " unless $@ =~ /did not return a true/;
102print "ok ",$i++,"\n";
103
104# compile-time failure in require
105do_require "1)\n";
f0ec1f9a 106# bison says 'parse error' instead of 'syntax error',
d91e2bdb 107# various yaccs may or may not capitalize 'syntax'.
f0ec1f9a 108print "# $@\nnot " unless $@ =~ /(syntax|parse) error/mi;
f46d017c 109print "ok ",$i++,"\n";
110
111# successful require
112do_require "1";
113print "# $@\nnot " if $@;
114print "ok ",$i++,"\n";
115
faa7e5bb 116# do FILE shouldn't see any outside lexicals
117my $x = "ok $i\n";
118write_file("bleah.do", <<EOT);
119\$x = "not ok $i\\n";
120EOT
121do "bleah.do";
122dofile();
123sub dofile { do "bleah.do"; };
124print $x;
faa7e5bb 125
b250498f 126# UTF-encoded things
127my $utf8 = chr(0xFEFF);
dea0fc0b 128
129$i++; do_require(qq(${utf8}print "ok $i\n"; 1;\n));
130
131sub bytes_to_utf16 {
132 my $utf16 = pack("$_[0]*", unpack("C*", $_[1]));
133 return @_ == 3 && $_[2] ? pack("$_[0]", 0xFEFF) . $utf16 : $utf16;
134}
135
136$i++; do_require(bytes_to_utf16('n', qq(print "ok $i\\n"; 1;\n), 1)); # BE
137$i++; do_require(bytes_to_utf16('v', qq(print "ok $i\\n"; 1;\n), 1)); # LE
b250498f 138
faa7e5bb 139END { 1 while unlink 'bleah.pm'; 1 while unlink 'bleah.do'; }
4a9ae47a 140
141# ***interaction with pod (don't put any thing after here)***
142
143=pod