blib/lib/Test/JSON/Schema/Acceptance.pm

filter: Statementstmt 93.9% 278 / 296 Branchbran 82.1% 133 / 162 Conditioncond 82.1% 106 / 129 MC/DCmcdc 65.2% 45 / 69 Subroutinesub 91.3% 53 / 58 Podpod 50.0% 2 / 4 totaltotal 85.9% 617 / 718 CC 127 SCAR 31.1
CC
127
Cov
88%
acceptance
61.4
__ANON__
19.3
_build_results_text
12.3
CRAP 22.4
↑ Summary
1 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 18 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Test::JSON::Schema::Acceptance; # git description: v1.040-2-g938041b
4 # vim: set ts=8 sts=2 sw=2 tw=100 et :
5 # ABSTRACT: Acceptance testing for JSON-Schema based validators
6  
7 18 our $VERSION = '1.041';
8  
9 18 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 18 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 18 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 18 ▶use stable 0.031 'postderef';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 18 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 18 ▶no autovivification warn => qw(fetch store exists delete);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 18 ▶use if "$]" >= 5.022, experimental => 're_strict';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 18 ▶no if "$]" >= 5.031009, feature => 'indirect';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 18 ▶no if "$]" >= 5.033001, feature => 'multidimensional';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 18 ▶no if "$]" >= 5.033006, feature => 'bareword_filehandles';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 18 ▶no if "$]" >= 5.041009, feature => 'smartmatch';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 18 ▶no feature 'switch';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 18 ▶use Test2::API ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22 18 ▶use Test2::Todo;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 18 ▶use Test2::Tools::Compare ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24 18 ▶use Mojo::JSON (); # for JSON_XS, MOJO_NO_JSON_XS environment variables
Subroutine BEGIN: called CC=1 SCAR=0.0
25 18 ▶use File::ShareDir 'dist_dir';
Subroutine BEGIN: called CC=1 SCAR=0.0
26 18 ▶use Feature::Compat::Try;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 18 ▶use MooX::TypeTiny 0.002002;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 18 ▶use Types::Standard 1.016003 qw(Str InstanceOf ArrayRef HashRef Dict Any HasMethods Bool Optional Slurpy Enum);
Subroutine BEGIN: called CC=1 SCAR=0.0
29 18 ▶use Types::Common::Numeric 'PositiveOrZeroInt';
Subroutine BEGIN: called CC=1 SCAR=0.0
30 18 ▶use Path::Tiny 0.069;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 18 ▶use List::Util 1.33 qw(any max sum0);
Subroutine BEGIN: called CC=1 SCAR=0.0
32 18 ▶use Git::Wrapper;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 18 ▶use B;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 18 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 # specification version => metaschema URI
37 18 ▶use constant METASCHEMA => {
Subroutine BEGIN: called CC=1 SCAR=0.0
38 'v1' => 'https://json-schema.org/v1',
39 'draft2020-12' => 'https://json-schema.org/draft/2020-12/schema',
40 'draft2019-09' => 'https://json-schema.org/draft/2019-09/schema',
41 'draft7' => 'http://json-schema.org/draft-07/schema#',
42 'draft6' => 'http://json-schema.org/draft-06/schema#',
43 'draft4' => 'http://json-schema.org/draft-04/schema#',
44 'draft3' => 'http://json-schema.org/draft-03/schema#',
45 18 };
46  
47 18 my $spec_type = Enum[sort keys METASCHEMA->%*];
48 18 has specification => (
49 is => 'ro',
50 isa => $spec_type,
51 lazy => 1,
52 default => 'draft2020-12',
53 predicate => '_has_specification',
54 );
55  
56 has supported_specifications => (
57 is => 'ro',
58 isa => ArrayRef[$spec_type],
59 lazy => 1,
60 0 ▶ default => sub { [ shift->specification ] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
61 18 );
62  
63 # this comes from the tests/<spec version> directories in the JSON-Schema-Test-Suite repository
64 has test_dir => (
65 is => 'ro',
66 isa => InstanceOf['Path::Tiny'],
67 53 ▶ coerce => sub { path($_[0])->absolute('.') },
Subroutine __ANON__: called CC=1 SCAR=0.0
68 18 lazy => 1,
69 builder => '_build_test_dir',
70 predicate => '_has_test_dir',
71 );
72 54 ▶sub _build_test_dir { path(dist_dir('Test-JSON-Schema-Acceptance'), 'tests', $_[0]->specification) };
Subroutine _build_test_dir: called CC=1 SCAR=0.0
73  
74 # this comes from the remotes/ directory in the JSON-Schema-Test-Suite repository
75 has additional_resources => (
76 is => 'ro',
77 isa => InstanceOf['Path::Tiny'],
78 2 ▶ coerce => sub { path($_[0])->absolute('.') },
Subroutine __ANON__: called CC=1 SCAR=0.0
79 lazy => 1,
80 1 ▶ default => sub { $_[0]->test_dir->parent->parent->child('remotes') },
Subroutine __ANON__: called CC=1 SCAR=0.0
81 18 );
82  
83 18 has verbose => (
84 is => 'ro',
85 isa => Bool,
86 default => 0,
87 );
88  
89 18 has include_optional => (
90 is => 'ro',
91 isa => Bool,
92 default => 0,
93 );
94  
95 has skip_dir => (
96 is => 'ro',
97 isa => ArrayRef[Str],
98 41 ▶ coerce => sub { ref($_[0]) ? $_[0] : [ $_[0] ] },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 41 0 41
99 lazy => 1,
100 40 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
101 18 );
102  
103 18 has test_schemas => (
104 is => 'ro',
105 isa => Bool,
106 );
107  
108 18 has results => (
109 is => 'rwp',
110 init_arg => undef,
111 isa => ArrayRef[Dict[
112 file => InstanceOf['Path::Tiny'],
113 map +($_ => PositiveOrZeroInt), qw(pass todo_fail fail),
114 ]],
115 );
116  
117 18 has results_text => (
118 is => 'ro',
119 init_arg => undef,
120 isa => Str,
121 lazy => 1,
122 builder => '_build_results_text',
123 );
124  
125 56 ▶around BUILDARGS => sub ($orig, $class, @args) {
Subroutine __ANON__: called CC=4 SCAR=13.9
126 56 ▶ my %args = @args % 2 ? ( specification => 'draft'.$args[0] ) : @args;
Branch: 1 branch
BranchTrueFalseTotal
@args % 2 ? : 8 48 56
127 56 ▶ $args{specification} = 'draft2020-12' if ($args{specification} // '') eq 'latest';
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"specification"} // "") eq "latest" 1 55 56
Condition100%2/2
$args{"specification"} // ""
l!l
2333
MC/DC100%1/1
$args{"specification"} // ""
$args{"specification"}
Truth table100%2/2
A
A= $args{"specification"}
Aresult
11
00
128 56 $class->$orig(\%args);
129 18 };
130  
131 53 ▶sub BUILD ($self, @) {
Subroutine BUILD: called CC=2 SCAR=6.9
Pod undocumented
132 53 ▶ -d $self->test_dir or die 'test_dir does not exist: '.$self->test_dir;
Branch: 1 branch
BranchTrueFalseTotal
-d $self->test_dir or die 'test_dir does not exist: ' . $self->test_dir 52 1 53
133 }
134  
135 57 ▶sub acceptance {
Subroutine acceptance: called CC=51 SCAR=41.2
Pod documented
136 57 my $self = shift;
137 57 ▶ my $options = +{ ref $_[0] eq 'CODE' ? (validate_json_string => @_) : @_ };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'CODE' ? : 4 53 57
138  
139 die 'require one or the other of "validate_data", "validate_json_string"'
140 57 ▶ if not $options->{validate_data} and not $options->{validate_json_string};
Branch: 1 branch
BranchTrueFalseTotal
unless $$options{"validate_data"} or $$options{"validate_json_string"} 0 57 57
Condition66%2/3
$$options{"validate_data"} or $$options{"validate_json_string"}
l!l&&r!l&&!r
5070
MC/DC0%0/2
$$options{"validate_data"} or $$options{"validate_json_string"}
$$options{"validate_data"} $$options{"validate_json_string"}
Truth table66%2/3
A or B
A= $$options{"validate_data"}B= $$options{"validate_json_string"}
ABresult
1X1
011
000
141  
142 die 'cannot provide both "validate_data" and "validate_json_string"'
143 57 ▶ if $options->{validate_data} and $options->{validate_json_string};
Branch: 1 branch
BranchTrueFalseTotal
if $$options{"validate_data"} and $$options{"validate_json_string"} 0 57 57
Condition66%2/3
$$options{"validate_data"} and $$options{"validate_json_string"}
!ll&&!rl&&r
7500
MC/DC0%0/2
$$options{"validate_data"} and $$options{"validate_json_string"}
$$options{"validate_data"} $$options{"validate_json_string"}
Truth table66%2/3
A and B
A= $$options{"validate_data"}B= $$options{"validate_json_string"}
ABresult
0X0
100
111
144  
145 warn "'skip_tests' option is deprecated" if $options->{skip_tests}
146 57 ▶ and (not ref $options->{skip_tests} eq 'ARRAY' or not (grep +ref, $options->{skip_tests}->@*));
Branch: 1 branch
BranchTrueFalseTotal
if $$options{"skip_tests"} and not ref $$options{"skip_tests"} eq "ARRAY" && grep(ref($_), @{$$options{"skip_tests"}}) 5 52 57
Condition83%5/6
$$options{"skip_tests"} and not ref $$options{"skip_tests"} eq "ARRAY" && grep(ref($_), @{$$options{"skip_tests"}})
!ll&&!rl&&r
5115
ref $$options{'skip_tests'} eq 'ARRAY' && grep(ref($_), @{$$options{'skip_tests'}})
!ll&&!rl&&r
051
MC/DC66%2/3
$$options{"skip_tests"} and not ref $$options{"skip_tests"} eq "ARRAY" && grep(ref($_), @{$$options{"skip_tests"}})
$$options{"skip_tests"} ref $$options{'skip_tests'} eq 'ARRAY' grep(ref($_), @{$$options{'skip_tests'}})
Truth table75%3/4
A and not(B && C)
A= $$options{"skip_tests"}B= ref $$options{'skip_tests'} eq 'ARRAY'C= grep(ref($_), @{$$options{'skip_tests'}})
ABCresult
0XX0
1110
10X1
1101
147  
148 57 my $ctx = Test2::API::context;
149  
150 57 ▶ if ($options->{add_resource} and -d $self->additional_resources) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$options{"add_resource"} and -d $self->additional_resources) 1 56 57
Condition66%2/3
$$options{"add_resource"} and -d $self->additional_resources
!ll&&!rl&&r
5601
MC/DC50%1/2
$$options{"add_resource"} and -d $self->additional_resources
$$options{"add_resource"} -d $self->additional_resources
Truth table66%2/3
A and B
A= $$options{"add_resource"}B= -d $self->additional_resources
ABresult
0X0
100
111
151 # this is essentially what `bin/jsonschema_suite remote` does: resolves the filename against the
152 # base uri to determine the absolute schema location of each resource.
153 1 my $base = 'http://localhost:1234';
154 1 my %note_seen;
155 1 my $resource_basename = $self->additional_resources->basename; # "remotes"
156 $self->additional_resources->visit(
157 9 ▶ sub ($path, @) {
Subroutine __ANON__: called CC=9 SCAR=22.1
158 9 ▶ return if not $path->is_file or $path !~ /\.json$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $path->is_file and $path =~ /\.json$/u 4 5 9
Condition66%2/3
$path->is_file and $path =~ /\.json$/u
!ll&&!rl&&r
405
MC/DC50%1/2
$path->is_file and $path =~ /\.json$/u
$path->is_file $path =~ /\.json$/u
Truth table66%2/3
A and B
A= $path->is_fileB= $path =~ /\.json$/u
ABresult
0X0
100
111
159  
160 # version-specific resources are stored in a subdirectory by version:
161 # skip resource files that are marked as being for an unsupported draft
162 5 my $relative_path = $path->relative($self->additional_resources);
163 5 my ($topdir, $rest) = split qr{/}, $relative_path, 2;
164 5 ▶ return if $topdir =~ /^(?:draft(?:[3467]|2019-09|2020-12)|v1)\z/ and not grep $topdir eq $_, $self->supported_specifications->@*;
Branch: 1 branch
BranchTrueFalseTotal
if $topdir =~ /^(?:draft(?:[3467]|2019-09|2020-12)|v1)\z/u and not grep(($topdir eq $_), @{$self->supported_specifications}) 1 4 5
Condition100%3/3
$topdir =~ /^(?:draft(?:[3467]|2019-09|2020-12)|v1)\z/u and not grep(($topdir eq $_), @{$self->supported_specifications})
!ll&&!rl&&r
221
MC/DC100%2/2
$topdir =~ /^(?:draft(?:[3467]|2019-09|2020-12)|v1)\z/u and not grep(($topdir eq $_), @{$self->supported_specifications})
$topdir =~ /^(?:draft(?:[3467]|2019-09|2020-12)|v1)\z/u not grep(($topdir eq $_), @{$self->supported_specifications})
Truth table100%3/3
A and not(B)
A= $topdir =~ /^(?:draft(?:[3467]|2019-09|2020-12)|v1)\z/uB= not grep(($topdir eq $_), @{$self->supported_specifications})
ABresult
0X0
100
111
165  
166 $ctx->note('adding resource'.($rest//'' =~ m{/} ? 's' : '').' from '.$resource_basename.'/'.$topdir.' with the base URI "'.$base.'"...')
167 4 ▶ if not $note_seen{$resource_basename.'/'.$topdir}++;
Branch: 2 branches
BranchTrueFalseTotal
unless $note_seen{$resource_basename . '/' . $topdir}++ 4 0 4
$rest // '' =~ m[/]u ? : 3 1 4
Condition66%2/3
$rest // "" =~ m[/]u
l!l&&r!l&&!r
310
MC/DC0%0/2
$rest // "" =~ m[/]u
$rest "" =~ m[/]u
Truth table66%2/3
A // B
A= $restB= "" =~ m[/]u
ABresult
1X1
011
000
168  
169 4 my $data = $self->json_deserialize($path->slurp_raw);
170 4 my $uri = $base.'/'.$relative_path;
171 4 ▶ $options->{add_resource}->($uri => $data,
Branch: 1 branch
BranchTrueFalseTotal
$topdir =~ /^draft/u ? : 2 2 4
172 # ensure the evaluator parses this resource using its specified version
173 $topdir =~ /^draft/ ? (specification_version => $topdir) : ());
174 },
175 1 { recurse => 1 },
176 );
177 }
178  
179 57 ▶ $ctx->note('running tests in '.$self->test_dir.' against '
Branch: 1 branch
BranchTrueFalseTotal
$self->_has_specification ? : 27 30 57
180 .($self->_has_specification ? $self->specification : 'unknown version').'...');
181 57 my $tests = $self->_test_data;
182  
183 # [ { file => .., pass => .., fail => .. }, ... ]
184 57 my @results;
185  
186 57 foreach my $one_file (@$tests) {
187 218 my %results;
188 next if $options->{tests} and $options->{tests}{file}
189 and not grep $_ eq $one_file->{file},
190 (ref $options->{tests}{file} eq 'ARRAY'
191 218 ▶ ? $options->{tests}{file}->@* : $options->{tests}{file});
Branch: 2 branches
BranchTrueFalseTotal
if $$options{"tests"} and $$options{"tests"}{"file"} and not grep(($_ eq $$one_file{"file"}), ref $$options{"tests"}{"file"} eq "ARRAY" ? @{$$options{"tests"}{"file"}} : $$options{"tests"}{"file"}) 11 207 218
ref $$options{'tests'}{'file'} eq 'ARRAY' ? : 3 20 23
Condition100%6/6
$$options{"tests"} and $$options{"tests"}{"file"} and not grep(($_ eq $$one_file{"file"}), ref $$options{"tests"}{"file"} eq "ARRAY" ? @{$$options{"tests"}{"file"}} : $$options{"tests"}{"file"})
!ll&&!rl&&r
1951211
$$options{"tests"} and $$options{"tests"}{"file"}
!ll&&!rl&&r
186923
MC/DC100%3/3
$$options{"tests"} and $$options{"tests"}{"file"} and not grep(($_ eq $$one_file{"file"}), ref $$options{"tests"}{"file"} eq "ARRAY" ? @{$$options{"tests"}{"file"}} : $$options{"tests"}{"file"})
$$options{"tests"} $$options{"tests"}{"file"} not grep(($_ eq $$one_file{"file"}), ref $$options{"tests"}{"file"} eq "ARRAY" ? @{$$options{"tests"}{"file"}} : $$options{"tests"}{"file"})
Truth table100%4/4
A and B and not(C)
A= $$options{"tests"}B= $$options{"tests"}{"file"}C= not grep(($_ eq $$one_file{"file"}), ref $$options{"tests"}{"file"} eq "ARRAY" ? @{$$options{"tests"}{"file"}} : $$options{"tests"}{"file"})
ABCresult
0XX0
10X0
1100
1111
192  
193 207 $ctx->note('');
194  
195 SKIP:
196 207 foreach my $test_group ($one_file->{json}->@*) {
197 next if $options->{tests} and $options->{tests}{group_description}
198 and not grep $_ eq $test_group->{description},
199 (ref $options->{tests}{group_description} eq 'ARRAY'
200 973 ▶ ? $options->{tests}{group_description}->@* : $options->{tests}{group_description});
Branch: 2 branches
BranchTrueFalseTotal
if $$options{"tests"} and $$options{"tests"}{"group_description"} and not grep(($_ eq $$test_group{"description"}), ref $$options{"tests"}{"group_description"} eq "ARRAY" ? @{$$options{"tests"}{"group_description"}} : $$options{"tests"}{"group_description"}) 24 949 973
ref $$options{'tests'}{'group_description'} eq 'ARRAY' ? : 3 35 38
Condition100%6/6
$$options{"tests"} and $$options{"tests"}{"group_description"} and not grep(($_ eq $$test_group{"description"}), ref $$options{"tests"}{"group_description"} eq "ARRAY" ? @{$$options{"tests"}{"group_description"}} : $$options{"tests"}{"group_description"})
!ll&&!rl&&r
9351424
$$options{"tests"} and $$options{"tests"}{"group_description"}
!ll&&!rl&&r
9201538
MC/DC100%3/3
$$options{"tests"} and $$options{"tests"}{"group_description"} and not grep(($_ eq $$test_group{"description"}), ref $$options{"tests"}{"group_description"} eq "ARRAY" ? @{$$options{"tests"}{"group_description"}} : $$options{"tests"}{"group_description"})
$$options{"tests"} $$options{"tests"}{"group_description"} not grep(($_ eq $$test_group{"description"}), ref $$options{"tests"}{"group_description"} eq "ARRAY" ? @{$$options{"tests"}{"group_description"}} : $$options{"tests"}{"group_description"})
Truth table100%4/4
A and B and not(C)
A= $$options{"tests"}B= $$options{"tests"}{"group_description"}C= not grep(($_ eq $$test_group{"description"}), ref $$options{"tests"}{"group_description"} eq "ARRAY" ? @{$$options{"tests"}{"group_description"}} : $$options{"tests"}{"group_description"})
ABCresult
0XX0
10X0
1100
1111
201  
202 949 my $todo;
203 $todo = Test2::Todo->new(reason => 'Test marked TODO via "todo_tests"')
204 if $options->{todo_tests}
205 74 ▶ and any {
Subroutine __ANON__: called CC=7 SCAR=19.5
206 74 my $o = $_;
207 (not $o->{file} or grep $_ eq $one_file->{file}, (ref $o->{file} eq 'ARRAY' ? $o->{file}->@* : $o->{file}))
208 and
209 (not $o->{group_description} or grep $_ eq $test_group->{description}, (ref $o->{group_description} eq 'ARRAY' ? $o->{group_description}->@* : $o->{group_description}))
210 and not $o->{test_description}
211 74 ▶ }
Branch: 3 branches
BranchTrueFalseTotal
!$$o{"file"} || grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"}) and !$$o{"group_description"} || grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"}) and not $$o{"test_description"} 28 46 74
ref $$o{'file'} eq 'ARRAY' ? : 7 42 49
ref $$o{'group_description'} eq 'ARRAY' ? : 3 27 30
Condition100%9/9
!$$o{"file"} || grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"}) and !$$o{"group_description"} || grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"})
!ll&&!rl&&r
271928
not $$o{"file"} or grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"})
l!l&&r!l&&!r
252227
not $$o{"group_description"} or grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"})
l!l&&r!l&&!r
171119
MC/DC100%4/4
!$$o{"file"} || grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"}) and !$$o{"group_description"} || grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"})
not $$o{"file"} grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"}) not $$o{"group_description"} grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"})
Truth table100%7/7
not(A) or B and not(C) or D
A= not $$o{"file"}B= grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"})C= not $$o{"group_description"}D= grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"})
ABCDresult
00XX0
1X000
01000
1X1X1
1X011
011X1
01011
212 949 ▶ $options->{todo_tests}->@*;
Branch: 1 branch
BranchTrueFalseTotal
if $$options{"todo_tests"} and &any(sub { my $o = $_; !$$o{"file"} || grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"}) and !$$o{"group_description"} || grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"}) and not $$o{"test_description"}; } , @{$$options{"todo_tests"}}) 16 933 949
Condition100%3/3
$$options{"todo_tests"} and &any(sub { my $o = $_; !$$o{"file"} || grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"}) and !$$o{"group_description"} || grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"}) and not $$o{"test_description"}; } , @{$$options{"todo_tests"}})
!ll&&!rl&&r
8795416
MC/DC100%2/2
$$options{"todo_tests"} and &any(sub { my $o = $_; !$$o{"file"} || grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"}) and !$$o{"group_description"} || grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"}) and not $$o{"test_description"}; } , @{$$options{"todo_tests"}})
$$options{"todo_tests"} &any(sub { my $o = $_; !$$o{"file"} || grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"}) and !$$o{"group_description"} || grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"}) and not $$o{"test_description"}; } , @{$$options{"todo_tests"}})
Truth table100%3/3
A and B
A= $$options{"todo_tests"}B= &any(sub { my $o = $_; !$$o{"file"} || grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"}) and !$$o{"group_description"} || grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"}) and not $$o{"test_description"}; } , @{$$options{"todo_tests"}})
ABresult
0X0
100
111
213  
214 $ctx->skip('SKIP', 'Test marked skip via "skip_tests"'), next SKIP
215 if $options->{skip_tests}
216 and ref $options->{skip_tests} eq 'ARRAY'
217 and not (grep +!ref, $options->{skip_tests}->@*)
218 7 ▶ and any {
Subroutine __ANON__: called CC=7 SCAR=23.4
219 7 my $o = $_;
220 (not $o->{file} or grep $_ eq $one_file->{file}, (ref $o->{file} eq 'ARRAY' ? $o->{file}->@* : $o->{file}))
221 and
222 (not $o->{group_description} or grep $_ eq $test_group->{description}, (ref $o->{group_description} eq 'ARRAY' ? $o->{group_description}->@* : $o->{group_description}))
223 and not $o->{test_description}
224 7 ▶ }
Branch: 3 branches
BranchTrueFalseTotal
!$$o{"file"} || grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"}) and !$$o{"group_description"} || grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"}) and not $$o{"test_description"} 3 4 7
ref $$o{'file'} eq 'ARRAY' ? : 0 7 7
ref $$o{'group_description'} eq 'ARRAY' ? : 0 0 0
Condition55%5/9
!$$o{"file"} || grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"}) and !$$o{"group_description"} || grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"})
!ll&&!rl&&r
403
not $$o{"file"} or grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"})
l!l&&r!l&&!r
034
not $$o{"group_description"} or grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"})
l!l&&r!l&&!r
300
MC/DC25%1/4
!$$o{"file"} || grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"}) and !$$o{"group_description"} || grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"})
not $$o{"file"} grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"}) not $$o{"group_description"} grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"})
Truth table28%2/7
not(A) or B and not(C) or D
A= not $$o{"file"}B= grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"})C= not $$o{"group_description"}D= grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"})
ABCDresult
00XX0
1X000
01000
1X1X1
1X011
011X1
01011
225 949 ▶ $options->{skip_tests}->@*;
Branch: 1 branch
BranchTrueFalseTotal
if $$options{"skip_tests"} and ref $$options{"skip_tests"} eq "ARRAY" and not grep((!ref($_)), @{$$options{"skip_tests"}}) and &any(sub { my $o = $_; !$$o{"file"} || grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"}) and !$$o{"group_description"} || grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"}) and not $$o{"test_description"}; } , @{$$options{"skip_tests"}}) 3 946 949
Condition88%8/9
$$options{"skip_tests"} and ref $$options{"skip_tests"} eq "ARRAY" and not grep((!ref($_)), @{$$options{"skip_tests"}}) and &any(sub { my $o = $_; !$$o{"file"} || grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"}) and !$$o{"group_description"} || grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"}) and not $$o{"test_description"}; } , @{$$options{"skip_tests"}})
!ll&&!rl&&r
94243
$$options{"skip_tests"} and ref $$options{"skip_tests"} eq "ARRAY" and not grep((!ref($_)), @{$$options{"skip_tests"}})
!ll&&!rl&&r
907357
$$options{"skip_tests"} and ref $$options{"skip_tests"} eq "ARRAY"
!ll&&!rl&&r
907042
MC/DC75%3/4
$$options{"skip_tests"} and ref $$options{"skip_tests"} eq "ARRAY" and not grep((!ref($_)), @{$$options{"skip_tests"}}) and &any(sub { my $o = $_; !$$o{"file"} || grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"}) and !$$o{"group_description"} || grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"}) and not $$o{"test_description"}; } , @{$$options{"skip_tests"}})
$$options{"skip_tests"} ref $$options{"skip_tests"} eq "ARRAY" not grep((!ref($_)), @{$$options{"skip_tests"}}) &any(sub { my $o = $_; !$$o{"file"} || grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"}) and !$$o{"group_description"} || grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"}) and not $$o{"test_description"}; } , @{$$options{"skip_tests"}})
Truth table80%4/5
A and B and not(C) and D
A= $$options{"skip_tests"}B= ref $$options{"skip_tests"} eq "ARRAY"C= not grep((!ref($_)), @{$$options{"skip_tests"}})D= &any(sub { my $o = $_; !$$o{"file"} || grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"}) and !$$o{"group_description"} || grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"}) and not $$o{"test_description"}; } , @{$$options{"skip_tests"}})
ABCDresult
0XXX0
10XX0
110X0
11100
11111
226  
227 946 my $schema_fails;
228 946 ▶ if ($self->test_schemas) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->test_schemas) 0 946 946
229 0 ▶ die 'specification_version unknown: cannot evaluate schema against metaschema'
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_has_specification 0 0 0
230 if not $self->_has_specification;
231  
232 my $metaschema_uri = ref $test_group->{schema} eq 'HASH' && $test_group->{schema}{'$schema'}
233 ? $test_group->{schema}{'$schema'}
234 0 ▶ : METASCHEMA->{$self->specification};
Branch: 1 branch
BranchTrueFalseTotal
ref $$test_group{'schema'} eq 'HASH' && $$test_group{'schema'}{'$schema'} ? : 0 0 0
Condition0%0/3
ref $$test_group{"schema"} eq "HASH" and $$test_group{"schema"}{"\$schema"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $$test_group{"schema"} eq "HASH" and $$test_group{"schema"}{"\$schema"}
ref $$test_group{"schema"} eq "HASH" $$test_group{"schema"}{"\$schema"}
Truth table0%0/3
A and B
A= ref $$test_group{"schema"} eq "HASH"B= $$test_group{"schema"}{"\$schema"}
ABresult
0X0
100
111
235 0 my $metaschema_schema = $metaschema_uri;
236 my $result = $options->{validate_data}
237 ? $options->{validate_data}->($metaschema_schema, $test_group->{schema})
238 0 ▶ : $options->{validate_json_string}->($metaschema_schema, $self->json_serialize($test_group->{schema}));
Branch: 1 branch
BranchTrueFalseTotal
$$options{'validate_data'} ? : 0 0 0
239 0 ▶ if (not $result) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($result) 0 0 0
240 0 $ctx->fail('schema for '.$one_file->{file}.': "'.$test_group->{description}.'" fails to validate against '.$metaschema_uri.':');
241 0 $ctx->note($self->json_prettyprint($result));
242 0 $schema_fails = 1;
243 }
244 }
245  
246 946 foreach my $test ($test_group->{tests}->@*) {
247 next if $options->{tests} and $options->{tests}{test_description}
248 and not grep $_ eq $test->{description},
249 (ref $options->{tests}{test_description} eq 'ARRAY'
250 3239 ▶ ? $options->{tests}{test_description}->@* : $options->{tests}{test_description});
Branch: 2 branches
BranchTrueFalseTotal
if $$options{"tests"} and $$options{"tests"}{"test_description"} and not grep(($_ eq $$test{"description"}), ref $$options{"tests"}{"test_description"} eq "ARRAY" ? @{$$options{"tests"}{"test_description"}} : $$options{"tests"}{"test_description"}) 31 3208 3239
ref $$options{'tests'}{'test_description'} eq 'ARRAY' ? : 33 15 48
Condition100%6/6
$$options{"tests"} and $$options{"tests"}{"test_description"} and not grep(($_ eq $$test{"description"}), ref $$options{"tests"}{"test_description"} eq "ARRAY" ? @{$$options{"tests"}{"test_description"}} : $$options{"tests"}{"test_description"})
!ll&&!rl&&r
31911731
$$options{"tests"} and $$options{"tests"}{"test_description"}
!ll&&!rl&&r
31514048
MC/DC100%3/3
$$options{"tests"} and $$options{"tests"}{"test_description"} and not grep(($_ eq $$test{"description"}), ref $$options{"tests"}{"test_description"} eq "ARRAY" ? @{$$options{"tests"}{"test_description"}} : $$options{"tests"}{"test_description"})
$$options{"tests"} $$options{"tests"}{"test_description"} not grep(($_ eq $$test{"description"}), ref $$options{"tests"}{"test_description"} eq "ARRAY" ? @{$$options{"tests"}{"test_description"}} : $$options{"tests"}{"test_description"})
Truth table100%4/4
A and B and not(C)
A= $$options{"tests"}B= $$options{"tests"}{"test_description"}C= not grep(($_ eq $$test{"description"}), ref $$options{"tests"}{"test_description"} eq "ARRAY" ? @{$$options{"tests"}{"test_description"}} : $$options{"tests"}{"test_description"})
ABCresult
0XX0
10X0
1100
1111
251  
252 3208 my $todo;
253 $todo = Test2::Todo->new(reason => 'Test marked TODO via deprecated "skip_tests"')
254 if ref $options->{skip_tests} eq 'ARRAY'
255 and not (grep +ref, $options->{skip_tests}->@*)
256 and grep +(($test_group->{description}.' - '.$test->{description}) =~ /$_/),
257 3208 ▶ $options->{skip_tests}->@*;
Branch: 1 branch
BranchTrueFalseTotal
if ref $$options{"skip_tests"} eq "ARRAY" and not grep(ref($_), @{$$options{"skip_tests"}}) and grep((($$test_group{"description"} . ' - ' . $$test{"description"}) =~ /$_/u), @{$$options{"skip_tests"}}) 47 3161 3208
Condition100%6/6
ref $$options{"skip_tests"} eq "ARRAY" and not grep(ref($_), @{$$options{"skip_tests"}}) and grep((($$test_group{"description"} . ' - ' . $$test{"description"}) =~ /$_/u), @{$$options{"skip_tests"}})
!ll&&!rl&&r
31035847
ref $$options{"skip_tests"} eq "ARRAY" and not grep(ref($_), @{$$options{"skip_tests"}})
!ll&&!rl&&r
309112105
MC/DC100%3/3
ref $$options{"skip_tests"} eq "ARRAY" and not grep(ref($_), @{$$options{"skip_tests"}}) and grep((($$test_group{"description"} . ' - ' . $$test{"description"}) =~ /$_/u), @{$$options{"skip_tests"}})
ref $$options{"skip_tests"} eq "ARRAY" not grep(ref($_), @{$$options{"skip_tests"}}) grep((($$test_group{"description"} . ' - ' . $$test{"description"}) =~ /$_/u), @{$$options{"skip_tests"}})
Truth table100%4/4
A and not(B) and C
A= ref $$options{"skip_tests"} eq "ARRAY"B= not grep(ref($_), @{$$options{"skip_tests"}})C= grep((($$test_group{"description"} . ' - ' . $$test{"description"}) =~ /$_/u), @{$$options{"skip_tests"}})
ABCresult
0XX0
10X0
1100
1111
258  
259 $todo = Test2::Todo->new(reason => 'Test marked TODO via "todo_tests"')
260 if $options->{todo_tests}
261 222 ▶ and any {
Subroutine __ANON__: called CC=9 SCAR=22.0
262 222 my $o = $_;
263 (not $o->{file} or grep $_ eq $one_file->{file}, (ref $o->{file} eq 'ARRAY' ? $o->{file}->@* : $o->{file}))
264 and
265 (not $o->{group_description} or grep $_ eq $test_group->{description}, (ref $o->{group_description} eq 'ARRAY' ? $o->{group_description}->@* : $o->{group_description}))
266 and
267 222 ▶ (not $o->{test_description} or grep $_ eq $test->{description}, (ref $o->{test_description} eq 'ARRAY' ? $o->{test_description}->@* : $o->{test_description}))
Branch: 4 branches
BranchTrueFalseTotal
!$$o{"file"} || grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"}) and !$$o{"group_description"} || grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"}) and !$$o{"test_description"} || grep(($_ eq $$test{"description"}), ref $$o{"test_description"} eq "ARRAY" ? @{$$o{"test_description"}} : $$o{"test_description"}) 84 138 222
ref $$o{'file'} eq 'ARRAY' ? : 21 126 147
ref $$o{'group_description'} eq 'ARRAY' ? : 9 81 90
ref $$o{'test_description'} eq 'ARRAY' ? : 33 3 36
Condition100%15/15
(!$$o{'file'} || grep(($_ eq $$one_file{'file'}), ref $$o{'file'} eq 'ARRAY' ? @{$$o{'file'}} : $$o{'file'})) && (!$$o{'group_description'} || grep(($_ eq $$test_group{'description'}), ref $$o{'group_description'} eq 'ARRAY' ? @{$$o{'group_description'}} : $$o{'group_description'})) && (!$$o{'test_description'} || grep(($_ eq $$test{'description'}), ref $$o{'test_description'} eq 'ARRAY' ? @{$$o{'test_description'}} : $$o{'test_description'}))
!ll&&!rl&&r
1382361
!$$o{"file"} || grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"}) and !$$o{"group_description"} || grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"})
!ll&&!rl&&r
815784
not $$o{"file"} or grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"})
l!l&&r!l&&!r
756681
not $$o{"group_description"} or grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"})
l!l&&r!l&&!r
513357
not $$o{"test_description"} or grep(($_ eq $$test{"description"}), ref $$o{"test_description"} eq "ARRAY" ? @{$$o{"test_description"}} : $$o{"test_description"})
l!l&&r!l&&!r
481323
MC/DC100%6/6
(!$$o{'file'} || grep(($_ eq $$one_file{'file'}), ref $$o{'file'} eq 'ARRAY' ? @{$$o{'file'}} : $$o{'file'})) && (!$$o{'group_description'} || grep(($_ eq $$test_group{'description'}), ref $$o{'group_description'} eq 'ARRAY' ? @{$$o{'group_description'}} : $$o{'group_description'})) && (!$$o{'test_description'} || grep(($_ eq $$test{'description'}), ref $$o{'test_description'} eq 'ARRAY' ? @{$$o{'test_description'}} : $$o{'test_description'}))
not $$o{"file"} grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"}) not $$o{"group_description"} grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"}) not $$o{"test_description"} grep(($_ eq $$test{"description"}), ref $$o{"test_description"} eq "ARRAY" ? @{$$o{"test_description"}} : $$o{"test_description"})
Truth table80%12/15
not(A) or B and not(C) or D && not(E) or F
A= not $$o{"file"}B= grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"})C= not $$o{"group_description"}D= grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"})E= not $$o{"test_description"}F= grep(($_ eq $$test{"description"}), ref $$o{"test_description"} eq "ARRAY" ? @{$$o{"test_description"}} : $$o{"test_description"})
ABCDEFresult
00XXXX0
1X00XX0
0100XX0
1X1X000
1X01000
011X000
0101000
1X1X1X1
1X1X011
1X011X1
1X01011
011X1X1
011X011
01011X1
0101011
268 }
269 3208 ▶ $options->{todo_tests}->@*;
Branch: 1 branch
BranchTrueFalseTotal
if $$options{"todo_tests"} and &any(sub { my $o = $_; !$$o{"file"} || grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"}) and !$$o{"group_description"} || grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"}) and !$$o{"test_description"} || grep(($_ eq $$test{"description"}), ref $$o{"test_description"} eq "ARRAY" ? @{$$o{"test_description"}} : $$o{"test_description"}); } , @{$$options{"todo_tests"}}) 61 3147 3208
Condition100%3/3
$$options{"todo_tests"} and &any(sub { my $o = $_; !$$o{"file"} || grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"}) and !$$o{"group_description"} || grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"}) and !$$o{"test_description"} || grep(($_ eq $$test{"description"}), ref $$o{"test_description"} eq "ARRAY" ? @{$$o{"test_description"}} : $$o{"test_description"}); } , @{$$options{"todo_tests"}})
!ll&&!rl&&r
299814961
MC/DC100%2/2
$$options{"todo_tests"} and &any(sub { my $o = $_; !$$o{"file"} || grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"}) and !$$o{"group_description"} || grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"}) and !$$o{"test_description"} || grep(($_ eq $$test{"description"}), ref $$o{"test_description"} eq "ARRAY" ? @{$$o{"test_description"}} : $$o{"test_description"}); } , @{$$options{"todo_tests"}})
$$options{"todo_tests"} &any(sub { my $o = $_; !$$o{"file"} || grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"}) and !$$o{"group_description"} || grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"}) and !$$o{"test_description"} || grep(($_ eq $$test{"description"}), ref $$o{"test_description"} eq "ARRAY" ? @{$$o{"test_description"}} : $$o{"test_description"}); } , @{$$options{"todo_tests"}})
Truth table100%3/3
A and B
A= $$options{"todo_tests"}B= &any(sub { my $o = $_; !$$o{"file"} || grep(($_ eq $$one_file{"file"}), ref $$o{"file"} eq "ARRAY" ? @{$$o{"file"}} : $$o{"file"}) and !$$o{"group_description"} || grep(($_ eq $$test_group{"description"}), ref $$o{"group_description"} eq "ARRAY" ? @{$$o{"group_description"}} : $$o{"group_description"}) and !$$o{"test_description"} || grep(($_ eq $$test{"description"}), ref $$o{"test_description"} eq "ARRAY" ? @{$$o{"test_description"}} : $$o{"test_description"}); } , @{$$options{"todo_tests"}})
ABresult
0X0
100
111
270  
271 3208 my $result = $self->_run_test($one_file, $test_group, $test, $options);
272 3208 ▶ $result = 0 if $schema_fails;
Branch: 1 branch
BranchTrueFalseTotal
if $schema_fails 0 3208 3208
273  
274 3208 ▶ ++$results{ $result ? 'pass' : $todo ? 'todo_fail' : 'fail' };
Branch: 2 branches
BranchTrueFalseTotal
$result ? : 1946 1262 3208
$todo ? : 34 1228 1262
275 }
276 }
277  
278 207 push @results, { file => $one_file->{file}, pass => 0, 'todo_fail' => 0, fail => 0, %results };
279 }
280  
281 57 $self->_set_results(\@results);
282  
283 57 ▶ my $diag = $self->verbose ? 'diag' : 'note';
Branch: 1 branch
BranchTrueFalseTotal
$self->verbose ? : 0 57 57
284 57 $ctx->$diag("\n".$self->results_text."\n");
285  
286 57 ▶ if ($self->test_dir !~ m{\boptional\b}
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->test_dir =~ /\boptional\b/u and grep((!($our $_{'file'} =~ m[^optional/]u) && $our $_{'todo_fail'} + $our $_{'fail'}), @results)) { } 44 13 57
Condition83%5/6
not $self->test_dir =~ /\boptional\b/u and grep((!($our $_{"file"} =~ m[^optional/]u) && $our $_{"todo_fail"} + $our $_{"fail"}), @results)
!ll&&!rl&&r
01344
!($our $_{'file'} =~ m[^optional/]u) && $our $_{'todo_fail'} + $our $_{'fail'}
!ll&&!rl&&r
358146
MC/DC50%1/2
not $self->test_dir =~ /\boptional\b/u and grep((!($our $_{"file"} =~ m[^optional/]u) && $our $_{"todo_fail"} + $our $_{"fail"}), @results)
not $self->test_dir =~ /\boptional\b/u grep((!($our $_{"file"} =~ m[^optional/]u) && $our $_{"todo_fail"} + $our $_{"fail"}), @results)
MC/DC100%2/2
!($our $_{'file'} =~ m[^optional/]u) && $our $_{'todo_fail'} + $our $_{'fail'}
!($our $_{'file'} =~ m[^optional/]u) $our $_{'todo_fail'} + $our $_{'fail'}
Truth table66%2/3
not(A) and B
A= not $self->test_dir =~ /\boptional\b/uB= grep((!($our $_{"file"} =~ m[^optional/]u) && $our $_{"todo_fail"} + $our $_{"fail"}), @results)
ABresult
0X0
100
111
Truth table100%3/3
not(A) && B
A= !($our $_{'file'} =~ m[^optional/]u)B= $our $_{'todo_fail'} + $our $_{'fail'}
ABresult
0X0
100
111
287 and grep +($_->{file} !~ m{^optional/} && $_->{todo_fail} + $_->{fail}), @results) {
288 # non-optional test failures will always be visible, even when not in verbose mode.
289 44 $ctx->diag('WARNING: some non-optional tests are failing! This implementation is not fully compliant with the specification!');
290 44 $ctx->diag('');
291 }
292 else {
293 13 $ctx->$diag('Congratulations, all non-optional tests are passing!');
294 13 $ctx->$diag('');
295 }
296  
297 57 $ctx->release;
298 }
299  
300 3208 ▶sub _run_test ($self, $one_file, $test_group, $test, $options) {
Subroutine _run_test: called CC=1 SCAR=0.0
301 3208 my $test_name = $one_file->{file}.': "'.$test_group->{description}.'" - "'.$test->{description}.'"';
302  
303 3208 my $pass; # ignores TODO status
304  
305 Test2::API::run_subtest($test_name,
306 3208 ▶ sub {
Subroutine __ANON__: called CC=19 SCAR=29.6
307 3208 my ($result_bool, $result, $schema_before, $data_before, $schema_after, $data_after);
308 3208 try {
309 ($schema_before, $data_before) = map $self->json_serialize($_),
310 3208 $test_group->{schema}, $test->{data};
311  
312 ($result_bool, $result) = $options->{validate_data}
313 ? $options->{validate_data}->($test_group->{schema}, $test->{data})
314 3208 ▶ : $options->{validate_json_string}->($test_group->{schema}, $self->json_serialize($test->{data}));
Branch: 1 branch
BranchTrueFalseTotal
$$options{'validate_data'} ? : 1330 1878 3208
315  
316 ($schema_after, $data_after) = map $self->json_serialize($_),
317 3206 $test_group->{schema}, $test->{data};
318  
319 3206 my $ctx = Test2::API::context;
320  
321 # skip the ugly matrix comparison
322 3206 ▶ my $expected = $test->{valid} ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
$$test{'valid'} ? : 1902 1304 3206
323 3206 ▶ if ($result_bool xor $test->{valid}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result_bool xor $$test{'valid'}) { } 1240 1966 3206
Condition100%4/4
$result_bool xor $$test{"valid"}
l&&rl&&!r!l&&r!l&&!r
1848118654118
MC/DC100%2/2
$result_bool xor $$test{"valid"}
$result_bool $$test{"valid"}
Truth table100%4/4
A xor B
A= $result_boolB= $$test{"valid"}
ABresult
110
101
011
000
324 1240 ▶ $ctx->fail('evaluation result is incorrect', 'expected '.$expected.'; got '.($result_bool ? 'true' : 'false'));
Branch: 1 branch
BranchTrueFalseTotal
$result_bool ? : 1186 54 1240
325 1240 ▶ $ctx->${ $self->verbose ? \'diag' : \'note' }('schema: '.$self->json_prettyprint($test_group->{schema}));
Branch: 1 branch
BranchTrueFalseTotal
$self->verbose ? : 0 1240 1240
326 1240 ▶ $ctx->${ $self->verbose ? \'diag' : \'note' }('data: '.$self->json_prettyprint($test->{data})
Branch: 1 branch
BranchTrueFalseTotal
$self->verbose ? : 0 1240 1240
327 1240 ▶ .(ref $test->{data} ? 'reference to '.ref $test->{data} : ''));
Branch: 1 branch
BranchTrueFalseTotal
ref $$test{'data'} ? : 739 501 1240
328  
329 # for backwards compatibility, if only one value is returned, it might be possible to
330 # jsonify it to access the full results
331 1240 ▶ $ctx->${ $self->verbose ? \'diag' : \'note' }('result: '.$self->json_prettyprint($result // $result_bool));
Branch: 1 branch
BranchTrueFalseTotal
$self->verbose ? : 0 1240 1240
Condition33%1/3
$result // $result_bool
l!l&&r!l&&!r
012400
MC/DC0%0/2
$result // $result_bool
$result $result_bool
Truth table33%1/3
A // B
A= $resultB= $result_bool
ABresult
1X1
011
000
332 1240 $pass = 0;
333 }
334 else {
335 1966 $ctx->ok(1, 'test passes: data is valid: '.$expected);
336 1966 $pass = 1;
337 }
338  
339 3206 my @mutated_data_paths = $self->_mutation_check($test->{data});
340 3206 my @mutated_schema_paths = $self->_mutation_check($test_group->{schema});
341  
342 # string check path check behaviour
343 # 0 0 ::is(), and note. $pass = 0
344 # 0 1 ::is(). $pass = 0
345 # 1 0 ->fail and note. $pass = 0
346 # 1 1 no test. $pass does not change.
347  
348 3206 ▶ if ($data_before ne $data_after) {
Branch: 2 branches
BranchTrueFalseTotal
if ($data_before ne $data_after) { } 9 3197 3206
elsif (@mutated_data_paths) { } 1 3196 3197
349 9 Test2::Tools::Compare::is($data_after, $data_before, 'evaluator did not mutate data');
350 9 $pass = 0;
351 }
352 elsif (@mutated_data_paths) {
353 1 $ctx->fail('evaluator did not mutate data');
354 1 $pass = 0
355 }
356  
357 3206 ▶ $ctx->note('mutated data at location'.(@mutated_data_paths > 1 ? 's' : '').': '.join(', ', @mutated_data_paths)) if @mutated_data_paths;
Branch: 2 branches
BranchTrueFalseTotal
if @mutated_data_paths 4 3202 3206
@mutated_data_paths > 1 ? : 0 4 4
358  
359 3206 ▶ if ($schema_before ne $schema_after) {
Branch: 2 branches
BranchTrueFalseTotal
if ($schema_before ne $schema_after) { } 9 3197 3206
elsif (@mutated_schema_paths) { } 1 3196 3197
360 9 Test2::Tools::Compare::is($schema_after, $schema_before, 'evaluator did not mutate schema');
361 9 $pass = 0;
362 }
363 elsif (@mutated_schema_paths) {
364 1 $ctx->fail('evaluator did not mutate schema');
365 1 $pass = 0;
366 }
367  
368 3206 ▶ $ctx->note('mutated schema at location'.(@mutated_schema_paths > 1 ? 's' : '').': '.join(', ', @mutated_schema_paths)) if @mutated_schema_paths;
Branch: 2 branches
BranchTrueFalseTotal
if @mutated_schema_paths 4 3202 3206
@mutated_schema_paths > 1 ? : 0 4 4
369  
370 3206 $ctx->release;
371 }
372 catch ($e) {
373 2 chomp(my $exception = $e);
374 2 my $ctx = Test2::API::context;
375 2 $ctx->fail('died: '.$exception);
376 2 $ctx->release;
377 };
378 },
379 3208 { buffered => 1, inherit_trace => 1 },
380 );
381  
382 3208 return $pass;
383 }
384  
385 6412 ▶sub _mutation_check ($self, $data) {
Subroutine _mutation_check: called CC=10 SCAR=23.0
386 6412 my @error_paths;
387  
388 # [ path => data ]
389 6412 my @nodes = ([ '', $data ]);
390 6412 ▶ while (my $node = shift @nodes) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $node = shift @nodes) 19980 6412 26392
391 19980 ▶ if (not defined $node->[1]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $$node[1]) 306 19674 19980
392 306 next;
393 }
394 19674 ▶ if (ref $node->[1] eq 'ARRAY') {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $$node[1] eq 'ARRAY') { } 2259 17415 19674
elsif (ref $$node[1] eq 'HASH') { } 8155 9260 17415
elsif (ref $$node[1]) { } 1986 7274 9260
395 2259 push @nodes, map [ $node->[0].'/'.$_, $node->[1][$_] ], 0 .. $node->[1]->$#*;
396 2259 ▶ push @error_paths, $node->[0] if tied($node->[1]->@*);
Branch: 1 branch
BranchTrueFalseTotal
if tied @{$$node[1]} 0 2259 2259
397 }
398 elsif (ref $node->[1] eq 'HASH') {
399 8155 push @nodes, map [ $node->[0].'/'.(s!~!~0!gr =~ s!/!~1!gr), $node->[1]{$_} ], keys $node->[1]->%*;
400 8155 ▶ push @error_paths, $node->[0] if tied($node->[1]->%*);
Branch: 1 branch
BranchTrueFalseTotal
if tied %{$$node[1]} 2 8153 8155
401 }
402 elsif (ref $node->[1]) {
403 1986 next; # boolean or bignum
404 }
405 else {
406 7274 my $flags = B::svref_2object(\$node->[1])->FLAGS;
407 7274 ▶ push @error_paths, $node->[0]
Branch: 1 branch
BranchTrueFalseTotal
unless $flags & 1024 xor $flags & 768 6 7268 7274
Condition75%3/4
$flags & 1024 xor $flags & 768
l&&rl&&!r!l&&r!l&&!r
6473325350
MC/DC100%2/2
$flags & 1024 xor $flags & 768
$flags & 1024 $flags & 768
Truth table75%3/4
A xor B
A= $flags & 1024B= $flags & 768
ABresult
110
101
011
000
408 if not ($flags & B::SVf_POK xor $flags & (B::SVf_IOK | B::SVf_NOK));
409 }
410 }
411  
412 6412 return @error_paths;
413 }
414  
415 18 ▶use constant _JSON_BACKEND => Mojo::JSON::JSON_XS ? 'Cpanel::JSON::XS' : 'JSON::PP';
Subroutine BEGIN: called CC=1 SCAR=0.0
416  
417 # used for internal serialization/deserialization; does not prettify the string.
418 has _json_serializer => (
419 is => 'ro',
420 isa => HasMethods[qw(encode decode)],
421 handles => {
422 json_serialize => 'encode',
423 json_deserialize => 'decode',
424 },
425 lazy => 1,
426 40 ▶ default => sub { _JSON_BACKEND->new->allow_nonref(1)->utf8(1)->allow_blessed(1)->allow_bignum(1)->canonical(1) },
Subroutine __ANON__: called CC=1 SCAR=0.0
427  
428 18 );
429  
430 # used for displaying diagnostics only
431 has _json_prettyprinter => (
432 is => 'ro',
433 isa => HasMethods['encode'],
434 lazy => 1,
435 handles => {
436 json_prettyprint => 'encode',
437 },
438 8 ▶ default => sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
439 8 my $encoder = _JSON_BACKEND->new->allow_nonref(1)->utf8(0)->allow_blessed(1)->allow_bignum(1)->canonical(1)->convert_blessed(1)->pretty(1)->space_before(0);
440 8 ▶ $encoder->indent_length(2) if $encoder->can('indent_length');
Branch: 1 branch
BranchTrueFalseTotal
if $encoder->can("indent_length") 8 0 8
441 8 $encoder;
442 },
443 18 );
444  
445 # backcompat shims
446 0 ▶sub _json_decoder { shift->_json_serializer(@_) }
Subroutine _json_decoder: not called CC=1 SCAR=6.9
447 0 ▶sub json_decoder { shift->_json_serializer(@_) }
Subroutine json_decoder: not called CC=1 SCAR=6.9
Pod undocumented
448 0 ▶sub _json_encoder { shift->_json_prettyprinter(@_) }
Subroutine _json_encoder: not called CC=1 SCAR=6.9
449 0 ▶sub json_encoder { shift->_json_prettyprinter(@_) }
Subroutine json_encoder: not called CC=1 SCAR=6.9
Pod documented
450  
451 # see JSON::MaybeXS::is_bool
452 18 my $json_bool = InstanceOf[qw(JSON::XS::Boolean Cpanel::JSON::XS::Boolean JSON::PP::Boolean)];
453  
454 18 has _test_data => (
455 is => 'lazy',
456 isa => ArrayRef[Dict[
457 file => InstanceOf['Path::Tiny'],
458 json => ArrayRef[Dict[
459 # id => Optional[Str],
460 # specification => Optional[Str],
461 description => Str,
462 comment => Optional[Str],
463 schema => $json_bool|HashRef,
464 tests => ArrayRef[Dict[
465 # id => Optional[Str],
466 data => Any,
467 description => Str,
468 comment => Optional[Str],
469 valid => $json_bool,
470 Slurpy[Any],
471 ]],
472 Slurpy[Any],
473 ]],
474 ]],
475 );
476  
477 41 ▶sub _build__test_data ($self) {
Subroutine _build__test_data: called CC=2 SCAR=6.9
478 41 my @test_groups;
479  
480 $self->test_dir->visit(
481 648 ▶ sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
482 648 my ($path) = @_;
483 648 ▶ return if any { $self->test_dir->child($_)->subsumes($path) } $self->skip_dir->@*;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { $self->test_dir->child($_)->subsumes($path); } , @{$self->skip_dir}) 2 646 648
484 646 ▶ return if not $path->is_file;
Branch: 1 branch
BranchTrueFalseTotal
unless $path->is_file 26 620 646
485 620 ▶ return if $path !~ /\.json$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $path =~ /\.json$/u 2 618 620
486 618 my $data = $self->json_deserialize($path->slurp_raw);
487 618 ▶ return if not @$data; # placeholder files for renamed tests
Branch: 1 branch
BranchTrueFalseTotal
unless @$data 27 591 618
488 591 my $file = $path->relative($self->test_dir);
489 591 push @test_groups, [
490 scalar(split('/', $file)),
491 {
492 file => $file,
493 json => $data,
494 },
495 ];
496 },
497 41 { recurse => $self->include_optional },
498 );
499  
500 return [
501 map $_->[1],
502 41 ▶ sort { $a->[0] <=> $b->[0] || $a->[1]{file} cmp $b->[1]{file} }
Condition66%2/3
$our $a[0] <=> $our $b[0] || $our $a[1]{'file'} cmp $our $b[1]{'file'}
l!l&&r!l&&!r
19121270
MC/DC0%0/2
$our $a[0] <=> $our $b[0] || $our $a[1]{'file'} cmp $our $b[1]{'file'}
$our $a[0] <=> $our $b[0] $our $a[1]{'file'} cmp $our $b[1]{'file'}
Truth table66%2/3
A || B
A= $our $a[0] <=> $our $b[0]B= $our $a[1]{'file'} cmp $our $b[1]{'file'}
ABresult
1X1
011
000
503 @test_groups
504 ];
505 }
506  
507 33 ▶sub _build_results_text ($self) {
Subroutine _build_results_text: called CC=11 SCAR=25.1
508 33 my @lines;
509 169 ▶ sub _pad ($s, $rest) { sprintf('%-29s', $s) . $rest }
Subroutine _pad: called CC=1 SCAR=0.0
510 33 push @lines, _pad('generated with:', ref($self).' '.$self->VERSION);
511 33 push @lines, _pad('on perl: ', $^V);
512  
513 33 my $test_dir = $self->test_dir;
514 33 my $orig_dir = $self->_build_test_dir;
515  
516 33 my $submodule_status = path(dist_dir('Test-JSON-Schema-Acceptance'), 'submodule_status');
517 33 ▶ if ($submodule_status->exists and $submodule_status->parent->subsumes($self->test_dir)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($submodule_status->exists and $submodule_status->parent->subsumes($self->test_dir)) { } 3 30 33
elsif ($test_dir eq $orig_dir and not -d '.git') { } 0 60 60
Condition66%2/3
$submodule_status->exists and $submodule_status->parent->subsumes($self->test_dir)
!ll&&!rl&&r
0303
MC/DC50%1/2
$submodule_status->exists and $submodule_status->parent->subsumes($self->test_dir)
$submodule_status->exists $submodule_status->parent->subsumes($self->test_dir)
Truth table66%2/3
A and B
A= $submodule_status->existsB= $submodule_status->parent->subsumes($self->test_dir)
ABresult
0X0
100
111
518 3 chomp(my ($commit, $url) = $submodule_status->lines);
519 3 push @lines, _pad('with commit:', $commit);
520 3 push @lines, _pad('from repository:', $url);
521 }
522 ▶ elsif ($test_dir eq $orig_dir and not -d '.git') {
Condition33%1/3
$test_dir eq $orig_dir and not -d ".git"
!ll&&!rl&&r
3000
MC/DC0%0/2
$test_dir eq $orig_dir and not -d ".git"
$test_dir eq $orig_dir not -d ".git"
Truth table33%1/3
A and not(B)
A= $test_dir eq $orig_dirB= not -d ".git"
ABresult
0X0
100
111
523 0 die 'submodule_status file is missing - packaging error? cannot continue';
524 }
525  
526 33 ▶ push @lines, _pad('specification version:', $self->specification//'unknown');
Condition50%1/2
$self->specification // "unknown"
l!l
330
MC/DC0%0/1
$self->specification // "unknown"
$self->specification
Truth table50%1/2
A
A= $self->specification
Aresult
11
00
527  
528 33 ▶ if ($test_dir ne $orig_dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($test_dir ne $orig_dir) 30 3 33
529 30 my $local;
530 30 ▶ if ($orig_dir->subsumes($test_dir)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($orig_dir->subsumes($test_dir)) { } 0 30 30
elsif ('Path::Tiny'->cwd->subsumes($test_dir)) { } 30 0 30
531 0 $test_dir = '<base test directory>/'.substr($test_dir, length($orig_dir)+1);
532 }
533 elsif (Path::Tiny->cwd->subsumes($test_dir)) {
534 30 $test_dir = $test_dir->relative;
535 30 $local = 1;
536 }
537 30 push @lines, _pad('using custom test directory:', $test_dir);
538  
539 30 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
unless $local 0 30 30
540 0 my $git = Git::Wrapper->new($test_dir);
541 0 my @ref = $git->describe({ all => 1, long => 1, always => 1 });
542 0 push @lines, _pad('at ref:', $ref[0]);
543 } if not $local;
544 }
545 33 ▶ push @lines, _pad('optional tests included:', $self->include_optional ? 'yes' : 'no');
Branch: 1 branch
BranchTrueFalseTotal
$self->include_optional ? : 2 31 33
546 33 push @lines, map _pad('skipping directory:', $_), $self->skip_dir->@*;
547  
548 33 push @lines, '';
549 33 my $length = max(40, map length $_->{file}, $self->results->@*);
550  
551 33 push @lines, sprintf('%-'.$length.'s pass todo-fail fail', 'filename');
552 33 push @lines, '-'x($length + 23);
553 33 push @lines, map sprintf('%-'.$length.'s % 5d % 4d % 4d', $_->@{qw(file pass todo_fail fail)}),
554 $self->results->@*;
555  
556 33 my $total = +{ map do { my $type = $_; $type => sum0(map $_->{$type}, $self->results->@*) }, qw(pass todo_fail fail) };
557 33 push @lines, '-'x($length + 23);
558 33 push @lines, sprintf('%-'.$length.'s % 5d % 5d % 5d', 'TOTAL', $total->@{qw(pass todo_fail fail)});
559  
560 33 return join("\n", @lines, '');
561 }
562  
563 18 1;
564  
565 __END__
↑ Summary