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