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 $Is_UTF8 = (${^OPEN} || "") =~ /:utf8/;
|
---|
14 | my $total_tests = 31;
|
---|
15 | if ($Is_EBCDIC || $Is_UTF8) { $total_tests -= 3; }
|
---|
16 | print "1..$total_tests\n";
|
---|
17 |
|
---|
18 | sub do_require {
|
---|
19 | %INC = ();
|
---|
20 | write_file('bleah.pm',@_);
|
---|
21 | eval { require "bleah.pm" };
|
---|
22 | my @a; # magic guard for scope violations (must be first lexical in file)
|
---|
23 | }
|
---|
24 |
|
---|
25 | sub write_file {
|
---|
26 | my $f = shift;
|
---|
27 | open(REQ,">$f") or die "Can't write '$f': $!";
|
---|
28 | binmode REQ;
|
---|
29 | use bytes;
|
---|
30 | print REQ @_;
|
---|
31 | close REQ or die "Could not close $f: $!";
|
---|
32 | }
|
---|
33 |
|
---|
34 | eval {require 5.005};
|
---|
35 | print "# $@\nnot " if $@;
|
---|
36 | print "ok ",$i++,"\n";
|
---|
37 |
|
---|
38 | eval { require 5.005 };
|
---|
39 | print "# $@\nnot " if $@;
|
---|
40 | print "ok ",$i++,"\n";
|
---|
41 |
|
---|
42 | eval { require 5.005; };
|
---|
43 | print "# $@\nnot " if $@;
|
---|
44 | print "ok ",$i++,"\n";
|
---|
45 |
|
---|
46 | eval {
|
---|
47 | require 5.005
|
---|
48 | };
|
---|
49 | print "# $@\nnot " if $@;
|
---|
50 | print "ok ",$i++,"\n";
|
---|
51 |
|
---|
52 | # new style version numbers
|
---|
53 |
|
---|
54 | eval { require v5.5.630; };
|
---|
55 | print "# $@\nnot " if $@;
|
---|
56 | print "ok ",$i++,"\n";
|
---|
57 |
|
---|
58 | eval { require 10.0.2; };
|
---|
59 | print "# $@\nnot " unless $@ =~ /^Perl v10\.0\.2 required/;
|
---|
60 | print "ok ",$i++,"\n";
|
---|
61 |
|
---|
62 | eval q{ use v5.5.630; };
|
---|
63 | print "# $@\nnot " if $@;
|
---|
64 | print "ok ",$i++,"\n";
|
---|
65 |
|
---|
66 | eval q{ use 10.0.2; };
|
---|
67 | print "# $@\nnot " unless $@ =~ /^Perl v10\.0\.2 required/;
|
---|
68 | print "ok ",$i++,"\n";
|
---|
69 |
|
---|
70 | my $ver = 5.005_63;
|
---|
71 | eval { require $ver; };
|
---|
72 | print "# $@\nnot " if $@;
|
---|
73 | print "ok ",$i++,"\n";
|
---|
74 |
|
---|
75 | # check inaccurate fp
|
---|
76 | $ver = 10.2;
|
---|
77 | eval { require $ver; };
|
---|
78 | print "# $@\nnot " unless $@ =~ /^Perl v10\.200\.0 required/;
|
---|
79 | print "ok ",$i++,"\n";
|
---|
80 |
|
---|
81 | $ver = 10.000_02;
|
---|
82 | eval { require $ver; };
|
---|
83 | print "# $@\nnot " unless $@ =~ /^Perl v10\.0\.20 required/;
|
---|
84 | print "ok ",$i++,"\n";
|
---|
85 |
|
---|
86 | print "not " unless 5.5.1 gt v5.5;
|
---|
87 | print "ok ",$i++,"\n";
|
---|
88 |
|
---|
89 | {
|
---|
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 | # Test that scalar context is forced for require
|
---|
134 |
|
---|
135 | write_file('bleah.pm', <<'**BLEAH**'
|
---|
136 | print "not " if !defined wantarray || wantarray ne '';
|
---|
137 | print "ok $i - require() context\n";
|
---|
138 | 1;
|
---|
139 | **BLEAH**
|
---|
140 | );
|
---|
141 | delete $INC{"bleah.pm"}; ++$::i;
|
---|
142 | $foo = eval q{require bleah}; delete $INC{"bleah.pm"}; ++$::i;
|
---|
143 | @foo = eval q{require bleah}; delete $INC{"bleah.pm"}; ++$::i;
|
---|
144 | eval q{require bleah}; delete $INC{"bleah.pm"}; ++$::i;
|
---|
145 | eval q{$_=$_+2;require bleah}; delete $INC{"bleah.pm"}; ++$::i;
|
---|
146 | $foo = eval {require bleah}; delete $INC{"bleah.pm"}; ++$::i;
|
---|
147 | @foo = eval {require bleah}; delete $INC{"bleah.pm"}; ++$::i;
|
---|
148 | eval {require bleah};
|
---|
149 |
|
---|
150 | # Test for fix of RT #24404 : "require $scalar" may load a directory
|
---|
151 | my $r = "threads";
|
---|
152 | eval { require $r };
|
---|
153 | $i++;
|
---|
154 | if($@ =~ /Directory .*threads not allowed in require/) {
|
---|
155 | print "ok $i\n";
|
---|
156 | } else {
|
---|
157 | print "not ok $i\n";
|
---|
158 | }
|
---|
159 |
|
---|
160 | ##########################################
|
---|
161 | # What follows are UTF-8 specific tests. #
|
---|
162 | # Add generic tests before this point. #
|
---|
163 | ##########################################
|
---|
164 |
|
---|
165 | # UTF-encoded things - skipped on EBCDIC machines and on UTF-8 input
|
---|
166 |
|
---|
167 | if ($Is_EBCDIC || $Is_UTF8) { exit; }
|
---|
168 |
|
---|
169 | my $utf8 = chr(0xFEFF);
|
---|
170 |
|
---|
171 | $i++; do_require(qq(${utf8}print "ok $i\n"; 1;\n));
|
---|
172 |
|
---|
173 | sub bytes_to_utf16 {
|
---|
174 | my $utf16 = pack("$_[0]*", unpack("C*", $_[1]));
|
---|
175 | return @_ == 3 && $_[2] ? pack("$_[0]", 0xFEFF) . $utf16 : $utf16;
|
---|
176 | }
|
---|
177 |
|
---|
178 | $i++; do_require(bytes_to_utf16('n', qq(print "ok $i\\n"; 1;\n), 1)); # BE
|
---|
179 | $i++; do_require(bytes_to_utf16('v', qq(print "ok $i\\n"; 1;\n), 1)); # LE
|
---|
180 |
|
---|
181 | END { 1 while unlink 'bleah.pm'; 1 while unlink 'bleah.do'; }
|
---|
182 |
|
---|
183 | # ***interaction with pod (don't put any thing after here)***
|
---|
184 |
|
---|
185 | =pod
|
---|