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