| 1 | package Test::Wrapper; | ||||||||||||
| 2 | 3 | ▶ | BEGIN { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 3 | $Test::Wrapper::AUTHORITY = 'cpan:YANICK'; | |||||||||||
| 4 | } | ||||||||||||
| 5 | 3 | $Test::Wrapper::VERSION = '0.3.0'; | |||||||||||
| 6 | # ABSTRACT: Use Test::* tests outside of a TAP context | ||||||||||||
| 7 | |||||||||||||
| 8 | |||||||||||||
| 9 | 3 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 3 | ▶ | use Moose::Exporter; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | |||||||||||||
| 12 | 3 | ▶ | use Test::Builder; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | |||||||||||||
| 14 | 3 | ▶ | no warnings qw/ uninitialized /; # I know, I'm a bad boy | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | |||||||||||||
| 16 | 3 | Moose::Exporter->setup_import_methods( as_is => ['test_wrap'] ); | |||||||||||
| 17 | |||||||||||||
| 18 | |||||||||||||
| 19 | 4 | ▶ | sub test_wrap { | ||||||||||
|
Subroutine
test_wrap: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||
| 20 | 4 | my ( $test, %args ) = @_; | |||||||||||
| 21 | |||||||||||||
| 22 | 4 | ▶ | my @tests = ref $test ? @$test : ($test); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 23 | |||||||||||||
| 24 | 4 | my $package = __PACKAGE__; | |||||||||||
| 25 | 4 | my $level = 1; | |||||||||||
| 26 | |||||||||||||
| 27 | 4 | ▶ | ($package) = caller $level++ while $package eq __PACKAGE__; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 28 | |||||||||||||
| 29 | 4 | for my $t (@tests) { | |||||||||||
| 30 | |||||||||||||
| 31 | 5 | my $to_wrap = join '::', $package, $args{prefix} . $t; | |||||||||||
| 32 | |||||||||||||
| 33 | 5 | my $original = join '::', $package, $t; | |||||||||||
| 34 | 5 | my $original_ref = eval '\&' . $original; | |||||||||||
| 35 | |||||||||||||
| 36 | 5 | my $proto = prototype $original_ref; | |||||||||||
| 37 | 5 | ▶ | $proto &&= "($proto)"; | ||||||||||
|
Condition100%2/2
$proto &&= "($proto)"
MC/DC100%1/1
$proto &&= "($proto)"
$proto
Truth table100%2/2
A
A= $proto
| |||||||||||||
| 38 | |||||||||||||
| 39 | 3 | ▶ | no warnings qw/ redefine /; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 40 | |||||||||||||
| 41 | 5 | ▶ | eval sprintf <<'END', $to_wrap, $proto; | ||||||||||
|
Subroutine
like: called CC=1 SCAR=0.0
Subroutine
is: called CC=1 SCAR=0.0
Subroutine
unlike: called CC=1 SCAR=0.0
| |||||||||||||
| 42 | sub %s %s { | ||||||||||||
| 43 | Test::Wrapper->run_test( $t, $original_ref, @_ ); | ||||||||||||
| 44 | } | ||||||||||||
| 45 | END | ||||||||||||
| 46 | |||||||||||||
| 47 | 5 | ▶ | die $@ if $@; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 48 | } | ||||||||||||
| 49 | } | ||||||||||||
| 50 | |||||||||||||
| 51 | |||||||||||||
| 52 | 3 | has [qw/ diag output todo /] => ( is => 'ro', ); | |||||||||||
| 53 | |||||||||||||
| 54 | 5 | ▶ | sub is_success { | ||||||||||
|
Subroutine
is_success: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 55 | 5 | return $_[0]->output =~ /^ok/; | |||||||||||
| 56 | } | ||||||||||||
| 57 | |||||||||||||
| 58 | has "_test_args" => ( | ||||||||||||
| 59 | traits => [ 'Array' ], | ||||||||||||
| 60 | isa => 'ArrayRef', | ||||||||||||
| 61 | is => 'ro', | ||||||||||||
| 62 | 0 | ▶ | default => sub { [] }, | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 63 | 3 | handles => { | |||||||||||
| 64 | test_args => 'elements', | ||||||||||||
| 65 | }, | ||||||||||||
| 66 | ); | ||||||||||||
| 67 | |||||||||||||
| 68 | 3 | has "test_name" => ( | |||||||||||
| 69 | isa => 'Str', | ||||||||||||
| 70 | is => 'ro', | ||||||||||||
| 71 | ); | ||||||||||||
| 72 | |||||||||||||
| 73 | |||||||||||||
| 74 | 5 | ▶ | sub BUILD { | ||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 75 | 5 | my $self = shift; | |||||||||||
| 76 | |||||||||||||
| 77 | # we don't need the commenting | ||||||||||||
| 78 | 5 | $self->{diag} =~ s/^\s*#//mg; | |||||||||||
| 79 | } | ||||||||||||
| 80 | |||||||||||||
| 81 | 5 | ▶ | sub run_test { | ||||||||||
|
Subroutine
run_test: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 82 | 5 | my( undef, $name, $original_ref, @args ) = @_; | |||||||||||
| 83 | 5 | $name =~ s/^:://; | |||||||||||
| 84 | |||||||||||||
| 85 | 5 | local $Test::Builder::Test = undef; | |||||||||||
| 86 | |||||||||||||
| 87 | 5 | my $builder = Test::Builder->new; | |||||||||||
| 88 | |||||||||||||
| 89 | 5 | $builder->{Have_Plan} = 1; | |||||||||||
| 90 | 5 | $builder->{Have_Output_Plan} = 1; | |||||||||||
| 91 | 5 | $builder->{Expected_Tests} = 1; | |||||||||||
| 92 | |||||||||||||
| 93 | 5 | ▶ | $builder->{History} = Test::Builder2::History->create | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 94 | if Test::More->VERSION >= 2; | ||||||||||||
| 95 | |||||||||||||
| 96 | 5 | $builder->output( \my $output ); | |||||||||||
| 97 | 5 | $builder->failure_output( \my $failure); | |||||||||||
| 98 | 5 | $builder->todo_output( \my $todo ); | |||||||||||
| 99 | |||||||||||||
| 100 | 5 | $original_ref->( @args ); | |||||||||||
| 101 | |||||||||||||
| 102 | 5 | return Test::Wrapper->new( | |||||||||||
| 103 | test_name => $name, | ||||||||||||
| 104 | _test_args => \@args, | ||||||||||||
| 105 | output => $output, | ||||||||||||
| 106 | diag => $failure, | ||||||||||||
| 107 | todo => $todo, | ||||||||||||
| 108 | ); | ||||||||||||
| 109 | |||||||||||||
| 110 | } | ||||||||||||
| 111 | |||||||||||||
| 112 | |||||||||||||
| 113 | use overload | ||||||||||||
| 114 | 3 | ▶ | 'bool' => 'is_success', | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||
| 115 | 0 | ▶ | '""' => sub { $_[0]->diag }; | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.2
| |||||||||||||
| 116 | |||||||||||||
| 117 | 3 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 118 | |||||||||||||
| 119 | 3 | 1; | |||||||||||
| 120 | |||||||||||||
| 121 | __END__ | ||||||||||||