line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Cukes; |
2
|
5
|
|
|
5
|
|
103035
|
use strict; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
169
|
|
3
|
5
|
|
|
5
|
|
29
|
use warnings; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
145
|
|
4
|
5
|
|
|
5
|
|
2808
|
use Test::Cukes::Feature; |
|
5
|
|
|
|
|
15
|
|
|
5
|
|
|
|
|
168
|
|
5
|
5
|
|
|
5
|
|
5767
|
use Carp::Assert; |
|
5
|
|
|
|
|
24280
|
|
|
5
|
|
|
|
|
35
|
|
6
|
5
|
|
|
5
|
|
8609
|
use Try::Tiny; |
|
5
|
|
|
|
|
9629
|
|
|
5
|
|
|
|
|
365
|
|
7
|
|
|
|
|
|
|
|
8
|
5
|
|
|
5
|
|
102
|
use base 'Test::Builder::Module'; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
5167
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = "0.10"; |
11
|
|
|
|
|
|
|
our @EXPORT = qw(feature runtests Given When Then assert affirm should shouldnt); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @missing_steps = (); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $steps = {}; |
16
|
|
|
|
|
|
|
my $feature = {}; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub feature { |
19
|
3
|
|
|
3
|
0
|
23
|
my $caller = caller; |
20
|
3
|
|
|
|
|
8
|
my $text = shift; |
21
|
|
|
|
|
|
|
|
22
|
3
|
|
|
|
|
79
|
$feature->{$caller} = Test::Cukes::Feature->new($text) |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub runtests { |
26
|
4
|
|
|
4
|
0
|
33
|
my $caller = caller; |
27
|
4
|
|
|
|
|
11
|
my $feature_text = shift; |
28
|
|
|
|
|
|
|
|
29
|
4
|
100
|
|
|
|
16
|
if ($feature_text) { |
30
|
1
|
|
|
|
|
30
|
$feature->{$caller} = Test::Cukes::Feature->new($feature_text); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
4
|
|
|
|
|
8
|
my @scenarios_of_caller = @{$feature->{$caller}->scenarios}; |
|
4
|
|
|
|
|
24
|
|
34
|
|
|
|
|
|
|
|
35
|
4
|
|
|
|
|
8
|
for my $scenario (@scenarios_of_caller) { |
36
|
4
|
|
|
|
|
9
|
my $skip = 0; |
37
|
4
|
|
|
|
|
7
|
my $skip_reason = ""; |
38
|
4
|
|
|
|
|
7
|
my $gwt; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
4
|
|
|
|
|
7
|
for my $step_text (@{$scenario->steps}) { |
|
4
|
|
|
|
|
15
|
|
42
|
12
|
|
|
|
|
43
|
my ($pre, $step) = split " ", $step_text, 2; |
43
|
12
|
50
|
|
|
|
30
|
if ($skip) { |
44
|
0
|
|
|
|
|
0
|
Test::Cukes->builder->skip($step_text); |
45
|
0
|
|
|
|
|
0
|
next; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
12
|
50
|
|
|
|
97
|
$gwt = $pre if $pre =~ /(Given|When|Then)/; |
49
|
|
|
|
|
|
|
|
50
|
12
|
|
|
|
|
16
|
my $found_step = 0; |
51
|
12
|
|
|
|
|
35
|
for my $step_pattern (keys %$steps) { |
52
|
21
|
|
|
|
|
41
|
my $cb = $steps->{$step_pattern}->{code}; |
53
|
|
|
|
|
|
|
|
54
|
21
|
100
|
|
|
|
392
|
if (my (@matches) = $step =~ m/$step_pattern/) { |
55
|
9
|
|
|
|
|
15
|
my $ok = 1; |
56
|
|
|
|
|
|
|
try { |
57
|
9
|
|
|
9
|
|
294
|
$cb->(@matches); |
58
|
|
|
|
|
|
|
} catch { |
59
|
0
|
|
|
0
|
|
0
|
$ok = 0; |
60
|
9
|
|
|
|
|
72
|
}; |
61
|
|
|
|
|
|
|
|
62
|
9
|
|
|
|
|
1853
|
Test::Cukes->builder->ok($ok, $step_text); |
63
|
|
|
|
|
|
|
|
64
|
9
|
50
|
33
|
|
|
4031
|
if ($skip == 0 && !$ok) { |
65
|
0
|
|
|
|
|
0
|
Test::Cukes->builder->diag($@); |
66
|
0
|
|
|
|
|
0
|
$skip = 1; |
67
|
0
|
|
|
|
|
0
|
$skip_reason = "Failed: $step_text"; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
9
|
|
|
|
|
15
|
$found_step = 1; |
71
|
9
|
|
|
|
|
22
|
last; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
12
|
100
|
|
|
|
45
|
unless($found_step) { |
76
|
3
|
|
|
|
|
4
|
$step_text =~ s/^And /$gwt /; |
77
|
3
|
|
|
|
|
10
|
push @missing_steps, $step_text; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# If the user doesn't specify tests explicitly when they use Test::Cukes;, |
83
|
|
|
|
|
|
|
# assume they had no plan and call done_testing for them. |
84
|
4
|
100
|
|
|
|
27
|
Test::Cukes->builder->done_testing if !Test::Cukes->builder->has_plan; |
85
|
|
|
|
|
|
|
|
86
|
4
|
|
|
|
|
693
|
report_missing_steps(); |
87
|
|
|
|
|
|
|
|
88
|
4
|
|
|
|
|
807
|
return 0; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub report_missing_steps { |
92
|
4
|
100
|
|
4
|
0
|
24
|
return if @missing_steps == 0; |
93
|
1
|
|
|
|
|
12
|
Test::Cukes->builder->note("There are missing step definitions, fill them in:"); |
94
|
1
|
|
|
|
|
465
|
for my $step_text (@missing_steps) { |
95
|
3
|
|
|
|
|
1026
|
my ($word, $text) = ($step_text =~ /^(Given|When|Then) (.+)$/); |
96
|
3
|
|
|
|
|
19
|
my $msg = "\n$word qr/${text}/ => sub {\n ...\n};\n"; |
97
|
3
|
|
|
|
|
11
|
Test::Cukes->builder->note($msg); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _add_step { |
102
|
10
|
|
|
10
|
|
119
|
my ($step, $cb) = @_; |
103
|
10
|
|
|
|
|
29
|
my ($package, $filename, $line) = caller; |
104
|
|
|
|
|
|
|
|
105
|
10
|
|
|
|
|
77
|
$steps->{$step} = { |
106
|
|
|
|
|
|
|
definition => { |
107
|
|
|
|
|
|
|
package => $package, |
108
|
|
|
|
|
|
|
filename => $filename, |
109
|
|
|
|
|
|
|
line => $line, |
110
|
|
|
|
|
|
|
}, |
111
|
|
|
|
|
|
|
code => $cb |
112
|
|
|
|
|
|
|
}; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
*Given = *_add_step; |
116
|
|
|
|
|
|
|
*When = *_add_step; |
117
|
|
|
|
|
|
|
*Then = *_add_step; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |
120
|
|
|
|
|
|
|
__END__ |