blib/lib/Test/JSV/Suite.pm

filter: Statementstmt 94.6% 53 / 56 Branchbran 80.0% 8 / 10 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 92.8% 13 / 14 Podpod 0.0% 0 / 4 totaltotal 88.7% 79 / 89 CC 9 SCAR 8.5
CC
9
Cov
93%
load_test_suite
4.1
__ANON__
4.0
run
2.0
CRAP 2.3
« blib/lib/JSV/Result.pm ↑ Summary blib/lib/JSV/Keyword/Draft4/Not.pm »
1 package Test::JSV::Suite;
2  
3 41 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 41 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 41 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 41 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 41 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 41 ▶use FindBin;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 41 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 41 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub run {
14 73 ▶ my ($class, %opts) = @_;
Subroutine run: called CC=2 SCAR=7.1
Pod undocumented
15  
16 %opts = (
17 base_dir => $opts{base_dir},
18 version => "",
19 suite => "type",
20 cb => sub {
21 0 ▶ my ($schema, $instance, $expect) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
22 0 return 1;
23 },
24 73 skip_test_cases => {},
25 verbose => 0,
26 %opts
27 );
28  
29 73 my $self = bless \%opts => $class;
30 73 my $test_suite = $self->load_test_suite;
31  
32 73 for my $test_cases (@$test_suite) {
33 189 $self->run_test_cases($test_cases, $opts{skip_test_cases});
34 }
35  
36 73 done_testing;
37 }
38  
39 sub run_test_cases {
40 189 ▶ my ($self, $test_cases, $skip_test_cases) = @_;
Subroutine run_test_cases: called CC=1 SCAR=0.0
Pod undocumented
41  
42 189 my ($desc, $schema, $tests) = @$test_cases{qw/description schema tests/};
43  
44 subtest $desc => sub {
45 SKIP: {
46 189 ▶ for my $test_case (@$tests) {
Subroutine __ANON__: called CC=4 SCAR=13.9
47 670 ▶ if (defined $test_case->{description} && exists $skip_test_cases->{$test_case->{description}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $test_case->{"description"} and exists $$skip_test_cases{$test_case->{"description"}}) 2 668 670
Condition100%3/3
defined $test_case->{"description"} and exists $$skip_test_cases{$test_case->{"description"}}
!ll&&!rl&&r
2624062
MC/DC100%2/2
defined $test_case->{"description"} and exists $$skip_test_cases{$test_case->{"description"}}
defined $test_case->{"description"} exists $$skip_test_cases{$test_case->{"description"}}
Truth table100%3/3
A and B
A= defined $test_case->{"description"}B= exists $$skip_test_cases{$test_case->{"description"}}
ABresult
0X0
100
111
48 2 skip $test_case->{description} => 1;
49 }
50 668 $self->run_test_case($schema, $test_case);
51 }
52 }
53 189 };
54 }
55  
56 sub run_test_case {
57 668 ▶ my ($self, $schema, $test_case) = @_;
Subroutine run_test_case: called CC=2 SCAR=6.9
Pod undocumented
58 668 my ($desc, $data, $expect) = @$test_case{qw/description data valid/};
59  
60 is(
61 668 ▶ $self->{cb}->($schema, $data, $expect, $test_case),
Branch: 1 branch
BranchTrueFalseTotal
$expect ? : 357 311 668
62 $expect ? 1 : 0,
63 $desc,
64 );
65 }
66  
67 sub load_test_suite {
68 73 ▶ my $self = shift;
Subroutine load_test_suite: called CC=4 SCAR=14.1
Pod undocumented
69 my $test_suite_file = File::Spec->catfile(
70 $self->{version} ? ( $self->{base_dir}, $self->{version} ) : ( $self->{base_dir} ),
71 73 ▶ $self->{suite} . ".json"
Branch: 1 branch
BranchTrueFalseTotal
$self->{'version'} ? : 41 32 73
72 );
73  
74 73 note $test_suite_file;
75  
76 73 ▶ unless (-f $test_suite_file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $test_suite_file) 0 73 73
77 0 croak sprintf("Not exists test suite (base_dir: %s, version: %s, suite: %s)", @$self{qw/base_dir version suite/});
78 }
79  
80 73 ▶ open(my $fh, "<", $test_suite_file) or croak $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $test_suite_file or croak($!) 0 73 73
81 73 my $test_suite = decode_json(do { local $/; <$fh> });
82 73 close $fh;
83 73 return $test_suite;
84 }
85  
86 41 1;
« blib/lib/JSV/Result.pm ↑ Summary blib/lib/JSV/Keyword/Draft4/Not.pm »