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