| 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 | 77 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | 77 | my ($class, %opts) = @_; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | %opts = ( | ||||||||||||||||||||||||||||
| 17 | base_dir => $opts{base_dir}, | ||||||||||||||||||||||||||||
| 18 | version => "", | ||||||||||||||||||||||||||||
| 19 | suite => "type", | ||||||||||||||||||||||||||||
| 20 | 0 | ▶ | cb => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 21 | 0 | my ($schema, $instance, $expect) = @_; | |||||||||||||||||||||||||||
| 22 | 0 | return 1; | |||||||||||||||||||||||||||
| 23 | }, | ||||||||||||||||||||||||||||
| 24 | 77 | skip_test_cases => {}, | |||||||||||||||||||||||||||
| 25 | verbose => 0, | ||||||||||||||||||||||||||||
| 26 | %opts | ||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 77 | my $self = bless \%opts => $class; | |||||||||||||||||||||||||||
| 30 | 77 | my $test_suite = $self->load_test_suite; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 77 | for my $test_cases (@$test_suite) { | |||||||||||||||||||||||||||
| 33 | 209 | $self->run_test_cases($test_cases, $opts{skip_test_cases}); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 77 | done_testing; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 209 | ▶ | sub run_test_cases { | ||||||||||||||||||||||||||
|
Subroutine
run_test_cases: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 40 | 209 | my ($self, $test_cases, $skip_test_cases) = @_; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 209 | my ($desc, $schema, $tests) = @$test_cases{qw/description schema tests/}; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 209 | ▶ | subtest $desc => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 45 | SKIP: { | ||||||||||||||||||||||||||||
| 46 | 209 | for my $test_case (@$tests) { | |||||||||||||||||||||||||||
| 47 | 722 | ▶ | if (defined $test_case->{description} && exists $skip_test_cases->{$test_case->{description}}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $test_case->{"description"} and exists $$skip_test_cases{$test_case->{"description"}}
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"}}
| |||||||||||||||||||||||||||||
| 48 | 2 | skip $test_case->{description} => 1; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | 720 | $self->run_test_case($schema, $test_case); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 209 | }; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 720 | ▶ | sub run_test_case { | ||||||||||||||||||||||||||
|
Subroutine
run_test_case: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 57 | 720 | my ($self, $schema, $test_case) = @_; | |||||||||||||||||||||||||||
| 58 | 720 | my ($desc, $data, $expect) = @$test_case{qw/description data valid/}; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | is( | ||||||||||||||||||||||||||||
| 61 | 720 | ▶ | $self->{cb}->($schema, $data, $expect, $test_case), | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | $expect ? 1 : 0, | ||||||||||||||||||||||||||||
| 63 | $desc, | ||||||||||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 77 | ▶ | sub load_test_suite { | ||||||||||||||||||||||||||
|
Subroutine
load_test_suite: called CC=4 SCAR=14.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 68 | 77 | my $self = shift; | |||||||||||||||||||||||||||
| 69 | my $test_suite_file = File::Spec->catfile( | ||||||||||||||||||||||||||||
| 70 | $self->{version} ? ( $self->{base_dir}, $self->{version} ) : ( $self->{base_dir} ), | ||||||||||||||||||||||||||||
| 71 | 77 | ▶ | $self->{suite} . ".json" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | ); | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 77 | note $test_suite_file; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 77 | ▶ | unless (-f $test_suite_file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 0 | croak sprintf("Not exists test suite (base_dir: %s, version: %s, suite: %s)", @$self{qw/base_dir version suite/}); | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 77 | ▶ | open(my $fh, "<", $test_suite_file) or croak $!; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 77 | my $test_suite = decode_json(do { local $/; <$fh> }); | |||||||||||||||||||||||||||
| 82 | 77 | close $fh; | |||||||||||||||||||||||||||
| 83 | 77 | return $test_suite; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 41 | 1; | |||||||||||||||||||||||||||