Re: Why t/lib/extutils.t is failing (was Re: [PATCH] Re: [PATCH] Re: [SPAM] Re:...
[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
12 my $Is_EBCDIC = (ord('A') == 193) ? 1 : 0;
13 my $total_tests = 23;
14 if ($Is_EBCDIC) { $total_tests = 20; }
15 print "1..$total_tests\n";
16
17 sub do_require {
18     %INC = ();
19     write_file('bleah.pm',@_);
20     eval { require "bleah.pm" };
21     my @a; # magic guard for scope violations (must be first lexical in file)
22 }
23
24 sub write_file {
25     my $f = shift;
26     open(REQ,">$f") or die "Can't write '$f': $!";
27     binmode REQ;
28     use bytes;
29     print REQ @_;
30     close REQ;
31 }
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 { require 5.005; };
42 print "# $@\nnot " if $@;
43 print "ok ",$i++,"\n";
44
45 eval {
46     require 5.005
47 };
48 print "# $@\nnot " if $@;
49 print "ok ",$i++,"\n";
50
51 # new style version numbers
52
53 eval { require v5.5.630; };
54 print "# $@\nnot " if $@;
55 print "ok ",$i++,"\n";
56
57 eval { require 10.0.2; };
58 print "# $@\nnot " unless $@ =~ /^Perl v10\.0\.2 required/;
59 print "ok ",$i++,"\n";
60
61 eval q{ use v5.5.630; };
62 print "# $@\nnot " if $@;
63 print "ok ",$i++,"\n";
64
65 eval q{ use 10.0.2; };
66 print "# $@\nnot " unless $@ =~ /^Perl v10\.0\.2 required/;
67 print "ok ",$i++,"\n";
68
69 my $ver = 5.005_63;
70 eval { require $ver; };
71 print "# $@\nnot " if $@;
72 print "ok ",$i++,"\n";
73
74 # check inaccurate fp
75 $ver = 10.2;
76 eval { require $ver; };
77 print "# $@\nnot " unless $@ =~ /^Perl v10\.200\.0 required/;
78 print "ok ",$i++,"\n";
79
80 $ver = 10.000_02;
81 eval { require $ver; };
82 print "# $@\nnot " unless $@ =~ /^Perl v10\.0\.20 required/;
83 print "ok ",$i++,"\n";
84
85 print "not " unless 5.5.1 gt v5.5;
86 print "ok ",$i++,"\n";
87
88 {
89     use utf8;
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
101 # interaction with pod (see the eof)
102 write_file('bleah.pm', "print 'ok $i\n'; 1;\n");
103 require "bleah.pm";
104 $i++;
105
106 # run-time failure in require
107 do_require "0;\n";
108 print "# $@\nnot " unless $@ =~ /did not return a true/;
109 print "ok ",$i++,"\n";
110
111 # compile-time failure in require
112 do_require "1)\n";
113 # bison says 'parse error' instead of 'syntax error',
114 # various yaccs may or may not capitalize 'syntax'.
115 print "# $@\nnot " unless $@ =~ /(syntax|parse) error/mi;
116 print "ok ",$i++,"\n";
117
118 # successful require
119 do_require "1";
120 print "# $@\nnot " if $@;
121 print "ok ",$i++,"\n";
122
123 # do FILE shouldn't see any outside lexicals
124 my $x = "ok $i\n";
125 write_file("bleah.do", <<EOT);
126 \$x = "not ok $i\\n";
127 EOT
128 do "bleah.do";
129 dofile();
130 sub dofile { do "bleah.do"; };
131 print $x;
132
133 # UTF-encoded things - skipped on EBCDIC machines
134
135 if ($Is_EBCDIC) { exit; }
136
137 my $utf8 = chr(0xFEFF);
138
139 $i++; do_require(qq(${utf8}print "ok $i\n"; 1;\n));
140
141 sub bytes_to_utf16 {
142     my $utf16 = pack("$_[0]*", unpack("C*", $_[1]));
143     return @_ == 3 && $_[2] ? pack("$_[0]", 0xFEFF) . $utf16 : $utf16;
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
148
149 END { 1 while unlink 'bleah.pm'; 1 while unlink 'bleah.do'; }
150
151 # ***interaction with pod (don't put any thing after here)***
152
153 =pod