Once again syncing after too long an absence
[p5sagit/p5-mst-13.2.git] / t / comp / require.t
CommitLineData
f46d017c 1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
22d4bb9c 5 @INC = '.';
6 push @INC, '../lib';
f46d017c 7}
8
9# don't make this lexical
10$i = 1;
4b19af01 11print "1..23\n";
f46d017c 12
13sub do_require {
14 %INC = ();
4a9ae47a 15 write_file('bleah.pm',@_);
f46d017c 16 eval { require "bleah.pm" };
17 my @a; # magic guard for scope violations (must be first lexical in file)
18}
19
4a9ae47a 20sub write_file {
21 my $f = shift;
22 open(REQ,">$f") or die "Can't write '$f': $!";
4b19af01 23 binmode REQ;
0e06870b 24 use bytes;
4a9ae47a 25 print REQ @_;
26 close REQ;
27}
28
9f3d182e 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 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 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 62print "# $@\nnot " unless $@ =~ /^Perl v10\.0\.2 required/;
63print "ok ",$i++,"\n";
64
44dcb63b 65my $ver = 5.005_63;
a7cb1f99 66eval { require $ver; };
67print "# $@\nnot " if $@;
68print "ok ",$i++,"\n";
69
44dcb63b 70# check inaccurate fp
dbe7b177 71$ver = 10.2;
72eval { require $ver; };
73print "# $@\nnot " unless $@ =~ /^Perl v10\.200\.0 required/;
74print "ok ",$i++,"\n";
44dcb63b 75
76$ver = 10.000_02;
a7cb1f99 77eval { require $ver; };
44dcb63b 78print "# $@\nnot " unless $@ =~ /^Perl v10\.0\.20 required/;
a7cb1f99 79print "ok ",$i++,"\n";
80
dd629d5b 81print "not " unless 5.5.1 gt v5.5;
a7cb1f99 82print "ok ",$i++,"\n";
83
a7cb1f99 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 97# interaction with pod (see the eof)
98write_file('bleah.pm', "print 'ok $i\n'; 1;\n");
99require "bleah.pm";
100$i++;
101
f46d017c 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 112print "ok ",$i++,"\n";
113
114# successful require
115do_require "1";
116print "# $@\nnot " if $@;
117print "ok ",$i++,"\n";
118
faa7e5bb 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;
4b19af01 128
129# UTF-encoded things
130my $utf8 = chr(0xFEFF);
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]));
0e06870b 136 return @_ == 3 && $_[2] ? pack("$_[0]", 0xFEFF) . $utf16 : $utf16;
4b19af01 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
faa7e5bb 141
142END { 1 while unlink 'bleah.pm'; 1 while unlink 'bleah.do'; }
4a9ae47a 143
144# ***interaction with pod (don't put any thing after here)***
145
146=pod