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