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