Make print, syswrite, send, readline, getc honour utf8-ness of PerlIO.
[p5sagit/p5-mst-13.2.git] / t / comp / require.t
1 #!./perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '.';
6     push @INC, '../lib';
7 }
8
9 # don't make this lexical
10 $i = 1;
11 print "1..23\n";
12
13 sub do_require {
14     %INC = ();
15     write_file('bleah.pm',@_);
16     eval { require "bleah.pm" };
17     my @a; # magic guard for scope violations (must be first lexical in file)
18 }
19
20 sub write_file {
21     my $f = shift;
22     open(REQ,">$f") or die "Can't write '$f': $!";
23     binmode REQ;
24     use bytes;
25     print REQ @_;
26     close REQ;
27 }
28
29 eval {require 5.005};
30 print "# $@\nnot " if $@;
31 print "ok ",$i++,"\n";
32
33 eval { require 5.005 };
34 print "# $@\nnot " if $@;
35 print "ok ",$i++,"\n";
36
37 eval { require 5.005; };
38 print "# $@\nnot " if $@;
39 print "ok ",$i++,"\n";
40
41 eval {
42     require 5.005
43 };
44 print "# $@\nnot " if $@;
45 print "ok ",$i++,"\n";
46
47 # new style version numbers
48
49 eval { require v5.5.630; };
50 print "# $@\nnot " if $@;
51 print "ok ",$i++,"\n";
52
53 eval { require 10.0.2; };
54 print "# $@\nnot " unless $@ =~ /^Perl v10\.0\.2 required/;
55 print "ok ",$i++,"\n";
56
57 eval q{ use v5.5.630; };
58 print "# $@\nnot " if $@;
59 print "ok ",$i++,"\n";
60
61 eval q{ use 10.0.2; };
62 print "# $@\nnot " unless $@ =~ /^Perl v10\.0\.2 required/;
63 print "ok ",$i++,"\n";
64
65 my $ver = 5.005_63;
66 eval { require $ver; };
67 print "# $@\nnot " if $@;
68 print "ok ",$i++,"\n";
69
70 # check inaccurate fp
71 $ver = 10.2;
72 eval { require $ver; };
73 print "# $@\nnot " unless $@ =~ /^Perl v10\.200\.0 required/;
74 print "ok ",$i++,"\n";
75
76 $ver = 10.000_02;
77 eval { require $ver; };
78 print "# $@\nnot " unless $@ =~ /^Perl v10\.0\.20 required/;
79 print "ok ",$i++,"\n";
80
81 print "not " unless 5.5.1 gt v5.5;
82 print "ok ",$i++,"\n";
83
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
97 # interaction with pod (see the eof)
98 write_file('bleah.pm', "print 'ok $i\n'; 1;\n");
99 require "bleah.pm";
100 $i++;
101
102 # run-time failure in require
103 do_require "0;\n";
104 print "# $@\nnot " unless $@ =~ /did not return a true/;
105 print "ok ",$i++,"\n";
106
107 # compile-time failure in require
108 do_require "1)\n";
109 # bison says 'parse error' instead of 'syntax error',
110 # various yaccs may or may not capitalize 'syntax'.
111 print "# $@\nnot " unless $@ =~ /(syntax|parse) error/mi;
112 print "ok ",$i++,"\n";
113
114 # successful require
115 do_require "1";
116 print "# $@\nnot " if $@;
117 print "ok ",$i++,"\n";
118
119 # do FILE shouldn't see any outside lexicals
120 my $x = "ok $i\n";
121 write_file("bleah.do", <<EOT);
122 \$x = "not ok $i\\n";
123 EOT
124 do "bleah.do";
125 dofile();
126 sub dofile { do "bleah.do"; };
127 print $x;
128
129 # UTF-encoded things
130 my $utf8 = chr(0xFEFF);
131
132 $i++; do_require(qq(${utf8}print "ok $i\n"; 1;\n));
133
134 sub bytes_to_utf16 {
135     my $utf16 = pack("$_[0]*", unpack("C*", $_[1]));
136     return @_ == 3 && $_[2] ? pack("$_[0]", 0xFEFF) . $utf16 : $utf16;
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
141
142 END { 1 while unlink 'bleah.pm'; 1 while unlink 'bleah.do'; }
143
144 # ***interaction with pod (don't put any thing after here)***
145
146 =pod