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