blib/lib/Lingy/Test.pm

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