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