| 1 | package TAP::Runner::Test; | ||||||||||||||||||||
| 2 | { | ||||||||||||||||||||
| 3 | 1 | $TAP::Runner::Test::VERSION = '0.005'; | |||||||||||||||||||
| 4 | } | ||||||||||||||||||||
| 5 | # ABSTRACT: Runner test class | ||||||||||||||||||||
| 6 | 1 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use TAP::Runner::Option; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 1 | ▶ | use Math::Cartesian::Product; # Used for cartesian multiplication | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 1 | subtype 'ArrayRef::' . __PACKAGE__, | |||||||||||||||||||
| 12 | as 'ArrayRef[' . __PACKAGE__ . ']'; | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | coerce 'ArrayRef::' . __PACKAGE__, | ||||||||||||||||||||
| 15 | from 'ArrayRef[HashRef]', | ||||||||||||||||||||
| 16 | 0 | ▶ | via { [ map { __PACKAGE__->new($_) } @{$_} ] }; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=3.5
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 1 | has file => ( | |||||||||||||||||||
| 19 | is => 'ro', | ||||||||||||||||||||
| 20 | isa => 'Str', | ||||||||||||||||||||
| 21 | required => 1, | ||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 1 | has alias => ( | |||||||||||||||||||
| 25 | is => 'ro', | ||||||||||||||||||||
| 26 | isa => 'Str', | ||||||||||||||||||||
| 27 | lazy_build => 1, | ||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | has args => ( | ||||||||||||||||||||
| 31 | is => 'ro', | ||||||||||||||||||||
| 32 | isa => 'ArrayRef', | ||||||||||||||||||||
| 33 | 2 | ▶ | default => sub{ [] }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 34 | 1 | ); | |||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | has options => ( | ||||||||||||||||||||
| 37 | is => 'ro', | ||||||||||||||||||||
| 38 | isa => 'ArrayRef::TAP::Runner::Option', | ||||||||||||||||||||
| 39 | 1 | ▶ | default => sub{ [] }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 40 | 1 | coerce => 1, | |||||||||||||||||||
| 41 | ); | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 1 | has harness_tests => ( | |||||||||||||||||||
| 44 | is => 'ro', | ||||||||||||||||||||
| 45 | isa => 'ArrayRef[HashRef]', | ||||||||||||||||||||
| 46 | lazy_build => 1, | ||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 0 | ▶ | sub get_parallel_rules { | ||||||||||||||||||
|
Subroutine
get_parallel_rules: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||
| 51 | 0 | my $self = shift; | |||||||||||||||||||
| 52 | 0 | my @rules = (); | |||||||||||||||||||
| 53 | my @parallel_options = | ||||||||||||||||||||
| 54 | 0 | ▶ | grep { $_->multiple && $_->parallel } @{ $self->options }; | ||||||||||||||||||
|
Condition0%0/3
$_->multiple && $_->parallel
MC/DC0%0/2
$_->multiple && $_->parallel
$_->multiple
$_->parallel
Truth table0%0/3
A && B
A= $_->multipleB= $_->parallel
| |||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 0 | foreach my $option ( @parallel_options ) { | |||||||||||||||||||
| 57 | 0 | my $test_alias = $self->alias; | |||||||||||||||||||
| 58 | 0 | my $option_name = $option->name; | |||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | push @rules, { seq => qr/$test_alias.*$option_name $_.*$/ } | ||||||||||||||||||||
| 61 | 0 | foreach @{ $option->values }; | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 0 | ( @rules ); | |||||||||||||||||||
| 65 | }; | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | # Build alias if it not defined | ||||||||||||||||||||
| 68 | 1 | ▶ | sub _build_alias { | ||||||||||||||||||
|
Subroutine
_build_alias: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 69 | 1 | my $self = shift; | |||||||||||||||||||
| 70 | 1 | $self->file; | |||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | # Build harness tests list from all the options and args | ||||||||||||||||||||
| 74 | 2 | ▶ | sub _build_harness_tests { | ||||||||||||||||||
|
Subroutine
_build_harness_tests: called CC=4 SCAR=13.9
| |||||||||||||||||||||
| 75 | 2 | my $self = shift; | |||||||||||||||||||
| 76 | 2 | my @multiple_options = (); | |||||||||||||||||||
| 77 | 2 | my @harness_tests = (); | |||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | # Array of args that same for all the tests | ||||||||||||||||||||
| 80 | 2 | my @test_args = @{ $self->args }; | |||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 2 | foreach my $option ( @{ $self->options } ) { | |||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 2 | ▶ | if ( $option->multiple ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 85 | 1 | push @multiple_options, $option; | |||||||||||||||||||
| 86 | 1 | next; | |||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | # Add options that same for all the tests | ||||||||||||||||||||
| 90 | 1 | push @test_args, map { ( $option->name, $_ ) } @{ $option->values }; | |||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | } | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | # If there are multiple options, that should passed to tests, build correct | ||||||||||||||||||||
| 95 | # tests args and harness tests | ||||||||||||||||||||
| 96 | 2 | ▶ | if ( @multiple_options ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | # Make array of arrays that contains merged options values with it names | ||||||||||||||||||||
| 99 | # Example: | ||||||||||||||||||||
| 100 | # ( | ||||||||||||||||||||
| 101 | # [ [ opt_name1, opt_val1.1 ], [ opt_name1, opt_val1.2 ] ], | ||||||||||||||||||||
| 102 | # [ [ opt_name2, opt_val2.1 ], [ opt_name2, opt_val2.2 ] ], | ||||||||||||||||||||
| 103 | # ) | ||||||||||||||||||||
| 104 | # | ||||||||||||||||||||
| 105 | 1 | my @merged_options = map { $_->get_values_array } @multiple_options; | |||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | # Make cartesian multiplication with all options | ||||||||||||||||||||
| 108 | # Result of example multiplication: | ||||||||||||||||||||
| 109 | # [ opt_name1, opt_val1.1 ],[ opt_name2, opt_val2.1 ] | ||||||||||||||||||||
| 110 | # [ opt_name1, opt_val1.1 ],[ opt_name2, opt_val2.2 ] | ||||||||||||||||||||
| 111 | # [ opt_name1, opt_val1.2 ],[ opt_name2, opt_val2.1 ] | ||||||||||||||||||||
| 112 | # [ opt_name1, opt_val1.2 ],[ opt_name2, opt_val2.2 ] | ||||||||||||||||||||
| 113 | # | ||||||||||||||||||||
| 114 | 2 | ▶ | cartesian { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 115 | # Unmerge options make separated option name and value | ||||||||||||||||||||
| 116 | # Example: ( opt_name1, opt_val1, opt_name2, opt_val2 ) | ||||||||||||||||||||
| 117 | 2 | my @opt_args = map { ($_->[0],$_->[1]) } @_; | |||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | # Build new alias defends on options that passed to test | ||||||||||||||||||||
| 120 | 2 | my $alias = $self->alias .' '. join(' ',@opt_args); | |||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | 2 | push @harness_tests, { | |||||||||||||||||||
| 123 | file => $self->file, | ||||||||||||||||||||
| 124 | alias => $alias, | ||||||||||||||||||||
| 125 | args => [ @test_args, @opt_args ], | ||||||||||||||||||||
| 126 | } | ||||||||||||||||||||
| 127 | 1 | } @merged_options; | |||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | } else { | ||||||||||||||||||||
| 130 | 1 | push @harness_tests, { | |||||||||||||||||||
| 131 | file => $self->file, | ||||||||||||||||||||
| 132 | alias => $self->alias, | ||||||||||||||||||||
| 133 | args => \@test_args, | ||||||||||||||||||||
| 134 | } | ||||||||||||||||||||
| 135 | } | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | 2 | \@harness_tests; | |||||||||||||||||||
| 138 | } | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | 1 | ▶ | no Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 141 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||
| 142 | 1 | 1; | |||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | =pod | ||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | =head1 NAME | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | TAP::Runner::Test - Runner test class | ||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | =head1 VERSION | ||||||||||||||||||||
| 153 | |||||||||||||||||||||
| 154 | version 0.005 | ||||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | =head1 DESCRIPTION | ||||||||||||||||||||
| 157 | |||||||||||||||||||||
| 158 | Test object used by L<TAP::Runner> | ||||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | =head1 MOOSE SUBTYPES | ||||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | =head2 ArrayRef::TAP::Runner::Test | ||||||||||||||||||||
| 163 | |||||||||||||||||||||
| 164 | Coerce ArrayRef[HashRef] to ArrayRef[TAP::Runner::Option] Used by L<TAP::Runner> | ||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | =head1 ATTRIBUTES | ||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | =head2 file Str | ||||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | Test file to run ( required ) | ||||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | =head2 alias Str | ||||||||||||||||||||
| 173 | |||||||||||||||||||||
| 174 | Alias for tests ( by default used file name ) | ||||||||||||||||||||
| 175 | |||||||||||||||||||||
| 176 | =head2 args ArrayRef | ||||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | Arguments that will pass to all the tests | ||||||||||||||||||||
| 179 | |||||||||||||||||||||
| 180 | =head2 options ArrayRef[TAP::Runner::Option] | ||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | Array of L<TAP::Runner::Option> used by test. | ||||||||||||||||||||
| 183 | |||||||||||||||||||||
| 184 | =head2 harness_tests ArrayRef[HashRef] | ||||||||||||||||||||
| 185 | |||||||||||||||||||||
| 186 | Array of hashes prepared for testing with L<TAP::Harness> | ||||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | HashRef -> { file: file.t, alias: 'Test alias', args: [] } | ||||||||||||||||||||
| 189 | |||||||||||||||||||||
| 190 | =head1 METHODS | ||||||||||||||||||||
| 191 | |||||||||||||||||||||
| 192 | =head2 get_parallel_rules | ||||||||||||||||||||
| 193 | |||||||||||||||||||||
| 194 | Rules for run tests in parallel | ||||||||||||||||||||
| 195 | |||||||||||||||||||||
| 196 | =head1 AUTHOR | ||||||||||||||||||||
| 197 | |||||||||||||||||||||
| 198 | Pavel R3VoLuT1OneR Zhytomirsky <r3volut1oner@gmail.com> | ||||||||||||||||||||
| 199 | |||||||||||||||||||||
| 200 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 201 | |||||||||||||||||||||
| 202 | This software is copyright (c) 2012 by Pavel R3VoLuT1OneR Zhytomirsky. | ||||||||||||||||||||
| 203 | |||||||||||||||||||||
| 204 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 205 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||
| 206 | |||||||||||||||||||||
| 207 | =cut | ||||||||||||||||||||
| 208 | |||||||||||||||||||||
| 209 | |||||||||||||||||||||
| 210 | __END__ | ||||||||||||||||||||