Commit | Line | Data |
---|---|---|
8d063cd8 LW |
1 | #!./perl |
2 | ||
90ce63d5 | 3 | BEGIN { |
90ce63d5 RS |
4 | $| = 1; |
5 | chdir 't' if -d 't'; | |
20822f61 | 6 | @INC = '../lib'; |
774d564b | 7 | $SIG{__WARN__} = sub { die "Dying on warning: ", @_ }; |
90ce63d5 | 8 | } |
8d063cd8 | 9 | |
9f1b1f2d | 10 | use warnings; |
04fee9b5 | 11 | use Config; |
9f1b1f2d | 12 | |
0bee926d | 13 | my $test = 1; |
90ce63d5 | 14 | sub ok { |
0bee926d MS |
15 | my($ok, $info, $todo) = @_; |
16 | ||
17 | # You have to do it this way or VMS will get confused. | |
18 | printf "%s $test%s\n", $ok ? "ok" : "not ok", | |
19 | $todo ? " # TODO $todo" : ''; | |
20 | ||
21 | unless( $ok ) { | |
22 | printf "# Failed test at line %d\n", (caller)[2]; | |
23 | print "# $info" if defined $info; | |
90ce63d5 | 24 | } |
0bee926d MS |
25 | |
26 | $test++; | |
27 | return $ok; | |
28 | } | |
29 | ||
30 | sub skip { | |
31 | my($reason) = @_; | |
32 | ||
33 | printf "ok $test # skipped%s\n", defined $reason ? ": $reason" : ''; | |
34 | ||
35 | $test++; | |
36 | return 1; | |
90ce63d5 RS |
37 | } |
38 | ||
306196c3 | 39 | print "1..44\n"; |
0bee926d | 40 | |
3e3baf6d | 41 | $Is_MSWin32 = $^O eq 'MSWin32'; |
2986a63f | 42 | $Is_NetWare = $^O eq 'NetWare'; |
3e3baf6d | 43 | $Is_VMS = $^O eq 'VMS'; |
be708cc0 JH |
44 | $Is_Dos = $^O eq 'dos'; |
45 | $Is_os2 = $^O eq 'os2'; | |
46 | $Is_Cygwin = $^O eq 'cygwin'; | |
47 | $Is_MacOS = $^O eq 'MacOS'; | |
dc22e1c4 | 48 | $Is_MPE = $^O eq 'mpeix'; |
be708cc0 | 49 | |
c363d00c CB |
50 | $PERL = ($Is_NetWare ? 'perl' : |
51 | ($Is_MacOS || $Is_VMS) ? $^X : | |
52 | $Is_MSWin32 ? '.\perl' : | |
be708cc0 | 53 | './perl'); |
68dc0745 | 54 | |
39e571d4 | 55 | eval '$ENV{"FOO"} = "hi there";'; # check that ENV is inited inside eval |
26f6e342 NK |
56 | # cmd.exe will echo 'variable=value' but 4nt will echo just the value |
57 | # -- Nikola Knezevic | |
be708cc0 JH |
58 | if ($Is_MSWin32) { ok `set FOO` =~ /^(FOO=)?hi there$/; } |
59 | elsif ($Is_MacOS) { ok "1 # skipped", 1; } | |
c363d00c | 60 | elsif ($Is_VMS) { ok `write sys\$output f\$trnlnm("FOO")` eq "hi there\n"; } |
be708cc0 | 61 | else { ok `echo \$FOO` eq "hi there\n"; } |
8d063cd8 | 62 | |
bf38876a | 63 | unlink 'ajslkdfpqjsjfk'; |
8d063cd8 | 64 | $! = 0; |
90ce63d5 | 65 | open(FOO,'ajslkdfpqjsjfk'); |
0bee926d | 66 | ok $!, $!; |
90ce63d5 | 67 | close FOO; # just mention it, squelch used-only-once |
8d063cd8 | 68 | |
be708cc0 | 69 | if ($Is_MSWin32 || $Is_NetWare || $Is_Dos || $Is_MPE || $Is_MacOS) { |
124f2019 | 70 | skip('SIGINT not safe on this platform') for 1..2; |
68dc0745 | 71 | } |
72 | else { | |
c363d00c CB |
73 | # the next tests are done in a subprocess because sh spits out a |
74 | # newline onto stderr when a child process kills itself with SIGINT. | |
04fee9b5 | 75 | # We use a pipe rather than system() because the VMS command buffer |
c363d00c CB |
76 | # would overflow with a command that long. |
77 | ||
78 | open( CMDPIPE, "| $PERL"); | |
79 | ||
80 | print CMDPIPE <<'END'; | |
378cc40b | 81 | |
79072805 | 82 | $| = 1; # command buffering |
378cc40b | 83 | |
b715f106 MB |
84 | $SIG{"INT"} = "ok3"; kill "INT",$$; sleep 1; |
85 | $SIG{"INT"} = "IGNORE"; kill "INT",$$; sleep 1; print "ok 4\n"; | |
0bee926d | 86 | $SIG{"INT"} = "DEFAULT"; kill "INT",$$; sleep 1; print "not ok 4\n"; |
79072805 LW |
87 | |
88 | sub ok3 { | |
89 | if (($x = pop(@_)) eq "INT") { | |
90 | print "ok 3\n"; | |
91 | } | |
92 | else { | |
652ed9f8 | 93 | print "not ok 3 ($x @_)\n"; |
79072805 LW |
94 | } |
95 | } | |
96 | ||
97 | END | |
c363d00c CB |
98 | |
99 | close CMDPIPE; | |
100 | ||
fae3d9ea | 101 | $test += 2; |
68dc0745 | 102 | } |
a687059c | 103 | |
68dc0745 | 104 | # can we slice ENV? |
105 | @val1 = @ENV{keys(%ENV)}; | |
a687059c | 106 | @val2 = values(%ENV); |
0bee926d MS |
107 | ok join(':',@val1) eq join(':',@val2); |
108 | ok @val1 > 1; | |
90ce63d5 RS |
109 | |
110 | # regex vars | |
111 | 'foobarbaz' =~ /b(a)r/; | |
0bee926d MS |
112 | ok $` eq 'foo', $`; |
113 | ok $& eq 'bar', $&; | |
114 | ok $' eq 'baz', $'; | |
115 | ok $+ eq 'a', $+; | |
90ce63d5 RS |
116 | |
117 | # $" | |
118 | @a = qw(foo bar baz); | |
0bee926d | 119 | ok "@a" eq "foo bar baz", "@a"; |
90ce63d5 RS |
120 | { |
121 | local $" = ','; | |
0bee926d | 122 | ok "@a" eq "foo,bar,baz", "@a"; |
90ce63d5 | 123 | } |
a687059c | 124 | |
90ce63d5 RS |
125 | # $; |
126 | %h = (); | |
127 | $h{'foo', 'bar'} = 1; | |
0bee926d | 128 | ok((keys %h)[0] eq "foo\034bar", (keys %h)[0]); |
90ce63d5 RS |
129 | { |
130 | local $; = 'x'; | |
131 | %h = (); | |
132 | $h{'foo', 'bar'} = 1; | |
0bee926d | 133 | ok((keys %h)[0] eq 'fooxbar', (keys %h)[0]); |
90ce63d5 | 134 | } |
ed6116ce | 135 | |
90ce63d5 | 136 | # $?, $@, $$ |
5aabfad6 | 137 | system qq[$PERL -e "exit(0)"]; |
0bee926d | 138 | ok $? == 0, $?; |
5aabfad6 | 139 | system qq[$PERL -e "exit(1)"]; |
0bee926d | 140 | ok $? != 0, $?; |
90ce63d5 RS |
141 | |
142 | eval { die "foo\n" }; | |
0bee926d | 143 | ok $@ eq "foo\n", $@; |
90ce63d5 | 144 | |
0bee926d | 145 | ok $$ > 0, $$; |
306196c3 MS |
146 | eval { $$++ }; |
147 | ok $@ =~ /^Modification of a read-only value attempted/; | |
90ce63d5 RS |
148 | |
149 | # $^X and $0 | |
ed37317b | 150 | { |
3e3baf6d | 151 | if ($^O eq 'qnx') { |
7fbf1995 | 152 | chomp($wd = `/usr/bin/fullpath -t`); |
68dc0745 | 153 | } |
04fee9b5 | 154 | elsif($Is_Cygwin || $Config{'d_procselfexe'}) { |
1cab015a EF |
155 | # Cygwin turns the symlink into the real file |
156 | chomp($wd = `pwd`); | |
157 | $wd =~ s#/t$##; | |
158 | } | |
ed344e4f IZ |
159 | elsif($Is_os2) { |
160 | $wd = Cwd::sys_cwd(); | |
161 | } | |
be708cc0 JH |
162 | elsif($Is_MacOS) { |
163 | $wd = ':'; | |
164 | } | |
68dc0745 | 165 | else { |
166 | $wd = '.'; | |
167 | } | |
c363d00c | 168 | my $perl = ($Is_MacOS || $Is_VMS) ? $^X : "$wd/perl"; |
ed37317b TB |
169 | my $headmaybe = ''; |
170 | my $tailmaybe = ''; | |
68dc0745 | 171 | $script = "$wd/show-shebang"; |
ed37317b TB |
172 | if ($Is_MSWin32) { |
173 | chomp($wd = `cd`); | |
8ac9c18d GS |
174 | $wd =~ s|\\|/|g; |
175 | $perl = "$wd/perl.exe"; | |
176 | $script = "$wd/show-shebang.bat"; | |
ed37317b TB |
177 | $headmaybe = <<EOH ; |
178 | \@rem =' | |
179 | \@echo off | |
180 | $perl -x \%0 | |
181 | goto endofperl | |
182 | \@rem '; | |
183 | EOH | |
184 | $tailmaybe = <<EOT ; | |
185 | ||
186 | __END__ | |
187 | :endofperl | |
188 | EOT | |
189 | } | |
ed344e4f IZ |
190 | elsif ($Is_os2) { |
191 | $script = "./show-shebang"; | |
192 | } | |
be708cc0 JH |
193 | elsif ($Is_MacOS) { |
194 | $script = ":show-shebang"; | |
195 | } | |
c363d00c CB |
196 | elsif ($Is_VMS) { |
197 | $script = "[]show-shebang"; | |
be708cc0 | 198 | } |
a1a0e61e | 199 | if ($^O eq 'os390' or $^O eq 'posix-bc' or $^O eq 'vmesa') { # no shebang |
9d116dd7 JH |
200 | $headmaybe = <<EOH ; |
201 | eval 'exec ./perl -S \$0 \${1+"\$\@"}' | |
202 | if 0; | |
203 | EOH | |
204 | } | |
2eecd615 | 205 | $s1 = "\$^X is $perl, \$0 is $script\n"; |
0bee926d MS |
206 | ok open(SCRIPT, ">$script"), $!; |
207 | ok print(SCRIPT $headmaybe . <<EOB . <<'EOF' . $tailmaybe), $!; | |
774d564b | 208 | #!$wd/perl |
209 | EOB | |
90ce63d5 RS |
210 | print "\$^X is $^X, \$0 is $0\n"; |
211 | EOF | |
0bee926d MS |
212 | ok close(SCRIPT), $!; |
213 | ok chmod(0755, $script), $!; | |
c363d00c | 214 | $_ = ($Is_MacOS || $Is_VMS) ? `$perl $script` : `$script`; |
ed344e4f | 215 | s/\.exe//i if $Is_Dos or $Is_Cygwin or $Is_os2; |
68dc0745 | 216 | s{\bminiperl\b}{perl}; # so that test doesn't fail with miniperl |
ed37317b | 217 | s{is perl}{is $perl}; # for systems where $^X is only a basename |
a6c40364 | 218 | s{\\}{/}g; |
0bee926d | 219 | ok((($Is_MSWin32 || $Is_os2) ? uc($_) eq uc($s1) : $_ eq $s1), " :$_:!=:$s1:"); |
ed37317b | 220 | $_ = `$perl $script`; |
ed344e4f | 221 | s/\.exe//i if $Is_Dos or $Is_os2; |
a6c40364 | 222 | s{\\}{/}g; |
0bee926d MS |
223 | ok((($Is_MSWin32 || $Is_os2) ? uc($_) eq uc($s1) : $_ eq $s1), " :$_:!=:$s1: after `$perl $script`"); |
224 | ok unlink($script), $!; | |
68dc0745 | 225 | } |
ed6116ce | 226 | |
90ce63d5 | 227 | # $], $^O, $^T |
0bee926d MS |
228 | ok $] >= 5.00319, $]; |
229 | ok $^O; | |
230 | ok $^T > 850000000, $^T; | |
66b1d557 | 231 | |
be708cc0 | 232 | if ($Is_VMS || $Is_Dos || $Is_MacOS) { |
c363d00c | 233 | skip("%ENV manipulations fail or aren't safe on $^O") for 1..2; |
66b1d557 HM |
234 | } |
235 | else { | |
3e3baf6d | 236 | $PATH = $ENV{PATH}; |
7ddf2a0a | 237 | $PDL = $ENV{PERL_DESTRUCT_LEVEL} || 0; |
3e3baf6d TB |
238 | $ENV{foo} = "bar"; |
239 | %ENV = (); | |
240 | $ENV{PATH} = $PATH; | |
7ddf2a0a | 241 | $ENV{PERL_DESTRUCT_LEVEL} = $PDL || 0; |
0bee926d | 242 | ok ($Is_MSWin32 ? (`set foo 2>NUL` eq "") |
3e3baf6d TB |
243 | : (`echo \$foo` eq "\n") ); |
244 | ||
ec00bdd8 | 245 | $ENV{__NoNeSuCh} = "foo"; |
3e3baf6d | 246 | $0 = "bar"; |
26f6e342 NK |
247 | # cmd.exe will echo 'variable=value' but 4nt will echo just the value |
248 | # -- Nikola Knezevic | |
0bee926d | 249 | ok ($Is_MSWin32 ? (`set __NoNeSuCh` =~ /^(__NoNeSuCh=)?foo$/) |
ec00bdd8 | 250 | : (`echo \$__NoNeSuCh` eq "foo\n") ); |
66b1d557 | 251 | } |
3e3baf6d | 252 | |
c7213721 | 253 | { |
2eecd615 | 254 | local $SIG{'__WARN__'} = sub { print "# @_\nnot " }; |
78987ded | 255 | $! = undef; |
0bee926d | 256 | ok 1; |
78987ded HS |
257 | } |
258 | ||
902173a3 GS |
259 | # test case-insignificance of %ENV (these tests must be enabled only |
260 | # when perl is compiled with -DENV_IS_CASELESS) | |
2986a63f | 261 | if ($Is_MSWin32 || $Is_NetWare) { |
902173a3 GS |
262 | %ENV = (); |
263 | $ENV{'Foo'} = 'bar'; | |
264 | $ENV{'fOo'} = 'baz'; | |
0bee926d MS |
265 | ok (scalar(keys(%ENV)) == 1); |
266 | ok exists($ENV{'FOo'}); | |
267 | ok (delete($ENV{'foO'}) eq 'baz'); | |
268 | ok (scalar(keys(%ENV)) == 0); | |
902173a3 GS |
269 | } |
270 | else { | |
0bee926d | 271 | skip('no caseless %ENV support') for 1..4; |
902173a3 | 272 | } |
d2c93421 RH |
273 | |
274 | # Make sure Errno hasn't been prematurely autoloaded | |
275 | ||
0bee926d | 276 | ok !defined %Errno::; |
d2c93421 RH |
277 | |
278 | # Test auto-loading of Errno when %! is used | |
279 | ||
0bee926d | 280 | ok scalar eval q{ |
d2c93421 RH |
281 | my $errs = %!; |
282 | defined %Errno::; | |
283 | }, $@; | |
284 | ||
285 | ||
286 | # Make sure that Errno loading doesn't clobber $! | |
287 | ||
288 | undef %Errno::; | |
289 | delete $INC{"Errno.pm"}; | |
290 | ||
291 | open(FOO, "nonesuch"); # Generate ENOENT | |
292 | my %errs = %{"!"}; # Cause Errno.pm to be loaded at run-time | |
0bee926d | 293 | ok ${"!"}{ENOENT}; |
a4268c0a | 294 | |
0bee926d MS |
295 | ok $^S == 0; |
296 | eval { ok $^S == 1 }; | |
297 | ok $^S == 0; | |
7c36658b MS |
298 | |
299 | ok ${^TAINT} == 0; | |
300 | eval { ${^TAINT} = 1 }; | |
301 | ok ${^TAINT} == 0; |