| 1 | # | ||||||||||||||||||||||||||||
| 2 | # This file is part of TAP-SimpleOutput | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # This software is Copyright (c) 2012 by Chris Weyl. | ||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||
| 6 | # This is free software, licensed under: | ||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||
| 8 | # The GNU Lesser General Public License, Version 2.1, February 1999 | ||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||
| 10 | package TAP::SimpleOutput; | ||||||||||||||||||||||||||||
| 11 | 2 | our $AUTHORITY = 'cpan:RSRCHBOY'; | |||||||||||||||||||||||||||
| 12 | # git description: 0.007-1-g6755323 | ||||||||||||||||||||||||||||
| 13 | 2 | $TAP::SimpleOutput::VERSION = '0.008'; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | # ABSTRACT: Simple closure-driven TAP generator | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 2 | use Sub::Exporter::Progressive -setup => { | |||||||||||||||||||||||||||
| 21 | exports => [ qw{ | ||||||||||||||||||||||||||||
| 22 | counters counters_and_levelset counters_as_hashref | ||||||||||||||||||||||||||||
| 23 | subtest_header subtest_header_needed | ||||||||||||||||||||||||||||
| 24 | } ], | ||||||||||||||||||||||||||||
| 25 | groups => { | ||||||||||||||||||||||||||||
| 26 | default => [ 'counters' ], | ||||||||||||||||||||||||||||
| 27 | subtest => [ qw{ counters subtest_header subtest_header_needed } ], | ||||||||||||||||||||||||||||
| 28 | }, | ||||||||||||||||||||||||||||
| 29 | 2 | ▶ | }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 2 | ▶ | use Carp 'croak'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | 2 | ▶ | use Class::Load 'try_load_class'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | sub counters { | ||||||||||||||||||||||||||||
| 36 | 6 | ▶ | my $level = shift @_; | ||||||||||||||||||||||||||
|
Subroutine
counters: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 6 | ▶ | return { _build_counters($level) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | unless wantarray; | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 4 | my $i = 0; | |||||||||||||||||||||||||||
| 42 | my @counters = | ||||||||||||||||||||||||||||
| 43 | 4 | grep { $i++ % 2 } | |||||||||||||||||||||||||||
| 44 | _build_counters($level) | ||||||||||||||||||||||||||||
| 45 | ; | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # ditch levelset | ||||||||||||||||||||||||||||
| 48 | 4 | pop @counters; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 4 | return @counters; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 1 | ▶ | sub counters_as_hashref { scalar counters } | ||||||||||||||||||||||||||
|
Subroutine
counters_as_hashref: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | sub counters_and_levelset { goto \&_build_counters } | ||||||||||||||||||||||||||
|
Subroutine
counters_and_levelset: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | sub _build_counters { | ||||||||||||||||||||||||||||
| 60 | 6 | ▶ | my $level = shift @_ || 0; | ||||||||||||||||||||||||||
|
Subroutine
_build_counters: called CC=3 SCAR=12.2
Condition100%2/2
shift @_ || 0
MC/DC100%1/1
shift @_ || 0
shift @_
Truth table100%2/2
A
A= shift @_
| |||||||||||||||||||||||||||||
| 61 | 6 | $level *= 4; | |||||||||||||||||||||||||||
| 62 | 6 | my $i = 0; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 6 | ▶ | my $indent = !$level ? q{} : (' ' x $level); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | return ( | ||||||||||||||||||||||||||||
| 67 | 19 | ▶ | ok => sub { $indent . 'ok ' . ++$i . " - $_[0]" }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 68 | 5 | ▶ | nok => sub { $indent . 'not ok ' . ++$i . " - $_[0]" }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 69 | 5 | ▶ | skip => sub { $indent . 'ok ' . ++$i . " # skip $_[0]" }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 70 | 5 | ▶ | plan => sub { $indent . "1..$i" }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 71 | 5 | ▶ | todo => sub { "$_[0] # TODO $_[1]" }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 72 | 4 | ▶ | freeform => sub { $indent . "$_[0]" }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 73 | levelset => sub { | ||||||||||||||||||||||||||||
| 74 | # if we're called with a new level, set $level and $indent | ||||||||||||||||||||||||||||
| 75 | # appropriately | ||||||||||||||||||||||||||||
| 76 | 0 | ▶ | do { $level = $_[0] * 4; $indent = !$level ? q{} : (' ' x $level) } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 77 | if defined $_[0]; | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | # return our new/set level regardless, in the form we passed it in | ||||||||||||||||||||||||||||
| 80 | 0 | return $level / 4; | |||||||||||||||||||||||||||
| 81 | }, | ||||||||||||||||||||||||||||
| 82 | 6 | ); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 2 | my $_subtest_header_needed; | |||||||||||||||||||||||||||
| 87 | sub subtest_header_needed { | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | return $_subtest_header_needed | ||||||||||||||||||||||||||
|
Subroutine
subtest_header_needed: not called CC=4 SCAR=30.0
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | if defined $_subtest_header_needed; | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | do { | ||||||||||||||||||||||||||||
| 93 | 0 | my ($success, $error) = try_load_class $_; | |||||||||||||||||||||||||||
| 94 | 0 | ▶ | croak __PACKAGE__ . " needs $_, but can't find it: $error" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | unless $success; | ||||||||||||||||||||||||||||
| 96 | 0 | } for qw{ Perl::Version Test::More }; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | return $_subtest_header_needed | |||||||||||||||||||||||||||
| 99 | = Perl::Version->new(Test::More->VERSION) >= Perl::Version->new('0.98_05'); | ||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub _subtest_header_indent { $INC{'Test/Stream.pm'} ? q{} : (' ' x 4) } | ||||||||||||||||||||||||||
|
Subroutine
_subtest_header_indent: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | sub subtest_header { | ||||||||||||||||||||||||||||
| 106 | 0 | ▶ | my ($out, $name) = @_; | ||||||||||||||||||||||||||
|
Subroutine
subtest_header: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | $out = $out->{freeform} | ||||||||||||||||||||||||||||
| 109 | 0 | ▶ | if ref $out && ref $out eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $out and ref $out eq "HASH"
MC/DC0%0/2
ref $out and ref $out eq "HASH"
ref $out
ref $out eq "HASH"
Truth table0%0/3
A and B
A= ref $outB= ref $out eq "HASH"
| |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | return subtest_header_needed() | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | ? $out->(_subtest_header_indent . "# Subtest: $name") | ||||||||||||||||||||||||||||
| 113 | : q{} | ||||||||||||||||||||||||||||
| 114 | ; | ||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 2 | !!42; | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | __END__ | ||||||||||||||||||||||||||||