blib/lib/Test/A8N/Fixture.pm

filter: Statementstmt 63.0% 70 / 111 Branchbran 58.3% 21 / 36 Conditioncond 72.7% 8 / 11 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 72.7% 16 / 22 Podpod 33.3% 2 / 6 totaltotal 62.5% 120 / 192 CC 29 SCAR 19.0
CC
29
Cov
63%
_get_metavar
20.0
_squish_array
20.0
_recurse_parse_arguments
7.3
CRAP 6.7
« blib/lib/Test/A8N/Fixture/Selenium.pm ↑ Summary blib/lib/Test/A8N/File.pm »
1 package Test::A8N::Fixture;
2 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 9 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 # This ensures the constructor from Moose::Object is
9 # preferred over the FITesque one... this is IMPORTANT!
10 9 extends(qw(Moose::Object Test::FITesque::Fixture));
11 }
12  
13 9 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 9 ▶use YAML::Syck;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 9 our @EXCLUDE_METHODS = qw(
16 config
17 selenium
18 testcase
19 ctxt
20 verbose
21 parse_method_string
22 disallowed_phrases
23 parse_arguments
24 );
25  
26 28 ▶sub BUILD {
Subroutine BUILD: called CC=6 SCAR=18.0
Pod undocumented
27 28 my $self = shift;
28 28 my ($params) = @_;
29 28 ▶ if (!$self->verbose || $params->{QUIET} || $ENV{QUIET_FIXTURES}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->verbose or $params->{"QUIET"} or $ENV{"QUIET_FIXTURES"}) 25 3 28
Condition66%4/6
not $self->verbose or $params->{"QUIET"} or $ENV{"QUIET_FIXTURES"}
l!l&&r!l&&!r
2503
not $self->verbose or $params->{"QUIET"}
l!l&&r!l&&!r
2503
MC/DC33%1/3
not $self->verbose or $params->{"QUIET"} or $ENV{"QUIET_FIXTURES"}
not $self->verbose $params->{"QUIET"} $ENV{"QUIET_FIXTURES"}
Truth table50%2/4
not(A) or B or C
A= not $self->verboseB= $params->{"QUIET"}C= $ENV{"QUIET_FIXTURES"}
ABCresult
1XX1
01X1
0011
0000
30 25 Test::Builder->new->no_diag(1);
31 }
32 28 ▶ diag sprintf(q{Using fixture class "%s"}, blessed($self))
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose > 1 2 26 28
33 if ($self->verbose > 1);
34 28 ▶ diag sprintf('START: "%s": %s', $self->testcase->filename, $self->testcase->id)
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 3 25 28
35 if ($self->verbose);
36 }
37  
38 28 ▶sub DEMOLISH {
Subroutine DEMOLISH: called CC=3 SCAR=11.8
Pod undocumented
39 28 my $self = shift;
40 # fixture actions can clean up after themselves
41 28 ▶ while (my $coderef = shift @{ $self->_demolish_actions() }){
Branch: 1 branch
BranchTrueFalseTotal
if (my $coderef = shift @{$self->_demolish_actions;}) 0 28 28
42 0 $self->$coderef();
43 0 $coderef = undef;
44 }
45 28 ▶ diag sprintf('FINISH: "%s": %s', $self->testcase->filename, $self->testcase->id)
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 3 25 28
46 if ($self->verbose);
47 }
48  
49 has '_demolish_actions' => (
50 is => 'ro',
51 isa => 'ArrayRef',
52 28 ▶ default => sub {[]},
Subroutine __ANON__: called CC=1 SCAR=0.0
53 9 );
54  
55 0 ▶sub _add_demolish_actions {
Subroutine _add_demolish_actions: not called CC=1 SCAR=6.9
56 0 my ($self, @actions) = @_;
57 0 push @{ $self->_demolish_actions() }, @actions;
58 }
59  
60 has 'config' => (
61 is => 'rw',
62 required => 1,
63 isa => 'HashRef',
64 28 ▶ default => sub { shift->testcase->config },
Subroutine __ANON__: called CC=1 SCAR=0.0
65 9 lazy => 1,
66 );
67  
68 9 has 'testcase' => (
69 is => 'rw',
70 isa => 'Object'
71 );
72  
73 has 'ctxt' => (
74 is => 'rw',
75 required => 1,
76 isa => 'HashRef',
77 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
78 9 lazy => 1,
79 );
80  
81 has verbose => (
82 required => 1,
83 lazy => 1,
84 is => q{ro},
85 isa => q{Int},
86 28 ▶ default => sub { return shift->config->{verbose} },
Subroutine __ANON__: called CC=1 SCAR=0.0
87 9 );
88  
89 # NB: this is a FITesque method, please do not edit.
90 384 ▶sub parse_method_string {
Subroutine parse_method_string: called CC=5 SCAR=17.6
Pod documented
91 384 my ($self, $method_string) = @_;
92 384 (my $method_name = $method_string) =~ s/\s+/_/g;
93  
94 # don't allow test cases to call private methods
95 384 ▶ if($method_name =~ m{^_}){
Branch: 1 branch
BranchTrueFalseTotal
if ($method_name =~ /^_/) 0 384 384
96 0 warn "Cannot call '$method_name' from test cases";
97 0 return undef;
98 }
99  
100 384 ▶ if (ref($self) and $self->verbose > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self and $self->verbose > 1) 24 360 384
Condition100%3/3
ref $self and $self->verbose > 1
!ll&&!rl&&r
9626424
MC/DC100%2/2
ref $self and $self->verbose > 1
ref $self $self->verbose > 1
Truth table100%3/3
A and B
A= ref $selfB= $self->verbose > 1
ABresult
0X0
100
111
101 24 diag "Fixture method $method_name";
102 }
103  
104 # Don't allow testcases to talk about implementaion details
105 0 ▶ if(grep { $method_name =~ m{$_} } $self->disallowed_phrases()){
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$method_name =~ /$_/;} $self->disallowed_phrases) 0 384 384
106  
107 #
108 # Test cases should be completely oblivious to how things are done
109 # internally since they should be written from the perspective of the
110 # user. This is just a catchall to make sure that the developer really
111 # means "do something like the user would" instead of "hoke around the
112 # internals"
113 #
114 0 warn "'$method_name' refers to implementation details";
115 0 return undef;
116 }
117  
118 384 my $coderef = $self->can($method_name);
119 384 return $coderef;
120 }
121  
122 384 ▶sub disallowed_phrases {
Subroutine disallowed_phrases: called CC=1 SCAR=0.0
Pod undocumented
123 384 my ($self) = @_;
124 384 return qw();
125 }
126  
127 0 ▶sub _get_metavar {
Subroutine _get_metavar: not called CC=4 SCAR=30.0
128 0 my $self = shift;
129 0 my ($name) = @_;
130 0 my $config_ref = $self->config;
131  
132 0 my @path = split(/\./, $name);
133 0 foreach my $sub_name (@path) {
134 0 ▶ $config_ref = $config_ref->{$sub_name} or last;
Branch: 1 branch
BranchTrueFalseTotal
$config_ref = $config_ref->{$sub_name} or last 0 0 0
135 }
136 0 ▶ warn qq{Config reference "$name" does not point to a value}
Branch: 1 branch
BranchTrueFalseTotal
if ref $config_ref 0 0 0
137 if (ref($config_ref));
138 0 return $config_ref;
139 }
140  
141 80 ▶sub _parse_metavars {
Subroutine _parse_metavars: called CC=3 SCAR=11.8
142 80 my $self = shift;
143 80 my ($str) = @_;
144 80 ▶ $str ||= '';
Condition50%1/2
$str ||= ""
l!l
800
MC/DC0%0/1
$str ||= ""
$str
Truth table50%1/2
A
A= $str
Aresult
11
00
145  
146 80 my @keys = $str =~ /\$\(([^\)]+)\)/g;
147 80 foreach (@keys) {
148 0 my $value = $self->_get_metavar($_);
149 0 $str =~ s/\$\($_\)/$value/g;
150 }
151  
152 80 return $str;
153 }
154 60 ▶sub _recurse_parse_arguments {
Subroutine _recurse_parse_arguments: called CC=7 SCAR=19.9
155 60 my $self = shift;
156 60 my $arg = shift;
157 60 ▶ if (ref($arg) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $arg eq 'HASH') { } 20 40 60
elsif (ref $arg eq 'ARRAY') { } 20 20 40
158 20 foreach my $key (keys %$arg) {
159 20 ▶ if (ref($arg->{$key})) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg->{$key}) { } 0 20 20
160 0 $arg->{$key} = $self->_recurse_parse_arguments($arg->{$key});
161 } else {
162 20 $arg->{$key} = $self->_parse_metavars($arg->{$key});
163 }
164 }
165 } elsif (ref($arg) eq 'ARRAY') {
166 20 foreach my $idx (0 .. scalar(@$arg) - 1) {
167 40 ▶ if (ref($arg->[$idx])) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg->[$idx]) { } 0 40 40
168 0 $arg->[$idx] = $self->_recurse_parse_arguments($arg->[$idx]);
169 } else {
170 40 $arg->[$idx] = $self->_parse_metavars($arg->[$idx]);
171 }
172 }
173 } else {
174 20 $arg = $self->_parse_metavars($arg);
175 }
176 60 return $arg;
177 }
178  
179 # NB: This is a FITesque required function
180 124 ▶sub parse_arguments {
Subroutine parse_arguments: called CC=3 SCAR=11.0
Pod documented
181 124 my $self = shift;
182 124 ▶ return @_ if !ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 28 96 124
183  
184 96 my @args = ();
185 96 my $recurse;
186  
187 96 foreach my $arg (@_) {
188 60 push @args, $self->_recurse_parse_arguments($arg);
189 }
190 96 return @args;
191 }
192  
193 0 ▶sub _squish_array {
Subroutine _squish_array: not called CC=4 SCAR=30.0
194 0 my $self = shift;
195 0 my ($arg) = @_;
196 0 my $array;
197 0 ▶ if (ref($arg) eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $arg eq 'ARRAY') { } 0 0 0
elsif (defined $arg) { } 0 0 0
198 0 $array = $arg;
199 } elsif (defined($arg)) {
200 0 $array = [$arg];
201 } else {
202 0 $array = [];
203 }
204 0 ▶ return wantarray ? @{ $array } : $array;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
205 }
206  
207 0 ▶sub _lowercase_args {
Subroutine _lowercase_args: not called CC=2 SCAR=17.9
208 0 my $self = shift;
209 0 my ($args) = @_;
210 0 foreach my $field (keys %$args) {
211 0 $args->{lc($field)} = delete $args->{$field};
212 }
213 }
214  
215 =head1 FIXTURE ACTIONS
216  
217 =cut
218  
219 =head2 todo fail
220  
221 todo fail: [ message ]
222  
223 Marks a place in the test case where you would like it to fail, flagging it as a TODO item.
224  
225 =cut
226  
227 0 ▶sub todo_fail {
Subroutine todo_fail: not called CC=1 SCAR=6.9
Pod undocumented
228 0 my $self = shift;
229 0 my ($arg) = @_;
230 TODO: {
231 0 local $TODO = "Marked as a failing TODO: $arg";
232 0 fail($arg);
233 }
234 }
235  
236 9 1;
237 __END__
« blib/lib/Test/A8N/Fixture/Selenium.pm ↑ Summary blib/lib/Test/A8N/File.pm »