| 1 | # | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # Copyright (c) 2013-2021 Christian Jaeger, copying@christianjaeger.ch | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # This is free software, offered under either the same terms as perl 5 | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # or the terms of the Artistic License version 2 or the terms of the | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # MIT License (Expat version). See the file COPYING.md that came | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # bundled with this file. | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | Chj::TEST | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Chj::TEST; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | # or | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use Chj::TEST use => 'Method::Signatures' | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | #, use => ['Foo::Bar', qw(bar baz)], | ||||||||||||||||||||||||||||||||||||||||||
| 20 | #, require => 'CGI' | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | ; | |||||||||||||||||||||||||||||||||||||||||
| 22 | # ^ this will use or require the indicated modules, and if RUN_TESTS | ||||||||||||||||||||||||||||||||||||||||||
| 23 | # is set and they fail, will gracefully fail with a SKIP testing message | ||||||||||||||||||||||||||||||||||||||||||
| 24 | # (if RUN_TESTS is not set, it will die as normally). | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | TEST { 1+1 } 2; # success | ||||||||||||||||||||||||||||||||||||||||||
| 27 | TEST { 1+1 } "2"; # fails, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | # because equality is compared on the result of Data::Dumper | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | # compute also result lazily: | ||||||||||||||||||||||||||||||||||||||||||
| 31 | TEST { 1+1 } GIVES {3-1}; # success | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | TEST_STDOUT { print "Hello" } "Hello"; | ||||||||||||||||||||||||||||||||||||||||||
| 34 | TEST_EXCEPTION { die "Hello" } "Hello"; # " at .. line .." and | ||||||||||||||||||||||||||||||||||||||||||
| 35 | # backtrace are cut off | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | ▶ | use Chj::TEST ':all'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | my $result = run_tests(__PACKAGE__); | ||||||||||||||||||||||||||||||||||||||||||
| 41 | is $result->failures, 0; # 0 failures | ||||||||||||||||||||||||||||||||||||||||||
| 42 | is $result->successes > 0, 1; | ||||||||||||||||||||||||||||||||||||||||||
| 43 | is $result->exit_code, 0; # usable for passing to `exit` | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | #run_tests; | ||||||||||||||||||||||||||||||||||||||||||
| 46 | # or | ||||||||||||||||||||||||||||||||||||||||||
| 47 | #run_tests __PACKAGE__, "Another::Package"; | ||||||||||||||||||||||||||||||||||||||||||
| 48 | # or | ||||||||||||||||||||||||||||||||||||||||||
| 49 | #run_tests_ packages => __PACKAGE__, numbers => [2..4]; | ||||||||||||||||||||||||||||||||||||||||||
| 50 | # aliases package, number, no also accepted | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | # For conditional running the tests as part of a global test suite: | ||||||||||||||||||||||||||||||||||||||||||
| 53 | #perhaps_run_tests "main" or do_something_else; | ||||||||||||||||||||||||||||||||||||||||||
| 54 | # This will run run_tests("main") iff the RUN_TESTS environment | ||||||||||||||||||||||||||||||||||||||||||
| 55 | # variable is true, otherwise run do_something_else. | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | If the `TEST` environmental variable is set to false (as opposed to | ||||||||||||||||||||||||||||||||||||||||||
| 60 | not set at all), tests are dropped. This saves the memory otherwise | ||||||||||||||||||||||||||||||||||||||||||
| 61 | required to hold the test code and results. | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | L<Chj::noTEST> | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | =head1 NOTE | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | This is alpha software! Read the status section in the package README | ||||||||||||||||||||||||||||||||||||||||||
| 70 | or on the L<website|http://functional-perl.org/>. | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | package Chj::TEST; | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 86 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 86 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 86 | ▶ | use warnings FATAL => 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 86 | ▶ | use base "Exporter"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 86 | our @EXPORT = qw(TEST TEST_STDOUT TEST_EXCEPTION GIVES perhaps_run_tests); | |||||||||||||||||||||||||||||||||||||||||
| 81 | 86 | our @EXPORT_OK = qw(run_tests run_tests_ no_tests); | |||||||||||||||||||||||||||||||||||||||||
| 82 | 86 | our %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]); | |||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 86 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 86 | ▶ | use FP::Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 86 | ▶ | use Chj::singlequote; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | # get the style | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 21 | ▶ | sub run_tests_style { # "old" or "tap" | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_tests_style: called CC=3 SCAR=11.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 21 | ▶ | if (my $rt = $ENV{RUN_TESTS}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 21 | ▶ | $rt =~ /(old|pod_snippets)/i ? "old" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | : | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | #$rt =~ /(new|tap)/i ? "tap" : | ||||||||||||||||||||||||||||||||||||||||||
| 96 | "tap" | ||||||||||||||||||||||||||||||||||||||||||
| 97 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 98 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | # Use from the repl can't run "tap" style as that one will | ||||||||||||||||||||||||||||||||||||||||||
| 101 | # fail on re-runs | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | "old" | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 86 | our $run_tests_style; # used internally only, see sub run_tests_style | |||||||||||||||||||||||||||||||||||||||||
| 107 | # ($ENV{RUN_TESTS}) how to set it. OK? | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 2613 | ▶ | sub style_switch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
style_switch: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 2613 | my $choices = shift; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 2613 | ▶ | my $handler = $choices->{$run_tests_style} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | or die "missing choice for style '$run_tests_style'"; | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 2613 | goto $handler | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | # remove 'use' and 'require' arguments from import list, run them, | ||||||||||||||||||||||||||||||||||||||||||
| 117 | # then delegate to Exporter | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 812 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=12 SCAR=26.8
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 812 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 812 | my ($package, $filename, $line) = caller; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 812 | my @args; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 812 | ▶ | for (my $i = 0; $i < @_; $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 42 | my $v = $_[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 42 | ▶ | if ($v eq "use" or $v eq "require") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$v eq "use" or $v eq "require"
MC/DC50%1/2
$v eq "use" or $v eq "require"
$v eq "use"
$v eq "require"
Truth table66%2/3
A or B
A= $v eq "use"B= $v eq "require"
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 8 | my $val = $_[$i + 1]; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 8 | ▶ | defined $val or croak "undef given as 'require' parameter"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 8 | my ($module, @args) = do { | |||||||||||||||||||||||||||||||||||||||||
| 129 | 8 | ▶ | if (ref($val) eq "ARRAY") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | @$val | |||||||||||||||||||||||||||||||||||||||||
| 131 | } elsif (length $val) { | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 8 | ($val) | |||||||||||||||||||||||||||||||||||||||||
| 133 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | croak | |||||||||||||||||||||||||||||||||||||||||
| 135 | "value given as 'require' parameter must be a string or array"; | ||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 138 | my $smallcode | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | = ("$v $module " . join(",", map { singlequote $_} @args)); | |||||||||||||||||||||||||||||||||||||||||
| 140 | 8 | ▶ | $filename =~ /[\r\n]/ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | and die | ||||||||||||||||||||||||||||||||||||||||||
| 142 | "possible security issue"; # XXX: how to do it fully right? | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 8 | my $code = "#line $line $filename\npackage $package; $smallcode; 1"; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 8 | ▶ | if (eval $code) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | # ok | ||||||||||||||||||||||||||||||||||||||||||
| 147 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 2 | ▶ | if (my $rt = $ENV{RUN_TESTS}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 2 | ▶ | if ($rt =~ /pod_snippets/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | die "TEST use<$module> failed: $smallcode"; | |||||||||||||||||||||||||||||||||||||||||
| 151 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 2 | require Test::More; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 2 | Test::More::plan(skip_all => "could not $smallcode"); | |||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | exit 1; # necessary? | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | die $@ | |||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 6 | $i++; | |||||||||||||||||||||||||||||||||||||||||
| 161 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 34 | push @args, $v | |||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | 810 | ▶ | my $sub = $class->can("SUPER::import") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | or die "$class does not have an 'import' procedure"; | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 810 | @_ = ($class, @args); | |||||||||||||||||||||||||||||||||||||||||
| 168 | 810 | goto &$sub; | |||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 86 | ▶ | use Chj::xIO 'capture_stdout_'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 86 | our $tests_by_package = {}; | |||||||||||||||||||||||||||||||||||||||||
| 174 | 86 | our $num_by_package = {}; | |||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 86 | our $dropped_tests = 0; | |||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 16366 | ▶ | sub no_tests { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
no_tests: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 16366 | ▶ | @_ == 0 or fp_croak_arity 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | exists $ENV{TEST} and !$ENV{TEST} | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 16366 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 16366 | ▶ | sub _TEST { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_TEST: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 16366 | my ($proc, $res) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 185 | 16366 | ▶ | if (no_tests) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | $dropped_tests++; | |||||||||||||||||||||||||||||||||||||||||
| 187 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 16366 | my ($package, $filename, $line) = caller(1); | |||||||||||||||||||||||||||||||||||||||||
| 189 | 16366 | $$num_by_package{$package}++; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 16366 | push @{ $$tests_by_package{$package} }, | |||||||||||||||||||||||||||||||||||||||||
| 191 | [ | ||||||||||||||||||||||||||||||||||||||||||
| 192 | $proc, $res, | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 16366 | $$num_by_package{$package}, ($package, $filename, $line) | |||||||||||||||||||||||||||||||||||||||||
| 194 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 14562 | ▶ | sub TEST (&$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
TEST: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 14562 | _TEST(@_) | |||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 1130 | ▶ | sub TEST_STDOUT (&$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
TEST_STDOUT: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 1130 | my ($proc, $res) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 204 | 1130 | ▶ | _TEST(sub { capture_stdout_($proc) }, $res); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 674 | ▶ | sub TEST_EXCEPTION (&$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
TEST_EXCEPTION: called CC=1 SCAR=0.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 674 | my ($proc, $res) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 209 | _TEST( | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 43 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 43 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | eval { | ||||||||||||||||||||||||||||||||||||||||||
| 213 | 43 | &$proc(); | |||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | 1 | |||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 217 | { | ||||||||||||||||||||||||||||||||||||||||||
| 218 | undef | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | } else { | |||||||||||||||||||||||||||||||||||||||||
| 220 | 43 | my $msg = "$@"; | |||||||||||||||||||||||||||||||||||||||||
| 221 | 43 | $msg =~ s| at .*? line \d*.*||s; | |||||||||||||||||||||||||||||||||||||||||
| 222 | 43 | $msg | |||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||
| 224 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 674 | $res | |||||||||||||||||||||||||||||||||||||||||
| 226 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 409 | ▶ | sub GIVES (&) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
GIVES: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 409 | my ($thunk) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 409 | bless $thunk, "Chj::TEST::GIVES"; | |||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 86 | package Chj::TEST::Test::Builder { | |||||||||||||||||||||||||||||||||||||||||
| 235 | 86 | our @ISA = qw(Test::Builder); | |||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | # sub level { | ||||||||||||||||||||||||||||||||||||||||||
| 238 | # my( $self, $level ) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 239 | # # original just sets $Level in Test::Builder to $level if | ||||||||||||||||||||||||||||||||||||||||||
| 240 | # # defined; returns $Level | ||||||||||||||||||||||||||||||||||||||||||
| 241 | # 18 | ||||||||||||||||||||||||||||||||||||||||||
| 242 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | # Ah, ^ that won't ever work since the sub at the right location | ||||||||||||||||||||||||||||||||||||||||||
| 244 | # already returned after value generation. So, fake it | ||||||||||||||||||||||||||||||||||||||||||
| 245 | # completely instead: | ||||||||||||||||||||||||||||||||||||||||||
| 246 | 86 | our $fake_caller; | |||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | sub caller { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
caller: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | my ($self, $height) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | if ($fake_caller) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | wantarray ? @$fake_caller : $$fake_caller[0] ## no critic | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | my $m = $self->can("SUPER::caller") or die "bug"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | goto $m | |||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | 86 | ▶ | use FP::Equal qw(relaxedequal); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | 86 | ▶ | use FP::Show; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 823 | ▶ | sub eval_test { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
eval_test: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 823 | ▶ | @_ == 2 or fp_croak_arity 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 823 | my ($t, $stat) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 265 | 823 | my ($proc, $res, $num, $package, $filename, $line) = @$t; | |||||||||||||||||||||||||||||||||||||||||
| 266 | style_switch { | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 6 | ▶ | old => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 6 | print "running test $num.."; | |||||||||||||||||||||||||||||||||||||||||
| 269 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 270 | 817 | ▶ | tap => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | # say nothing, the ok at the end will say it; XXX: capture | ||||||||||||||||||||||||||||||||||||||||||
| 273 | # output! then present that after the "not ok" output. | ||||||||||||||||||||||||||||||||||||||||||
| 274 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 823 | }; | |||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | 823 | my ($got, $maybe_e); | |||||||||||||||||||||||||||||||||||||||||
| 278 | 823 | ▶ | my $action = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | 823 | $got = &$proc; | |||||||||||||||||||||||||||||||||||||||||
| 280 | 820 | ▶ | if (ref($res) eq 'Chj::TEST::GIVES') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | 11 | $res = &$res; | |||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 823 | }; | |||||||||||||||||||||||||||||||||||||||||
| 284 | style_switch { | ||||||||||||||||||||||||||||||||||||||||||
| 285 | old => $action, | ||||||||||||||||||||||||||||||||||||||||||
| 286 | 817 | ▶ | tap => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | eval { | ||||||||||||||||||||||||||||||||||||||||||
| 288 | 817 | &$action; | |||||||||||||||||||||||||||||||||||||||||
| 289 | 814 | 1 | |||||||||||||||||||||||||||||||||||||||||
| 290 | 817 | ▶ | } || do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | 3 | $maybe_e = [$@]; # box it to ensure not undef | |||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||
| 293 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 294 | 823 | }; | |||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 823 | my $location = "at $filename line $line"; | |||||||||||||||||||||||||||||||||||||||||
| 297 | 823 | my $nicelocation = "line $line"; | |||||||||||||||||||||||||||||||||||||||||
| 298 | 823 | ▶ | if (!$maybe_e and relaxedequal($got, $res)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $maybe_e and relaxedequal($got, $res)
MC/DC100%2/2
not $maybe_e and relaxedequal($got, $res)
not $maybe_e
relaxedequal($got, $res)
Truth table100%3/3
not(A) and B
A= not $maybe_eB= relaxedequal($got, $res)
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | style_switch { | ||||||||||||||||||||||||||||||||||||||||||
| 300 | 6 | ▶ | old => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 6 | print "ok\n"; | |||||||||||||||||||||||||||||||||||||||||
| 302 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 303 | 813 | ▶ | tap => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | 813 | pass($nicelocation); | |||||||||||||||||||||||||||||||||||||||||
| 305 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 819 | }; | |||||||||||||||||||||||||||||||||||||||||
| 307 | 819 | $$stat{successes}++ | |||||||||||||||||||||||||||||||||||||||||
| 308 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 309 | 4 | my $gotstr = show $got; | |||||||||||||||||||||||||||||||||||||||||
| 310 | 4 | my $resstr = show $res; | |||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | style_switch { | ||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | old => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | die "bug, shouldn't happen in this mode" if defined $maybe_e; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | print "FAIL $location:\n"; | |||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | print " got: $gotstr\n"; | |||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | print " expected: $resstr\n"; | |||||||||||||||||||||||||||||||||||||||||
| 318 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 319 | 4 | ▶ | tap => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | # fail($location); | ||||||||||||||||||||||||||||||||||||||||||
| 322 | # want to avoid it reporting this file as the location, thus use this: | ||||||||||||||||||||||||||||||||||||||||||
| 323 | 4 | my $tb = Test::More->builder; | |||||||||||||||||||||||||||||||||||||||||
| 324 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 325 | 4 | ▶ | ref($tb) eq 'Test::Builder' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $tb eq "Test::Builder" or ref $tb eq "Chj::TEST::Test::Builder"
MC/DC0%0/2
ref $tb eq "Test::Builder" or ref $tb eq "Chj::TEST::Test::Builder"
ref $tb eq "Test::Builder"
ref $tb eq "Chj::TEST::Test::Builder"
Truth table66%2/3
A or B
A= ref $tb eq "Test::Builder"B= ref $tb eq "Chj::TEST::Test::Builder"
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | or ref($tb) eq 'Chj::TEST::Test::Builder' | ||||||||||||||||||||||||||||||||||||||||||
| 327 | or die "unexpected class of: $tb" | ||||||||||||||||||||||||||||||||||||||||||
| 328 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 329 | 4 | bless $tb, 'Chj::TEST::Test::Builder'; | |||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | # NOTE: Test::More->builder is a singleton and | ||||||||||||||||||||||||||||||||||||||||||
| 332 | # *remains* blessed! | ||||||||||||||||||||||||||||||||||||||||||
| 333 | 4 | local $Chj::TEST::Test::Builder::fake_caller | |||||||||||||||||||||||||||||||||||||||||
| 334 | = [$package, $filename, $line]; | ||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | #$tb->ok( 0, $nicelocation); | ||||||||||||||||||||||||||||||||||||||||||
| 337 | # On some systems (Test::Builder versions?), the above | ||||||||||||||||||||||||||||||||||||||||||
| 338 | # hackery doesn't work (sigh, move to Test2::*?), thus | ||||||||||||||||||||||||||||||||||||||||||
| 339 | # provide the full location info anyway: | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 4 | $tb->ok(0, $location); | |||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | 4 | ▶ | if (defined $maybe_e) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | 3 | diag("Exception: $$maybe_e[0]"); | |||||||||||||||||||||||||||||||||||||||||
| 344 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 345 | 1 | diag(" got: $gotstr\n" . " expected: $resstr\n"); | |||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||
| 347 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||
| 349 | 4 | $$stat{failures}++ | |||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | 55 | ▶ | sub run_tests_for_package { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_tests_for_package: called CC=1 SCAR=1.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 354 | 55 | my ($package, $stat, $maybe_testnumbers) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 55 | ▶ | my $action = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=29.5
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | 55 | ▶ | if (my $tests = $$tests_by_package{$package}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 358 | 55 | ▶ | if (defined $maybe_testnumbers) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | style_switch { | ||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | old => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 362 | "=== running selected tests in package '$package'\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 363 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | ▶ | tap => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | # XX better? | ||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | warn | |||||||||||||||||||||||||||||||||||||||||
| 368 | "=== running selected tests in package '$package'\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 369 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | for my $number (@$maybe_testnumbers) { | |||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | if ( $number =~ /^\d+\z/ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$number =~ /^\d+\z/ and $number > 0 and my $test = $$tests[$number - 1]
$number =~ /^\d+\z/ and $number > 0
MC/DC0%0/3
$number =~ /^\d+\z/ and $number > 0 and my $test = $$tests[$number - 1]
$number =~ /^\d+\z/
$number > 0
my $test = $$tests[$number - 1]
Truth table0%0/4
A and B and C
A= $number =~ /^\d+\z/B= $number > 0C= my $test = $$tests[$number - 1]
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | and $number > 0 | ||||||||||||||||||||||||||||||||||||||||||
| 374 | and (my $test = $$tests[$number - 1])) | ||||||||||||||||||||||||||||||||||||||||||
| 375 | { | ||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | eval_test $test, $stat | |||||||||||||||||||||||||||||||||||||||||
| 377 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | warn "ignoring invalid test number '$number'"; | |||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||
| 381 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 382 | 55 | ▶ | my $action = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | 55 | for my $test (@$tests) { | |||||||||||||||||||||||||||||||||||||||||
| 384 | 823 | eval_test $test, $stat | |||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||
| 386 | 55 | }; | |||||||||||||||||||||||||||||||||||||||||
| 387 | style_switch { | ||||||||||||||||||||||||||||||||||||||||||
| 388 | 2 | ▶ | old => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | 2 | print "=== running tests in package '$package'\n"; | |||||||||||||||||||||||||||||||||||||||||
| 390 | 2 | &$action; | |||||||||||||||||||||||||||||||||||||||||
| 391 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 392 | 53 | ▶ | tap => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | 53 | plan(tests => scalar @$tests); | |||||||||||||||||||||||||||||||||||||||||
| 394 | 53 | &$action; | |||||||||||||||||||||||||||||||||||||||||
| 395 | 53 | done_testing(); | |||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 397 | 55 | }; | |||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||
| 399 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 400 | style_switch { | ||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | old => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | print "=== no tests for package '$package'\n"; | |||||||||||||||||||||||||||||||||||||||||
| 403 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | ▶ | tap => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | # Can't do 0 tests, planning for it throws an | ||||||||||||||||||||||||||||||||||||||||||
| 407 | # exception right away, and not planning will fail | ||||||||||||||||||||||||||||||||||||||||||
| 408 | # in the upper level instead. Thus, fake test result: | ||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | plan(tests => 1); | |||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | pass("no tests for package '$package'"); | |||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | done_testing(); | |||||||||||||||||||||||||||||||||||||||||
| 412 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||
| 415 | 55 | }; | |||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | style_switch { | ||||||||||||||||||||||||||||||||||||||||||
| 418 | old => $action, | ||||||||||||||||||||||||||||||||||||||||||
| 419 | 53 | ▶ | tap => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | 53 | subtest("Package $package" => $action); | |||||||||||||||||||||||||||||||||||||||||
| 421 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 422 | 55 | }; | |||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | 26 | ▶ | sub unify_values { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unify_values: called CC=4 SCAR=14.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | 26 | my $maybe_values; | |||||||||||||||||||||||||||||||||||||||||
| 427 | 26 | for (@_) { | |||||||||||||||||||||||||||||||||||||||||
| 428 | 65 | ▶ | if (ref $_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | 13 | push @$maybe_values, @$_ | |||||||||||||||||||||||||||||||||||||||||
| 430 | } elsif (defined $_) { | ||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | push @$maybe_values, $_ | |||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||
| 434 | $maybe_values | ||||||||||||||||||||||||||||||||||||||||||
| 435 | 26 | } | |||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||
| 437 | 86 | package Chj::TEST::Result { | |||||||||||||||||||||||||||||||||||||||||
| 438 | 172 | ▶ | my $accessor = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | 172 | my ($field) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 440 | 4 | ▶ | sub { my $s = shift; $$s{$field} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | 172 | }; | |||||||||||||||||||||||||||||||||||||||||
| 442 | 86 | *failures = $accessor->("failures"); | |||||||||||||||||||||||||||||||||||||||||
| 443 | 86 | *successes = $accessor->("successes"); | |||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||
| 445 | 1 | ▶ | sub exit_code { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exit_code: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 447 | 1 | my $n = $self->failures; | |||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||
| 449 | # arbitrary use of exit codes up to 99, OK? | ||||||||||||||||||||||||||||||||||||||||||
| 450 | 1 | ▶ | $n < 100 ? $n : 100 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||
| 454 | 13 | ▶ | sub run_tests_ { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_tests_: called CC=6 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | 13 | ▶ | @_ % 2 and die "need even number of arguments"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 456 | 13 | my $args = +{@_}; | |||||||||||||||||||||||||||||||||||||||||
| 457 | my $maybe_packages = unify_values delete $$args{packages}, | ||||||||||||||||||||||||||||||||||||||||||
| 458 | 13 | delete $$args{package}; | |||||||||||||||||||||||||||||||||||||||||
| 459 | my $maybe_testnumbers = unify_values delete $$args{numbers}, | ||||||||||||||||||||||||||||||||||||||||||
| 460 | 13 | delete $$args{number}, delete $$args{no}; | |||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | for (sort keys %$args) { warn "run_tests_: unknown argument '$_'" } | |||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||
| 463 | 13 | ▶ | local $run_tests_style //= run_tests_style; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
local $Chj::TEST::run_tests_style //= run_tests_style()
MC/DC0%0/2
local $Chj::TEST::run_tests_style //= run_tests_style()
local $Chj::TEST::run_tests_style
run_tests_style()
Truth table33%1/3
A //= B
A= local $Chj::TEST::run_tests_styleB= run_tests_style()
| |||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||
| 465 | 13 | local $| = 1; | |||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | style_switch { | ||||||||||||||||||||||||||||||||||||||||||
| 468 | 2 | ▶ | old => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 469 | 2 | print "==== run_tests in $run_tests_style style ====\n"; | |||||||||||||||||||||||||||||||||||||||||
| 470 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 471 | 11 | ▶ | tap => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||
| 473 | # if run_tests is called from perhaps_run_tests this was | ||||||||||||||||||||||||||||||||||||||||||
| 474 | # already done but can't count on that: | ||||||||||||||||||||||||||||||||||||||||||
| 475 | 11 | require Test::More; | |||||||||||||||||||||||||||||||||||||||||
| 476 | 11 | import Test::More; | |||||||||||||||||||||||||||||||||||||||||
| 477 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 478 | 13 | }; | |||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | 13 | my $stat = bless { successes => 0, failures => 0 }, "Chj::TEST::Result"; | |||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||
| 482 | 13 | my $packages = do { | |||||||||||||||||||||||||||||||||||||||||
| 483 | 13 | ▶ | if (defined $maybe_packages and @$maybe_packages) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $maybe_packages and @$maybe_packages
MC/DC50%1/2
defined $maybe_packages and @$maybe_packages
defined $maybe_packages
@$maybe_packages
Truth table66%2/3
A and B
A= defined $maybe_packagesB= @$maybe_packages
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | 12 | $maybe_packages; | |||||||||||||||||||||||||||||||||||||||||
| 485 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 486 | 1 | [sort keys %$tests_by_package] | |||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||
| 488 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 489 | 13 | ▶ | my $action = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 490 | 13 | run_tests_for_package $_, $stat, $maybe_testnumbers for @$packages; | |||||||||||||||||||||||||||||||||||||||||
| 491 | 13 | }; | |||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||
| 493 | style_switch { | ||||||||||||||||||||||||||||||||||||||||||
| 494 | 2 | ▶ | old => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 495 | 2 | &$action; | |||||||||||||||||||||||||||||||||||||||||
| 496 | 2 | print "===\n"; | |||||||||||||||||||||||||||||||||||||||||
| 497 | 2 | print " => $$stat{successes} success(es), " | |||||||||||||||||||||||||||||||||||||||||
| 498 | . "$$stat{failures} failure(s)\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 499 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 500 | 11 | ▶ | tap => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 501 | 11 | plan(tests => scalar @$packages); | |||||||||||||||||||||||||||||||||||||||||
| 502 | 11 | &$action; | |||||||||||||||||||||||||||||||||||||||||
| 503 | 11 | done_testing(); | |||||||||||||||||||||||||||||||||||||||||
| 504 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 505 | 13 | }; | |||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||
| 507 | 13 | $stat | |||||||||||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||
| 510 | 13 | ▶ | sub run_tests { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_tests: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 511 | 13 | my $packages = [@_]; | |||||||||||||||||||||||||||||||||||||||||
| 512 | 13 | run_tests_ packages => $packages; | |||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | # run tests for test suite: | ||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | 30 | ▶ | sub perhaps_run_tests { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
perhaps_run_tests: called CC=4 SCAR=16.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 518 | 30 | my $args = [@_]; | |||||||||||||||||||||||||||||||||||||||||
| 519 | 30 | ▶ | if ($ENV{RUN_TESTS}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||
| 521 | # run TEST forms (called as part of test suite) | ||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||
| 523 | 8 | ▶ | die "Tests were dropped due to the TEST environmental " | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 524 | . "variable being set to false" | ||||||||||||||||||||||||||||||||||||||||||
| 525 | if $dropped_tests; | ||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||
| 527 | 8 | ▶ | local $run_tests_style //= run_tests_style; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
local $Chj::TEST::run_tests_style //= run_tests_style()
MC/DC0%0/2
local $Chj::TEST::run_tests_style //= run_tests_style()
local $Chj::TEST::run_tests_style
run_tests_style()
Truth table33%1/3
A //= B
A= local $Chj::TEST::run_tests_styleB= run_tests_style()
| |||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||
| 529 | 8 | require Test::More; | |||||||||||||||||||||||||||||||||||||||||
| 530 | 8 | import Test::More; | |||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||
| 532 | style_switch { | ||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | ▶ | old => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||
| 535 | # Outer single TAP wrapper around the running of the | ||||||||||||||||||||||||||||||||||||||||||
| 536 | # whole test suite. # XX could still report individual | ||||||||||||||||||||||||||||||||||||||||||
| 537 | # failures by collecting them up, perhaps even simply | ||||||||||||||||||||||||||||||||||||||||||
| 538 | # via Capture::Tiny. Not currently done. | ||||||||||||||||||||||||||||||||||||||||||
| 539 | is( | ||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | eval { run_tests(@$args)->failures } | |||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | ▶ | // do { diag($@); undef }, | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
eval {
do {
run_tests(@$args)->failures
}
} // do {
diag($@);
undef
}
MC/DC0%0/2
eval {
do {
run_tests(@$args)->failures
}
} // do {
diag($@);
undef
}
eval {
do {
run_tests(@$args)->failures
}
}
do {
diag($@);
undef
}
Truth table0%0/3
A // B
A= eval {
do {
run_tests(@$args)->failures
}
}B= do {
diag($@);
undef
}
| |||||||||||||||||||||||||||||||||||||||||||
| 542 | 0, "run_tests" | ||||||||||||||||||||||||||||||||||||||||||
| 543 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | done_testing(); | |||||||||||||||||||||||||||||||||||||||||
| 545 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 546 | 8 | ▶ | tap => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||
| 548 | # Run each test as a TAP test. | ||||||||||||||||||||||||||||||||||||||||||
| 549 | # Handle exceptions at each individual test, OK? | ||||||||||||||||||||||||||||||||||||||||||
| 550 | 8 | run_tests(@$args); | |||||||||||||||||||||||||||||||||||||||||
| 551 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 552 | 8 | }; | |||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||
| 554 | 8 | 1 # so that one can write `perhaps_run_tests or something_else;` | |||||||||||||||||||||||||||||||||||||||||
| 555 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 556 | () | ||||||||||||||||||||||||||||||||||||||||||
| 557 | 22 | } | |||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||
| 560 | 86 | 1 | |||||||||||||||||||||||||||||||||||||||||