Commit | Line | Data |
6ae8f908 |
1 | #!./perl |
2 | |
3 | BEGIN { |
4 | chdir 't'; |
5 | @INC = '../lib'; |
6 | require './test.pl'; |
7 | } |
8 | |
9 | BEGIN { |
10 | use Config; |
11 | if( !$Config{d_alarm} ) { |
12 | skip_all("alarm() not implemented on this platform"); |
13 | } |
14 | } |
15 | |
16 | plan tests => 4; |
17 | my $Perl = which_perl(); |
18 | |
19 | my $start_time = time; |
20 | eval { |
21 | local $SIG{ALRM} = sub { die "ALARM!\n" }; |
22 | alarm 3; |
23 | |
24 | # perlfunc recommends against using sleep in combination with alarm. |
25 | 1 while (time - $start_time < 6); |
26 | }; |
27 | alarm 0; |
28 | my $diff = time - $start_time; |
29 | |
30 | # alarm time might be one second less than you said. |
31 | is( $@, "ALARM!\n", 'alarm w/$SIG{ALRM} vs inf loop' ); |
32 | ok( $diff == 3 || $diff == 2, ' right time' ); |
33 | |
34 | |
35 | my $start_time = time; |
36 | eval { |
37 | local $SIG{ALRM} = sub { die "ALARM!\n" }; |
38 | alarm 3; |
39 | system(qq{$Perl -e "sleep 6"}); |
40 | }; |
41 | alarm 0; |
42 | $diff = time - $start_time; |
43 | |
44 | # alarm time might be one second less than you said. |
45 | is( $@, "ALARM!\n", 'alarm w/$SIG{ALRM} vs system()' ); |
46 | |
1689481e |
47 | ok( $diff == 3 || $diff == 2, ' right time' ); |