blib/lib/Lingy/Test.pm

filter: Statementstmt 96.5% 111 / 115 Branchbran 67.8% 19 / 28 Conditioncond 64.2% 9 / 14 MC/DCmcdc 37.5% 3 / 8 Subroutinesub 100% 25 / 25 Podpod 0.0% 0 / 7 totaltotal 84.7% 167 / 197 CC 16 SCAR 10.4
CC
16
Cov
89%
test
7.4
BEGIN
3.7
test_out
3.1
CRAP 2.8
« lib/Lingy/Exception.pm ↑ Summary blib/lib/Lingy/Class.pm »
1 39 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Lingy::Test;
3  
4 39 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 39 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 39 ▶use YAML::PP;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 39 ▶use Lingy;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 39 ▶use Lingy::RT;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 39 ▶use Lingy::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 39 ▶use Capture::Tiny qw'capture capture_merged';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 39 ▶use File::Temp 'tempfile';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 BEGIN {
17 39 ▶ $ENV{LINGY_TEST} //= 1;
Subroutine BEGIN: called CC=3 SCAR=13.1
Condition50%1/2
$ENV{"LINGY_TEST"} //= 1
l!l
039
MC/DC0%0/1
$ENV{"LINGY_TEST"} //= 1
$ENV{"LINGY_TEST"}
Truth table50%1/2
A
A= $ENV{"LINGY_TEST"}
Aresult
11
00
18 39 ▶ if (defined $INC{'Carp/Always.pm'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $INC{"Carp/Always.pm"}) 0 39 39
19 0 eval "no Carp::Always";
20 }
21 }
22  
23 39 ▶use lib 'lib', './test/lib', './t/lib';
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 39 ▶symlink 't', 'test' if -d 't' and not -e 'test';
Branch: 1 branch
BranchTrueFalseTotal
if -d "t" and not -e "test" 1 38 39
Condition66%2/3
-d "t" and not -e "test"
!ll&&!rl&&r
0381
MC/DC50%1/2
-d "t" and not -e "test"
-d "t" not -e "test"
Truth table66%2/3
A and not(B)
A= -d "t"B= not -e "test"
ABresult
0X0
100
111
26  
27 39 my $ypp = YAML::PP->new;
28  
29 39 RT->init;
30 39 $Lingy::RT::OK = 0;
31  
32 39 ▶our $lingy =
Branch: 2 branches
BranchTrueFalseTotal
-f './blib/script/lingy' ? : 39 0 39
-f './bin/lingy' ? : 0 0 0
33 -f './blib/script/lingy' ? './blib/script/lingy' :
34 -f './bin/lingy' ? './bin/lingy' :
35 undef;
36  
37 39 ▶our $eg =
Branch: 2 branches
BranchTrueFalseTotal
-d 'eg' ? : 0 39 39
-d 'example' ? : 39 0 39
38 -d 'eg' ? 'eg' :
39 -d 'example' ? 'example' :
40 die "Can't find eg/example directory";
41  
42 39 our @EXPORT = qw<
43 done_testing
44 is
45 like
46 note
47 pass
48 plan
49 subtest
50 use_ok
51  
52 capture
53 capture_merged
54 tempfile
55  
56 $lingy
57 $eg
58  
59 rep
60 run_is
61 test
62 test_out
63 tests
64  
65 PPP WWW XXX YYY ZZZ
66 >;
67  
68 sub collapse;
69 sub line;
70  
71 sub import {
72 40 ▶ strict->import;
Subroutine import: called CC=1 SCAR=0.0
73 40 warnings->import;
74 40 shift->export_to_level(1, @_);
75 }
76  
77 sub rep {
78 19 ▶ RT->rep(@_);
Subroutine rep: called CC=1 SCAR=0.0
Pod undocumented
79 }
80  
81 sub tests {
82 31 ▶ my ($spec) = @_;
Subroutine tests: called CC=3 SCAR=11.0
Pod undocumented
83 31 my $list = $ypp->load_string($spec);
84 31 for my $elem (@$list) {
85 365 ▶ if (ref($elem) eq 'HASH'){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $elem eq 'HASH') { } 27 338 365
86 27 my ($key, $val) = %$elem;
87 39 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
88 27 $key->($val);
89 } else {
90 338 test(@$elem);
91 }
92 }
93 }
94  
95 # Test 'rep' for return value or error:
96 39 my $test_i = 0;
97 sub test {
98 345 ▶ RT->nextID(10);
Subroutine test: called CC=7 SCAR=20.0
Pod undocumented
99 345 $test_i++;
100 345 ▶ if ($ENV{ONLY} and $ENV{ONLY} != $test_i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"ONLY"} and $ENV{"ONLY"} != $test_i) 0 345 345
Condition33%1/3
$ENV{"ONLY"} and $ENV{"ONLY"} != $test_i
!ll&&!rl&&r
34500
MC/DC0%0/2
$ENV{"ONLY"} and $ENV{"ONLY"} != $test_i
$ENV{"ONLY"} $ENV{"ONLY"} != $test_i
Truth table33%1/3
A and B
A= $ENV{"ONLY"}B= $ENV{"ONLY"} != $test_i
ABresult
0X0
100
111
101 0 return;
102 }
103 345 my ($input, $want, $label) = @_;
104 345 ▶ $label //= "'${\ collapse $input}' -> '${\line $want}'";
Condition100%2/2
$label //= "'${\collapse($input);}' -> '${\line($want);}'"
l!l
4341
MC/DC100%1/1
$label //= "'${\collapse($input);}' -> '${\line($want);}'"
$label
Truth table100%2/2
A
A= $label
Aresult
11
00
105  
106 345 $Lingy::RT::OK = 1;
107 345 my $got = eval { join("\n", RT->rep($input)) };
108 345 ▶ $got = $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 42 303 345
109 345 chomp $got;
110  
111 345 $got =~ s/^Error: //;
112  
113 345 ▶ if (ref($want) eq 'Regexp') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $want eq 'Regexp') { } 0 345 345
elsif ($want =~ s[^/(.*)/$][$1]) { } 8 337 345
114 0 like $got, $want, $label;
115 } elsif ($want =~ s{^/(.*)/$}{$1}) {
116 8 like $got, qr/$want/, $label;
117 } else {
118 337 is $got, $want, $label;
119 }
120 }
121  
122 sub test_out {
123 4 ▶ my ($input, $want, $label) = @_;
Subroutine test_out: called CC=3 SCAR=11.2
Pod undocumented
124 4 ▶ $label //= "'${\ collapse $input}' -> '${\line $want}'";
Condition50%1/2
$label //= "'${\collapse($input);}' -> '${\line($want);}'"
l!l
04
MC/DC0%0/1
$label //= "'${\collapse($input);}' -> '${\line($want);}'"
$label
Truth table50%1/2
A
A= $label
Aresult
11
00
125 my ($got) = Capture::Tiny::capture_merged {
126 4 ▶ RT->rep($input);
Subroutine __ANON__: called CC=1 SCAR=0.0
127 4 };
128 4 chomp $got;
129 4 chomp $want;
130  
131 4 $got =~ s/^Error: //;
132  
133 4 ▶ if (ref($want) eq 'Regexp') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $want eq 'Regexp') { } 0 4 4
134 0 like $got, $want, $label;
135 } else {
136 4 is $got, $want, $label;
137 }
138 }
139  
140 sub run_is {
141 15 ▶ my ($cmd, $want, $label) = @_;
Subroutine run_is: called CC=3 SCAR=11.0
Pod undocumented
142 15 ▶ $label //= "'$cmd' -> '$want'";
Condition100%2/2
$label //= "'${cmd}' -> '${want}'"
l!l
114
MC/DC100%1/1
$label //= "'${cmd}' -> '${want}'"
$label
Truth table100%2/2
A
A= $label
Aresult
11
00
143 15 $label =~ s/\$cmd/$cmd/g;
144 15 $label =~ s/\$want/$want/g;
145 15 $label =~ s/\n/\\n/g;
146 15 my $got = `( $cmd ) 2>&1`;
147 15 chomp $got;
148 15 ▶ if (ref($want) eq 'Regexp') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $want eq 'Regexp') { } 4 11 15
149 4 like $got, $want, $label;
150 } else {
151 11 chomp $got;
152 11 is $got, $want, $label;
153 }
154 }
155  
156 sub collapse {
157 345 ▶ local $_ = shift;
Subroutine collapse: called CC=1 SCAR=0.0
Pod undocumented
158 345 s/\s\s+/ /g;
159 345 s/^ //;
160 345 chomp;
161 345 $_;
162 }
163  
164 sub line {
165 345 ▶ local $_ = shift;
Subroutine line: called CC=1 SCAR=0.0
Pod undocumented
166 345 s/\n/\\n/g;
167 345 $_;
168 }
169  
170 39 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
171  
172 39 my $done_testing = 0;
173 sub done_testing {
174 40 ▶ return if $done_testing++;
Subroutine done_testing: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $done_testing++ 1 39 40
175 39 goto &Test::More::done_testing;
176 }
177  
178 END {
179 package main;
180 39 ▶ done_testing();
Subroutine END: called CC=1 SCAR=0.0
181 }
182  
183 39 1;
« lib/Lingy/Exception.pm ↑ Summary blib/lib/Lingy/Class.pm »