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