Routine/Runner.pm

filter: Statementstmt 91.5% 54 / 59 Branchbran 100% 4 / 4 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 76.4% 13 / 17 Podpod 0.0% 0 / 1 totaltotal 83.7% 72 / 86 CC 5 SCAR 4.9
CC
5
Cov
89%
_get_tests
3.0
_run_tests
3.0
__ANON__
1.4
CRAP 1.6
« Routine/Util.pm ↑ Summary Routine/Test/Role.pm »
1 11 ▶use v5.12.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Test::Routine::Runner 0.032;
3 # ABSTRACT: tools for running Test::Routine tests
4  
5 11 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 #pod =head1 OVERVIEW
8 #pod
9 #pod A Test::Routine::Runner takes a callback for building test instances, then uses
10 #pod it to build instances and run the tests on it. The Test::Routine::Runner
11 #pod interface is still undergoing work, but the Test::Routine::Util exports for
12 #pod running tests, described in L<Test::Routine|Test::Routine/Running Tests>, are
13 #pod more stable. Please use those instead, unless you are willing to deal with
14 #pod interface breakage.
15 #pod
16 #pod =cut
17  
18 11 ▶use Carp qw(confess croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 11 ▶use Scalar::Util qw(reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 11 ▶use Test2::API 1.302045 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
21 11 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 11 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 11 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 11 subtype 'Test::Routine::_InstanceBuilder', as 'CodeRef';
28 subtype 'Test::Routine::_Instance',
29 as 'Object',
30 0 ▶ where { $_->does('Test::Routine::Common') };
Subroutine __ANON__: not called CC=1 SCAR=1.2
31  
32 coerce 'Test::Routine::_InstanceBuilder',
33 from 'Test::Routine::_Instance',
34 0 ▶ via { my $instance = $_; sub { $instance } };
Subroutine __ANON__: not called CC=1 SCAR=3.5
Subroutine __ANON__: not called CC=1 SCAR=3.5
35  
36 11 has _instance_builder => (
37 is => 'ro',
38 isa => 'Test::Routine::_InstanceBuilder',
39 coerce => 1,
40 traits => [ 'Code' ],
41 init_arg => 'instance_from',
42 required => 1,
43 handles => {
44 'build_test_instance' => 'execute_method',
45 },
46 );
47  
48 11 has description => (
49 is => 'ro',
50 isa => 'Str',
51 required => 1,
52 );
53  
54 22 ▶sub _get_tests {
Subroutine _get_tests: called CC=3 SCAR=11.1
55 22 my ($self, $test_instance) = @_;
56  
57 22 my @tests = grep { Moose::Util::does_role($_, 'Test::Routine::Test::Role') }
58 $test_instance->meta->get_all_methods;
59  
60 22 my $re = $ENV{TEST_METHOD};
61 22 ▶ if (length $re) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $re) 3 19 22
62 3 ▶ my $filter = try { qr/$re/ } # compile the the regex separately ...
Subroutine __ANON__: called CC=1 SCAR=0.0
63 0 ▶ catch { croak("TEST_METHOD ($re) is not a valid regular expression: $_") };
Subroutine __ANON__: not called CC=1 SCAR=1.2
64 3 $filter = qr/\A$filter\z/; # ... so it can't mess with the anchoring
65 3 @tests = grep { $_->description =~ $filter } @tests;
66 }
67  
68 # As a side note, I wonder whether there is any way to format the code below
69 # to not look stupid. -- rjbs, 2010-09-28
70 my @ordered_tests = sort {
71 22 $a->_origin->{file} cmp $b->_origin->{file}
72 || $a->_origin->{nth} <=> $b->_origin->{nth}
73 31 ▶ } @tests;
Condition33%1/3
$a->_origin->{'file'} cmp $b->_origin->{'file'} || $a->_origin->{'nth'} <=> $b->_origin->{'nth'}
l!l&&r!l&&!r
0310
MC/DC0%0/2
$a->_origin->{'file'} cmp $b->_origin->{'file'} || $a->_origin->{'nth'} <=> $b->_origin->{'nth'}
$a->_origin->{'file'} cmp $b->_origin->{'file'} $a->_origin->{'nth'} <=> $b->_origin->{'nth'}
Truth table33%1/3
A || B
A= $a->_origin->{'file'} cmp $b->_origin->{'file'}B= $a->_origin->{'nth'} <=> $b->_origin->{'nth'}
ABresult
1X1
011
000
74  
75 22 return \@ordered_tests;
76 }
77  
78 22 ▶sub _run_tests {
Subroutine _run_tests: called CC=3 SCAR=11.0
79 22 my ($self, $test_instance, $ordered_tests) = @_;
80  
81 22 TEST: for my $test (@$ordered_tests) {
82 47 my $ctx = Test2::API::context;
83 47 ▶ if (my $reason = $test->skip_reason($test_instance)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $reason = $test->skip_reason($test_instance)) { } 3 44 47
84 3 $ctx->skip($test->name, $reason);
85 } else {
86 44 $test_instance->run_test( $test );
87 }
88  
89 47 $ctx->release;
90 }
91 }
92  
93 22 ▶sub run {
Subroutine run: called CC=1 SCAR=0.0
Pod undocumented
94 22 my ($self) = @_;
95  
96 22 my $test_instance = $self->build_test_instance;
97  
98 22 my $ordered_tests = $self->_get_tests($test_instance);
99  
100 22 ▶ Test2::API::run_subtest($self->description, sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
101 22 $self->_run_tests($test_instance, $ordered_tests);
102 22 });
103 }
104  
105 11 1;
106  
107 __END__
« Routine/Util.pm ↑ Summary Routine/Test/Role.pm »