lib/YAMLScript/Test.pm

filter: Statementstmt 93.6% 88 / 94 Branchbran 46.8% 15 / 32 Conditioncond 75.0% 3 / 4 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 19 / 19 Podpod 0.0% 0 / 5 totaltotal 80.7% 126 / 156 CC 16 SCAR 16.6
CC
16
Cov
82%
map_yaml_tests
14.2
__ANON__
6.9
__ANON__
6.0
CRAP 5.3
« lib/YAMLScript/Reader.pm ↑ Summary lib/YAMLScript/RT.pm »
1 10 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package YAMLScript::Test;
3  
4 10 ▶use YAMLScript::Main;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use Lingy::Test;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 10 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 10 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 10 ▶use YAML::PP;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 10 ▶use Lingy::Printer;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 10 ▶use YAMLScript::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 10 ▶use YAMLScript::RT;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 10 ▶use YAMLScript::Reader;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 10 my $reader = YAMLScript::Reader->new;
19  
20 10 $ENV{YAMLSCRIPT_TEST} = 1;
21  
22 10 ▶our $yamlscript =
Branch: 2 branches
BranchTrueFalseTotal
-f './blib/script/yamlscript' ? : 10 0 10
-f './bin/yamlscript' ? : 0 0 0
23 -f './blib/script/yamlscript' ? './blib/script/yamlscript' :
24 -f './bin/yamlscript' ? './bin/yamlscript' :
25 die "Can't find 'yamlscript' bin script to test";
26  
27 10 ▶our $eg =
Branch: 2 branches
BranchTrueFalseTotal
-d 'eg' ? : 0 10 10
-d 'example' ? : 10 0 10
28 -d 'eg' ? 'eg' :
29 -d 'example' ? 'example' :
30 die "Can't find eg/example directory";
31  
32 10 our @EXPORT = (
33 @Lingy::Test::EXPORT,
34 qw<
35 $yamlscript
36 test_eval
37 test_ys_to_ly
38 >,
39 );
40  
41 104 ▶sub fmt {
Subroutine fmt: called CC=1 SCAR=0.0
Pod undocumented
42 104 local $_ = shift;
43 104 s/\n/\\n/g;
44 104 s/^\s+//;
45 104 s/\s+$//;
46 104 $_;
47 }
48  
49 58 ▶sub label {
Subroutine label: called CC=1 SCAR=0.0
Pod undocumented
50 58 local $_ = shift;
51 58 my ($got, $want) = @_;
52 58 s/\$GOT/$got/g;
53 58 s/\$WANT/$want/g;
54 58 $_;
55 }
56  
57 8 ▶sub map_yaml_tests {
Subroutine map_yaml_tests: called CC=6 SCAR=26.5
Pod undocumented
58 8 my ($func, $yaml) = @_;
59 8 my $data = YAML::PP->new->load_string($yaml);
60 8 ▶ if (my $last = $ENV{LAST}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $last = $ENV{'LAST'}) { } 0 8 8
elsif (length(my $only = $ENV{'ONLY'})) { } 0 8 8
61 0 $data = [$data->[0 - $last]];
62 } elsif (length(my $only = $ENV{ONLY})) {
63 0 ▶ die "Invalid setting ONLY='$only'" unless
Branch: 1 branch
BranchTrueFalseTotal
unless $only =~ /^[1-9]\d*$/ 0 0 0
64 $only =~ /^[1-9]\d*$/;
65 0 my $max = @$data;
66 0 ▶ die "You said ONLY='$only', but only $max tests"
Branch: 1 branch
BranchTrueFalseTotal
if $only > $max 0 0 0
67 if $only > $max;
68 0 $data = [$data->[$only - 1]];
69 }
70 8 for my $test (@$data) {
71 58 $func->(@$test);
72 }
73 }
74  
75 10 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
76 2 ▶sub test_eval {
Subroutine test_eval: called CC=1 SCAR=0.2
Pod undocumented
77 7 ▶ map_yaml_tests sub {
Subroutine __ANON__: called CC=6 SCAR=19.3
78 7 ▶ my ($input, $want, $label) =
Branch: 2 branches
BranchTrueFalseTotal
@_ == 2 ? : 7 0 7
@_ == 3 ? : 0 0 0
79 (@_ == 2) ? @_ :
80 (@_ == 3) ? ($_[1], $_[2], $_[0]) :
81 die;
82 7 ▶ $label //= "'${\fmt($input)}' -> '${\fmt($want)}'";
Condition50%1/2
$label //= "'${\fmt($input);}' -> '${\fmt($want);}'"
l!l
07
MC/DC0%0/1
$label //= "'${\fmt($input);}' -> '${\fmt($want);}'"
$label
Truth table50%1/2
A
A= $label
Aresult
11
00
83  
84 7 my $got = eval {
85 7 local $YAMLScript::Reader::read_ys = 1;
86 7 join("\n", RT->rep($input));
87 };
88 7 ▶ $got = $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 7 7
89 7 chomp $got;
90  
91 7 $got =~ s/^Error: //;
92  
93 7 $label = label($label. $got, $want);
94 7 ▶ if (ref($want) eq 'Regexp') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $want eq 'Regexp') { } 0 7 7
95 0 like $got, $want, $label;
96 } else {
97 7 is $got, $want, $label;
98 }
99 2 }, @_;
100 }
101  
102 6 ▶sub test_ys_to_ly {
Subroutine test_ys_to_ly: called CC=1 SCAR=0.0
Pod undocumented
103 51 ▶ map_yaml_tests sub {
Subroutine __ANON__: called CC=6 SCAR=17.9
104 51 ▶ my ($ys, $ly, $label) =
Branch: 2 branches
BranchTrueFalseTotal
@_ == 2 ? : 45 6 51
@_ == 3 ? : 6 0 6
105 (@_ == 2) ? @_ :
106 (@_ == 3) ? ($_[1], $_[2], $_[0]) :
107 die;
108  
109 51 $ys =~ s/\A\s+//;
110 51 $ly =~ s/\A\s+//;
111  
112 51 ▶ $label //= "'${\fmt($ys)}' -> '${\fmt($ly)}'";
Condition100%2/2
$label //= "'${\fmt($ys);}' -> '${\fmt($ly);}'"
l!l
645
MC/DC100%1/1
$label //= "'${\fmt($ys);}' -> '${\fmt($ly);}'"
$label
Truth table100%2/2
A
A= $label
Aresult
11
00
113  
114 51 my $got;
115 51 eval {
116 51 my $ast = $reader->read_ys("$ys\n");
117 50 $got = Lingy::Printer->pr_str($ast);
118 };
119 51 ▶ $got = $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 50 51
120  
121 51 my $want = $ly;
122 51 $label = label($label, $got, $ly);
123  
124 51 ▶ if ($want =~ s{^/(.*)/$}{$1}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($want =~ s[^/(.*)/$][$1]) { } 1 50 51
125 1 like $got, qr/$want/, $label;
126 } else {
127 50 is $got, $ly, $label;
128 }
129 6 }, @_;
130 }
131  
132 10 1;
« lib/YAMLScript/Reader.pm ↑ Summary lib/YAMLScript/RT.pm »