line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Should::Engine; |
2
|
3
|
|
|
3
|
|
87024
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
218
|
|
3
|
3
|
|
|
3
|
|
18
|
use warnings; |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
88
|
|
4
|
3
|
|
|
3
|
|
82
|
use 5.010001; |
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
190
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
18
|
use Carp (); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
76
|
|
8
|
3
|
|
|
3
|
|
2729
|
use Storable (); |
|
3
|
|
|
|
|
8391
|
|
|
3
|
|
|
|
|
1737
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @CARP_NOT = (__PACKAGE__); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub run { |
13
|
51
|
|
|
51
|
1
|
120757
|
my ($class, $pattern, $subject, @args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
51
|
100
|
100
|
|
|
796
|
if ($pattern =~ /^should_not_(.+)$/) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
16
|
4
|
|
|
|
|
14
|
$pattern = "should_$1"; |
17
|
4
|
|
|
|
|
23
|
return !$class->run($pattern, $subject, @args); |
18
|
|
|
|
|
|
|
} elsif ($pattern eq 'should_be_ok' || $pattern eq 'should_be_true') { |
19
|
9
|
|
|
|
|
46
|
return !!$subject; |
20
|
|
|
|
|
|
|
} elsif ($pattern eq 'should_be_false') { |
21
|
2
|
|
|
|
|
10
|
return !$subject; |
22
|
|
|
|
|
|
|
} elsif ($pattern eq 'should_be_undef') { |
23
|
2
|
|
|
|
|
10
|
return not defined($subject); |
24
|
|
|
|
|
|
|
} elsif ($pattern eq 'should_be_empty') { |
25
|
4
|
100
|
|
|
|
11
|
if (ref $subject eq 'ARRAY') { |
26
|
2
|
|
|
|
|
11
|
return (@$subject == 0); |
27
|
|
|
|
|
|
|
} else { |
28
|
2
|
|
|
|
|
13
|
return length($subject) == 0; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} elsif ($pattern eq 'should_be_equal') { |
31
|
3
|
|
|
|
|
5
|
local $Storable::canonical = 1; |
32
|
3
|
|
|
|
|
14
|
return Storable::nfreeze(\$subject) eq Storable::nfreeze(\$args[0]); |
33
|
|
|
|
|
|
|
} elsif ($pattern =~ /^should_be_an?$/) { |
34
|
6
|
|
|
|
|
57
|
return UNIVERSAL::isa($subject, $args[0]); |
35
|
|
|
|
|
|
|
} elsif ($pattern eq 'should_be_above') { |
36
|
3
|
|
|
|
|
18
|
return $subject > $args[0]; |
37
|
|
|
|
|
|
|
} elsif ($pattern eq 'should_be_below') { |
38
|
3
|
|
|
|
|
16
|
return $subject < $args[0]; |
39
|
|
|
|
|
|
|
} elsif ($pattern eq 'should_match') { |
40
|
2
|
|
|
|
|
21
|
return !!($subject =~ $args[0]); |
41
|
|
|
|
|
|
|
} elsif ($pattern eq 'should_have_length') { |
42
|
4
|
100
|
|
|
|
15
|
if (ref $subject eq 'ARRAY') { |
43
|
2
|
|
|
|
|
13
|
return (@$subject == $args[0]); |
44
|
|
|
|
|
|
|
} else { |
45
|
2
|
|
|
|
|
13
|
return length($subject) == $args[0]; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} elsif ($pattern eq 'should_include') { |
48
|
4
|
100
|
|
|
|
14
|
if (ref $subject eq 'ARRAY') { |
49
|
2
|
|
|
|
|
5
|
for (@$subject) { |
50
|
4
|
100
|
|
|
|
21
|
return 1 if $_ eq $args[0]; |
51
|
|
|
|
|
|
|
} |
52
|
1
|
|
|
|
|
7
|
return 0; |
53
|
|
|
|
|
|
|
} else { |
54
|
2
|
|
|
|
|
15
|
return index($subject, $args[0]) >= 0; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} elsif ($pattern eq 'should_throw') { |
57
|
3
|
|
|
|
|
5
|
eval { |
58
|
3
|
|
|
|
|
9
|
$subject->() |
59
|
|
|
|
|
|
|
}; |
60
|
3
|
100
|
|
|
|
45
|
if (ref $args[0] eq 'Regexp') { |
61
|
2
|
|
|
|
|
21
|
return $@ =~ $args[0]; |
62
|
|
|
|
|
|
|
} else { |
63
|
1
|
|
|
|
|
6
|
return !!$@; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} elsif ($pattern eq 'should_have_keys') { |
66
|
2
|
|
|
|
|
10
|
my %copy = %$subject; |
67
|
2
|
|
|
|
|
7
|
for (@args) { |
68
|
4
|
100
|
|
|
|
21
|
return 0 unless exists $copy{$_}; |
69
|
3
|
|
|
|
|
8
|
delete $copy{$_}; |
70
|
|
|
|
|
|
|
} |
71
|
1
|
|
|
|
|
9
|
return keys(%copy) == 0; |
72
|
|
|
|
|
|
|
} else { |
73
|
0
|
|
|
|
|
|
Carp::croak("Unknown pattern: $pattern"); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
__END__ |