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