| 1 | package Test::Data::Sah::Perl; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Test::Data::Sah qw(run_spectest all_match); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Test::More 0.98; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Data::Sah qw(gen_validator); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | our $DATE = '2024-02-16'; # DATE | |||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | our $DIST = 'Data-Sah'; # DIST | |||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | our $VERSION = '0.917'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | our @EXPORT_OK = qw(run_spectest_for_perl); | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | sub run_spectest_for_perl { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_spectest_for_perl: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | run_spectest( | ||||||||||||||||||||||||||||||||||||||||||
| 23 | test_merge_clause_sets => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 1503 | ▶ | test_func => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=25 SCAR=32.5
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 1503 | my $test = shift; | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 1503 | my $data = $test->{input}; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 1503 | my $ho = exists($test->{output}); # has output | |||||||||||||||||||||||||||||||||||||||||
| 29 | 1503 | my $vbool; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 1503 | eval { $vbool = gen_validator( | |||||||||||||||||||||||||||||||||||||||||
| 31 | 1503 | $test->{schema}, {accept_ref=>$ho}) }; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 1503 | my $eval_err = $@; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 1503 | ▶ | if ($test->{dies}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 33 | ok($eval_err, "compile error"); | |||||||||||||||||||||||||||||||||||||||||
| 35 | 33 | return; | |||||||||||||||||||||||||||||||||||||||||
| 36 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 1470 | ▶ | ok(!$eval_err, "compile success") or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | diag $eval_err; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 40 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 1470 | ▶ | if ($test->{valid_inputs}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | # test multiple inputs, currently only done for rt=bool_valid | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 25 | for my $i (0..@{ $test->{valid_inputs} }-1) { | |||||||||||||||||||||||||||||||||||||||||
| 46 | 51 | my $data = $test->{valid_inputs}[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 51 | ▶ | ok($vbool->($ho ? \$data : $data), "valid input [$i]"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 25 | for my $i (0..@{ $test->{invalid_inputs} }-1) { | |||||||||||||||||||||||||||||||||||||||||
| 50 | 60 | my $data = $test->{invalid_inputs}[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 60 | ▶ | ok(!$vbool->($ho ? \$data : $data), "invalid input [$i]"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | } elsif (exists $test->{valid}) { | ||||||||||||||||||||||||||||||||||||||||||
| 54 | # test a single input | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 1445 | ▶ | if ($test->{valid}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 833 | ▶ | ok($vbool->($ho ? \$data : $data), "valid (rt=bool_valid)"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 833 | ▶ | if ($ho) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 6 | is_deeply($data, $test->{output}, "output"); | |||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 612 | ▶ | ok(!$vbool->($ho ? \$data : $data), "invalid (rt=bool_valid)"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | my $vstr = gen_validator($test->{schema}, | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 1470 | {return_type=>'str_errmsg'}); | |||||||||||||||||||||||||||||||||||||||||
| 67 | 1470 | ▶ | if (exists $test->{valid}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 1445 | ▶ | if ($test->{valid}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 833 | is($vstr->($test->{input}), "", "valid (rt=str_errmsg)"); | |||||||||||||||||||||||||||||||||||||||||
| 70 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 612 | like($vstr->($test->{input}), qr/\S/, "invalid (rt=str_errmsg)"); | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | my $vfull = gen_validator($test->{schema}, | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 1470 | {return_type=>'hash_details'}); | |||||||||||||||||||||||||||||||||||||||||
| 77 | 1470 | my $res = $vfull->($test->{input}); | |||||||||||||||||||||||||||||||||||||||||
| 78 | 1470 | is(ref($res), 'HASH', "validator (rt=hash_details) returns hash"); | |||||||||||||||||||||||||||||||||||||||||
| 79 | 1470 | ▶ | if (exists($test->{errors}) || exists($test->{warnings}) || | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
exists $test->{"errors"} or exists $test->{"warnings"} or exists $test->{"valid"}
exists $test->{"errors"} or exists $test->{"warnings"}
MC/DC100%3/3
exists $test->{"errors"} or exists $test->{"warnings"} or exists $test->{"valid"}
exists $test->{"errors"}
exists $test->{"warnings"}
exists $test->{"valid"}
Truth table100%4/4
A or B or C
A= exists $test->{"errors"}B= exists $test->{"warnings"}C= exists $test->{"valid"}
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | exists($test->{valid})) { | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 1445 | ▶ | my $errors = $test->{errors} // ($test->{valid} ? 0 : 1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$test->{"errors"} // ($test->{"valid"} ? 0 : 1)
MC/DC100%1/1
$test->{"errors"} // ($test->{"valid"} ? 0 : 1)
$test->{"errors"}
Truth table100%2/2
A
A= $test->{"errors"}
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 1445 | ▶ | is(scalar(keys %{ $res->{errors} // {} }), $errors, "errors (rt=hash_details)") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$res->{"errors"} // {}
MC/DC100%1/1
$res->{"errors"} // {}
$res->{"errors"}
Truth table100%2/2
A
A= $res->{"errors"}
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | or diag explain $res; | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 1445 | ▶ | my $warnings = $test->{warnings} // 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$test->{"warnings"} // 0
MC/DC100%1/1
$test->{"warnings"} // 0
$test->{"warnings"}
Truth table100%2/2
A
A= $test->{"warnings"}
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 1445 | ▶ | is(scalar(keys %{ $res->{warnings} // {} }), $warnings, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$res->{"warnings"} // {}
MC/DC100%1/1
$res->{"warnings"} // {}
$res->{"warnings"}
Truth table100%2/2
A
A= $res->{"warnings"}
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | "warnings (rt=hash_details)") | ||||||||||||||||||||||||||||||||||||||||||
| 87 | or diag explain $res; | ||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | }, # test_func | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 1584 | ▶ | skip_if => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 1584 | my $t = shift; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 1584 | ▶ | return 0 unless $t->{tags}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | # disabled temporarily because failing for bool, even though i've | ||||||||||||||||||||||||||||||||||||||||||
| 96 | # adjust stuffs. but 'between' clause should be very seldomly used | ||||||||||||||||||||||||||||||||||||||||||
| 97 | # on bool, moreover with op, so i haven't looked into it. | ||||||||||||||||||||||||||||||||||||||||||
| 98 | return "currently failing" | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 1584 | ▶ | if all_match([qw/type:bool clause:between op/], $t->{tags}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 1556 | for (qw/ | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | check | ||||||||||||||||||||||||||||||||||||||||||
| 104 | check_each_elem | ||||||||||||||||||||||||||||||||||||||||||
| 105 | check_each_index | ||||||||||||||||||||||||||||||||||||||||||
| 106 | check_each_key | ||||||||||||||||||||||||||||||||||||||||||
| 107 | check_each_value | ||||||||||||||||||||||||||||||||||||||||||
| 108 | check_prop | ||||||||||||||||||||||||||||||||||||||||||
| 109 | exists | ||||||||||||||||||||||||||||||||||||||||||
| 110 | if | ||||||||||||||||||||||||||||||||||||||||||
| 111 | postfilters | ||||||||||||||||||||||||||||||||||||||||||
| 112 | prop | ||||||||||||||||||||||||||||||||||||||||||
| 113 | uniq | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | /) { | ||||||||||||||||||||||||||||||||||||||||||
| 116 | return "clause $_ not yet implemented" | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 16998 | ▶ | if all_match(["clause:$_"], $t->{tags}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | return "properties are not yet implemented" | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 1524 | ▶ | if grep {/^prop:/} @{ $t->{tags} }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 1503 | 0; | |||||||||||||||||||||||||||||||||||||||||
| 124 | }, # skip_if | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 130 | # ABSTRACT: Routines for testing Data::Sah (perl compiler) | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | __END__ | ||||||||||||||||||||||||||||||||||||||||||