line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- Perl -*- |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Tests exit status words |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Test::UnixExit; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
95970
|
use 5.006; |
|
2
|
|
|
|
|
6
|
|
8
|
2
|
|
|
2
|
|
8
|
use strict; |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
31
|
|
9
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
49
|
|
10
|
2
|
|
|
2
|
|
5
|
use Carp qw(croak); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
84
|
|
11
|
2
|
|
|
2
|
|
7
|
use Test::Builder; |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
65
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
require Exporter; |
16
|
2
|
|
|
2
|
|
6
|
use vars qw(@ISA @EXPORT); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
517
|
|
17
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
18
|
|
|
|
|
|
|
@EXPORT = qw(exit_is); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $test = Test::Builder->new; |
21
|
|
|
|
|
|
|
my @keys = qw(code signal iscore); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub exit_is { |
24
|
5
|
|
|
5
|
1
|
8137
|
my ( $status, $expected_value, $name ) = @_; |
25
|
|
|
|
|
|
|
|
26
|
5
|
50
|
33
|
|
|
41
|
croak "Usage: status expected-value test-name" |
27
|
|
|
|
|
|
|
if !defined $status |
28
|
|
|
|
|
|
|
or !defined $expected_value; |
29
|
|
|
|
|
|
|
|
30
|
5
|
100
|
|
|
|
61
|
if ( $expected_value =~ m/^[0-9]+$/ ) { |
|
|
50
|
|
|
|
|
|
31
|
3
|
|
|
|
|
21
|
$expected_value = { code => $expected_value }; |
32
|
|
|
|
|
|
|
} elsif ( ref $expected_value ne 'HASH' ) { |
33
|
0
|
|
|
|
|
0
|
croak "expected-value must be integer or hash reference"; |
34
|
|
|
|
|
|
|
} |
35
|
5
|
|
|
|
|
17
|
for my $key (@keys) { |
36
|
|
|
|
|
|
|
$expected_value->{$key} = 0 |
37
|
|
|
|
|
|
|
if !exists $expected_value->{$key} |
38
|
15
|
100
|
66
|
|
|
63
|
or !defined $expected_value->{$key}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
5
|
|
|
|
|
6
|
my $got_value; |
42
|
5
|
|
|
|
|
14
|
$got_value->{code} = $status >> 8; |
43
|
5
|
|
|
|
|
9
|
$got_value->{signal} = $status & 127; |
44
|
5
|
100
|
|
|
|
11
|
$got_value->{iscore} = $status & 128 ? 1 : 0; |
45
|
|
|
|
|
|
|
|
46
|
5
|
|
|
|
|
6
|
my $passed = 1; |
47
|
5
|
|
|
|
|
9
|
for my $key (@keys) { |
48
|
15
|
50
|
|
|
|
31
|
if ( $got_value->{$key} != $expected_value->{$key} ) { |
49
|
0
|
|
|
|
|
0
|
$passed = 0; |
50
|
0
|
|
|
|
|
0
|
last; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
5
|
|
|
|
|
38
|
$test->ok( $passed, $name ); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
$test->diag( |
56
|
|
|
|
|
|
|
sprintf |
57
|
|
|
|
|
|
|
"Got: code=%-3d signal=%-2d iscore=%d\nExpected: code=%-3d signal=%-2d iscore=%d\n", |
58
|
0
|
|
|
|
|
0
|
map( { $got_value->{$_} } @keys ), |
59
|
5
|
50
|
|
|
|
2427
|
map( { $expected_value->{$_} } @keys ) |
|
0
|
|
|
|
|
0
|
|
60
|
|
|
|
|
|
|
) if !$passed; |
61
|
|
|
|
|
|
|
|
62
|
5
|
|
|
|
|
15
|
return $passed; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
__END__ |