Commit | Line | Data |
---|---|---|
8d063cd8 LW |
1 | #!./perl |
2 | ||
90ce63d5 RS |
3 | BEGIN { |
4 | $^W = 1; | |
5 | $| = 1; | |
6 | chdir 't' if -d 't'; | |
7 | @INC = '../lib'; | |
774d564b | 8 | $SIG{__WARN__} = sub { die "Dying on warning: ", @_ }; |
90ce63d5 | 9 | } |
8d063cd8 | 10 | |
90ce63d5 RS |
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 TB |
22 | $Is_MSWin32 = $^O eq 'MSWin32'; |
23 | $Is_VMS = $^O eq 'VMS'; | |
68dc0745 | 24 | $PERL = ($Is_MSWin32 ? '.\perl' : './perl'); |
25 | ||
66b1d557 | 26 | print "1..30\n"; |
378cc40b LW |
27 | |
28 | eval '$ENV{"foo"} = "hi there";'; # check that ENV is inited inside eval | |
3fe9a6f1 | 29 | if ($Is_MSWin32) { ok 1, `cmd /x /c set foo` eq "foo=hi there\n"; } |
68dc0745 | 30 | else { ok 1, `echo \$foo` eq "hi there\n"; } |
8d063cd8 | 31 | |
bf38876a | 32 | unlink 'ajslkdfpqjsjfk'; |
8d063cd8 | 33 | $! = 0; |
90ce63d5 RS |
34 | open(FOO,'ajslkdfpqjsjfk'); |
35 | ok 2, $!, $!; | |
36 | close FOO; # just mention it, squelch used-only-once | |
8d063cd8 | 37 | |
68dc0745 | 38 | if ($Is_MSWin32) { |
39 | ok 3,1; | |
40 | ok 4,1; | |
41 | } | |
42 | else { | |
43 | # the next tests are embedded inside system simply because sh spits out | |
44 | # a newline onto stderr when a child process kills itself with SIGINT. | |
45 | system './perl', '-e', <<'END'; | |
378cc40b | 46 | |
79072805 | 47 | $| = 1; # command buffering |
378cc40b | 48 | |
79072805 LW |
49 | $SIG{"INT"} = "ok3"; kill "INT",$$; |
50 | $SIG{"INT"} = "IGNORE"; kill 2,$$; print "ok 4\n"; | |
51 | $SIG{"INT"} = "DEFAULT"; kill 2,$$; print "not ok\n"; | |
52 | ||
53 | sub ok3 { | |
54 | if (($x = pop(@_)) eq "INT") { | |
55 | print "ok 3\n"; | |
56 | } | |
57 | else { | |
652ed9f8 | 58 | print "not ok 3 ($x @_)\n"; |
79072805 LW |
59 | } |
60 | } | |
61 | ||
62 | END | |
68dc0745 | 63 | } |
a687059c | 64 | |
68dc0745 | 65 | # can we slice ENV? |
66 | @val1 = @ENV{keys(%ENV)}; | |
a687059c | 67 | @val2 = values(%ENV); |
90ce63d5 RS |
68 | ok 5, join(':',@val1) eq join(':',@val2); |
69 | ok 6, @val1 > 1; | |
70 | ||
71 | # regex vars | |
72 | 'foobarbaz' =~ /b(a)r/; | |
73 | ok 7, $` eq 'foo', $`; | |
74 | ok 8, $& eq 'bar', $&; | |
75 | ok 9, $' eq 'baz', $'; | |
76 | ok 10, $+ eq 'a', $+; | |
77 | ||
78 | # $" | |
79 | @a = qw(foo bar baz); | |
80 | ok 11, "@a" eq "foo bar baz", "@a"; | |
81 | { | |
82 | local $" = ','; | |
83 | ok 12, "@a" eq "foo,bar,baz", "@a"; | |
84 | } | |
a687059c | 85 | |
90ce63d5 RS |
86 | # $; |
87 | %h = (); | |
88 | $h{'foo', 'bar'} = 1; | |
89 | ok 13, (keys %h)[0] eq "foo\034bar", (keys %h)[0]; | |
90 | { | |
91 | local $; = 'x'; | |
92 | %h = (); | |
93 | $h{'foo', 'bar'} = 1; | |
94 | ok 14, (keys %h)[0] eq 'fooxbar', (keys %h)[0]; | |
95 | } | |
ed6116ce | 96 | |
90ce63d5 | 97 | # $?, $@, $$ |
5aabfad6 | 98 | system qq[$PERL -e "exit(0)"]; |
90ce63d5 | 99 | ok 15, $? == 0, $?; |
5aabfad6 | 100 | system qq[$PERL -e "exit(1)"]; |
90ce63d5 RS |
101 | ok 16, $? != 0, $?; |
102 | ||
103 | eval { die "foo\n" }; | |
104 | ok 17, $@ eq "foo\n", $@; | |
105 | ||
106 | ok 18, $$ > 0, $$; | |
107 | ||
108 | # $^X and $0 | |
68dc0745 | 109 | if ($Is_MSWin32) { |
110 | for (19 .. 25) { ok $_, 1 } | |
774d564b | 111 | } |
112 | else { | |
3e3baf6d | 113 | if ($^O eq 'qnx') { |
68dc0745 | 114 | chomp($wd = `pwd`); |
115 | } | |
116 | else { | |
117 | $wd = '.'; | |
118 | } | |
119 | $script = "$wd/show-shebang"; | |
120 | $s1 = $s2 = "\$^X is $wd/perl, \$0 is $script\n"; | |
121 | if ($^O eq 'os2') { | |
122 | # Started by ksh, which adds suffixes '.exe' and '.' to perl and script | |
123 | $s2 = "\$^X is $wd/perl.exe, \$0 is $script.\n"; | |
124 | } | |
125 | ok 19, open(SCRIPT, ">$script"), $!; | |
126 | ok 20, print(SCRIPT <<EOB . <<'EOF'), $!; | |
774d564b | 127 | #!$wd/perl |
128 | EOB | |
90ce63d5 RS |
129 | print "\$^X is $^X, \$0 is $0\n"; |
130 | EOF | |
68dc0745 | 131 | ok 21, close(SCRIPT), $!; |
132 | ok 22, chmod(0755, $script), $!; | |
133 | $_ = `$script`; | |
134 | s{\bminiperl\b}{perl}; # so that test doesn't fail with miniperl | |
135 | s{is perl}{is $wd/perl}; # for systems where $^X is only a basename | |
136 | ok 23, $_ eq $s2, ":$_:!=:$s2:"; | |
137 | $_ = `$wd/perl $script`; | |
138 | ok 24, $_ eq $s1, ":$_:!=:$s1: after `$wd/perl $script`"; | |
139 | ok 25, unlink($script), $!; | |
140 | } | |
ed6116ce | 141 | |
90ce63d5 RS |
142 | # $], $^O, $^T |
143 | ok 26, $] >= 5.00319, $]; | |
144 | ok 27, $^O; | |
145 | ok 28, $^T > 850000000, $^T; | |
66b1d557 | 146 | |
3e3baf6d TB |
147 | if ($Is_VMS) { |
148 | ok 29, 1; | |
149 | ok 30, 1; | |
66b1d557 HM |
150 | } |
151 | else { | |
3e3baf6d TB |
152 | $PATH = $ENV{PATH}; |
153 | $ENV{foo} = "bar"; | |
154 | %ENV = (); | |
155 | $ENV{PATH} = $PATH; | |
156 | ok 29, ($Is_MSWin32 ? (`cmd /x /c set foo 2>NUL` eq "") | |
157 | : (`echo \$foo` eq "\n") ); | |
158 | ||
159 | $ENV{NoNeSuCh} = "foo"; | |
160 | $0 = "bar"; | |
161 | ok 30, ($Is_MSWin32 ? (`cmd /x /c set NoNeSuCh` eq "NoNeSuCh=foo\n") | |
162 | : (`echo \$NoNeSuCh` eq "foo\n") ); | |
66b1d557 | 163 | } |
3e3baf6d | 164 |