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