Runner.pm untested

filter: Statementstmt 0.0% 0 / 51 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 76 CC 6 SCAR 23.5
CC
6
Cov
0%
_get_harness_args
20.0
run
12.0
_get_harness_tests
2.0
CRAP 10.5
1 package TAP::Runner;
2 {
3 $TAP::Runner::VERSION = '0.005';
4 }
5 # ABSTRACT: Running tests with options
6 use Moose;
7 use Carp;
8 use TAP::Runner::Test;
9  
10  
11  
12 has harness_class => (
13 is => 'rw',
14 isa => 'Str',
15 default => 'TAP::Harness',
16 );
17  
18  
19 has harness_formatter => (
20 is => 'rw',
21 predicate => 'has_custom_formatter',
22 );
23  
24  
25 has harness_args => (
26 is => 'rw',
27 isa => 'HashRef',
28 default => sub{ {} },
29 );
30  
31  
32 has tests => (
33 is => 'rw',
34 isa => 'ArrayRef::TAP::Runner::Test',
35 coerce => 1,
36 );
37  
38  
39  
40  
41 sub run {
42 my $self = shift;
43 my $harness_class = $self->harness_class;
44 my $harness_args = $self->_get_harness_args;
45 my @harness_tests = $self->_get_harness_tests;
46  
47 # Load harness class
48 eval "use $harness_class";
49 croak "Can't load $harness_class" if $@;
50  
51 my $harness = $harness_class->new( $harness_args );
52  
53 # Custom formatter
54 $harness->formatter( $self->harness_formatter )
55 if $self->has_custom_formatter;
56  
57 $harness->runtests( @harness_tests );
58 }
59  
60 # Harness args with building test arguments
61 sub _get_harness_args {
62 my $self = shift;
63  
64 # Build parallel runing test rules
65 my @rules = (
66 map { $_->get_parallel_rules } @{ $self->tests },
67 exists $self->harness_args->{rules}->{par} ?
68 @{ $self->harness_args->{rules}->{par} } : ()
69 );
70  
71 # Set correct jobs counter if jobs not set
72 $self->harness_args->{jobs} = int @rules
73 if ( @rules and not exists $self->harness_args->{jobs} );
74  
75 # Build tests args hash ref
76 my %test_args =
77 map { ( $_->{alias}, $_->{args} ) }
78 map { @{ $_->harness_tests } } @{ $self->tests };
79  
80 $self->harness_args->{rules} = { par => \@rules } if @rules;
81 $self->harness_args->{test_args} = \%test_args;
82 $self->harness_args;
83 }
84  
85 # Return array of tests to run with it aliases
86 sub _get_harness_tests {
87 my $self = shift;
88  
89 map { [ $_->{file}, $_->{alias} ] }
90 map { @{ $_->harness_tests } } @{ $self->tests };
91 }
92  
93 no Moose;
94 __PACKAGE__->meta->make_immutable;
95 1;
96  
97  
98  
99 =pod
100  
101 =head1 NAME
102  
103 TAP::Runner - Running tests with options
104  
105 =head1 VERSION
106  
107 version 0.005
108  
109 =head1 SYNOPSIS
110  
111 #!/usr/bin/perl
112 use strict;
113 use warnings;
114  
115 use TAP::Runner;
116 use TAP::Formatter::HTML;
117  
118 TAP::Runner->new(
119 {
120 # harness_class => 'TAP::Harness::JUnit',
121 harness_formatter => TAP::Formatter::HTML->new,
122 tests => [
123 {
124 file => 't/examples/test.t',
125 alias => 'Test alias',
126 args => [
127 '--option', 'option_value_1'
128 ],
129 options => [
130 {
131 name => '--website',
132 values => [
133 'first.local',
134 'second.local',
135 ],
136 multiple => 0,
137 },
138 {
139 name => '--browser',
140 values => [
141 'firefox',
142 'chrome',
143 ],
144 multiple => 1,
145 parallel => 1,
146 },
147 ],
148 },
149 {
150 file => 't/examples/test.t',
151 alias => 'Test alias 2',
152 args => [
153 '--option', 'option_value_1'
154 ],
155 },
156 ],
157 }
158 )->run;
159  
160 =head1 DESCRIPTION
161  
162 This module allows to run tests more flexible. Allows to use TAP::Harness, not just for unit tests.
163  
164 =head1 ATTRIBUTES
165  
166 =head2 harness_class
167  
168 Harness class to run the tests ( default L<TAP::Harness> )
169  
170 =head2 harness_formatter
171  
172 Custom formatter for Harness.
173  
174 =head2 harness_args HashRef
175  
176 Default args that will pass to Harness object
177  
178 =head2 tests ArrayRef[TAP::Runner::Test]
179  
180 Tests configs that should run. See L<TAP::Runner::Test>
181  
182 =head1 METHODS
183  
184 =head2 new
185  
186 Create a new L<TAP::Runner> object. tests atribute required
187  
188 # Tests to run with runner
189 my @tests = ( { file => 't/test.t' } );
190  
191 # Tests auto coerce to L<TAP::Runner::Test>
192 my $runner = TAP::Runner->new(
193 tests => \@tests,
194 );
195  
196 =head2 run
197  
198 Run the tests
199  
200 =head1 AUTHOR
201  
202 Pavel R3VoLuT1OneR Zhytomirsky <r3volut1oner@gmail.com>
203  
204 =head1 COPYRIGHT AND LICENSE
205  
206 This software is copyright (c) 2012 by Pavel R3VoLuT1OneR Zhytomirsky.
207  
208 This is free software; you can redistribute it and/or modify it under
209 the same terms as the Perl 5 programming language system itself.
210  
211 =cut
212  
213  
214 __END__