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