| 1 | package TAP::Harness::Env; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use constant IS_VMS => ( $^O eq 'VMS' ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use TAP::Object; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use Text::ParseWords qw/shellwords/; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 7 | our $VERSION = '3.52'; | |||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | # Get the parts of @INC which are changed from the stock list AND | ||||||||||||||||||||||||||||||||
| 13 | # preserve reordering of stock directories. | ||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub _filtered_inc_vms { | ||||||||||||||||||||||||||||||
|
Subroutine
_filtered_inc_vms: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||
| 15 | 0 | my @inc = grep { !ref } @INC; #28567 | |||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | # VMS has a 255-byte limit on the length of %ENV entries, so | ||||||||||||||||||||||||||||||||
| 18 | # toss the ones that involve perl_root, the install location | ||||||||||||||||||||||||||||||||
| 19 | 0 | @inc = grep { !/perl_root/i } @inc; | |||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | 0 | my @default_inc = _default_inc(); | |||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | 0 | my @new_inc; | |||||||||||||||||||||||||||||||
| 24 | my %seen; | ||||||||||||||||||||||||||||||||
| 25 | 0 | for my $dir (@inc) { | |||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | next if $seen{$dir}++; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | if ( $dir eq ( $default_inc[0] || '' ) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$default_inc[0] || ''
MC/DC0%0/1
$default_inc[0] || ''
$default_inc[0]
Truth table0%0/2
A
A= $default_inc[0]
| |||||||||||||||||||||||||||||||||
| 29 | 0 | shift @default_inc; | |||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||
| 31 | else { | ||||||||||||||||||||||||||||||||
| 32 | 0 | push @new_inc, $dir; | |||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | shift @default_inc while @default_inc and $seen{ $default_inc[0] }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@default_inc and $seen{$default_inc[0]}
MC/DC0%0/2
@default_inc and $seen{$default_inc[0]}
@default_inc
$seen{$default_inc[0]}
Truth table0%0/3
A and B
A= @default_incB= $seen{$default_inc[0]}
| |||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||
| 37 | 0 | return @new_inc; | |||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | # Cache this to avoid repeatedly shelling out to Perl. | ||||||||||||||||||||||||||||||||
| 41 | 7 | my @inc; | |||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub _default_inc { | ||||||||||||||||||||||||||||||
|
Subroutine
_default_inc: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | return @inc if @inc; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | 0 | local $ENV{PERL5LIB}; | |||||||||||||||||||||||||||||||
| 47 | 0 | local $ENV{PERLLIB}; | |||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | my $perl = $ENV{HARNESS_PERL} || $^X; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$ENV{'HARNESS_PERL'} || $^X
MC/DC0%0/2
$ENV{'HARNESS_PERL'} || $^X
$ENV{'HARNESS_PERL'}
$^X
Truth table0%0/3
A || B
A= $ENV{'HARNESS_PERL'}B= $^X
| |||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | # Avoid using -l for the benefit of Perl 6 | ||||||||||||||||||||||||||||||||
| 52 | 0 | chomp( @inc = `"$perl" -e "print join qq[\\n], \@INC, q[]"` ); | |||||||||||||||||||||||||||||||
| 53 | 0 | return @inc; | |||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | 5 | ▶ | sub create { | ||||||||||||||||||||||||||||||
|
Subroutine
create: called CC=22 SCAR=40.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 57 | 5 | my $package = shift; | |||||||||||||||||||||||||||||||
| 58 | 5 | ▶ | my %input = %{ shift || {} }; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || {}
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 5 | ▶ | my @libs = @{ delete $input{lib} || [] }; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
delete $input{'lib'} || []
MC/DC0%0/1
delete $input{'lib'} || []
delete $input{'lib'}
Truth table50%1/2
A
A= delete $input{'lib'}
| |||||||||||||||||||||||||||||||||
| 61 | 5 | ▶ | my @raw_switches = @{ delete $input{switches} || [] }; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
delete $input{'switches'} || []
MC/DC0%0/1
delete $input{'switches'} || []
delete $input{'switches'}
Truth table50%1/2
A
A= delete $input{'switches'}
| |||||||||||||||||||||||||||||||||
| 62 | my @opt | ||||||||||||||||||||||||||||||||
| 63 | 5 | ▶ | = ( @raw_switches, shellwords( $ENV{HARNESS_PERL_SWITCHES} || '' ) ); | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{'HARNESS_PERL_SWITCHES'} || ''
MC/DC0%0/1
$ENV{'HARNESS_PERL_SWITCHES'} || ''
$ENV{'HARNESS_PERL_SWITCHES'}
Truth table50%1/2
A
A= $ENV{'HARNESS_PERL_SWITCHES'}
| |||||||||||||||||||||||||||||||||
| 64 | 5 | my @switches; | |||||||||||||||||||||||||||||||
| 65 | 5 | ▶ | while ( my $opt = shift @opt ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 66 | 5 | ▶ | if ( $opt =~ /^ -I (.*) $ /x ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | push @libs, length($1) ? $1 : shift @opt; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||
| 69 | else { | ||||||||||||||||||||||||||||||||
| 70 | 5 | push @switches, $opt; | |||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | # Do things the old way on VMS... | ||||||||||||||||||||||||||||||||
| 75 | 5 | push @libs, _filtered_inc_vms() if IS_VMS; | |||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | # If $Verbose isn't numeric default to 1. This helps core. | ||||||||||||||||||||||||||||||||
| 78 | my $verbose | ||||||||||||||||||||||||||||||||
| 79 | = $ENV{HARNESS_VERBOSE} | ||||||||||||||||||||||||||||||||
| 80 | ? $ENV{HARNESS_VERBOSE} !~ /\d/ | ||||||||||||||||||||||||||||||||
| 81 | ? 1 | ||||||||||||||||||||||||||||||||
| 82 | : $ENV{HARNESS_VERBOSE} | ||||||||||||||||||||||||||||||||
| 83 | 5 | ▶ | : 0; | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | my %args = ( | ||||||||||||||||||||||||||||||||
| 86 | lib => \@libs, | ||||||||||||||||||||||||||||||||
| 87 | timer => $ENV{HARNESS_TIMER} || 0, | ||||||||||||||||||||||||||||||||
| 88 | switches => \@switches, | ||||||||||||||||||||||||||||||||
| 89 | color => $ENV{HARNESS_COLOR} || 0, | ||||||||||||||||||||||||||||||||
| 90 | verbosity => $verbose, | ||||||||||||||||||||||||||||||||
| 91 | 5 | ▶ | ignore_exit => $ENV{HARNESS_IGNORE_EXIT} || 0, | ||||||||||||||||||||||||||||||
|
Condition66%4/6
$ENV{'HARNESS_TIMER'} || 0
$ENV{'HARNESS_COLOR'} || 0
$ENV{'HARNESS_IGNORE_EXIT'} || 0
MC/DC100%1/1
$ENV{'HARNESS_TIMER'} || 0
$ENV{'HARNESS_TIMER'}
MC/DC0%0/1
$ENV{'HARNESS_COLOR'} || 0
$ENV{'HARNESS_COLOR'}
MC/DC0%0/1
$ENV{'HARNESS_IGNORE_EXIT'} || 0
$ENV{'HARNESS_IGNORE_EXIT'}
Truth table100%2/2
A
A= $ENV{'HARNESS_TIMER'}
Truth table50%1/2
A
A= $ENV{'HARNESS_COLOR'}
Truth table50%1/2
A
A= $ENV{'HARNESS_IGNORE_EXIT'}
| |||||||||||||||||||||||||||||||||
| 92 | ); | ||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | 5 | ▶ | my $class = delete $input{harness_class} || $ENV{HARNESS_SUBCLASS} || 'TAP::Harness'; | ||||||||||||||||||||||||||||||
|
Condition40%2/5
delete $input{'harness_class'} || $ENV{'HARNESS_SUBCLASS'} || 'TAP::Harness'
delete $input{"harness_class"} or $ENV{"HARNESS_SUBCLASS"}
MC/DC0%0/2
delete $input{'harness_class'} || $ENV{'HARNESS_SUBCLASS'} || 'TAP::Harness'
delete $input{"harness_class"}
$ENV{"HARNESS_SUBCLASS"}
Truth table33%1/3
A or B
A= delete $input{"harness_class"}B= $ENV{"HARNESS_SUBCLASS"}
| |||||||||||||||||||||||||||||||||
| 95 | 5 | ▶ | if ( defined( my $env_opt = $ENV{HARNESS_OPTIONS} ) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 96 | 5 | for my $opt ( split /:/, $env_opt ) { | |||||||||||||||||||||||||||||||
| 97 | 2 | ▶ | if ( $opt =~ /^j(\d*)$/ ) { | ||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||
| 98 | 1 | ▶ | $args{jobs} = $1 || 9; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$1 || 9
MC/DC0%0/1
$1 || 9
$1
Truth table50%1/2
A
A= $1
| |||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||
| 100 | elsif ( $opt eq 'c' ) { | ||||||||||||||||||||||||||||||||
| 101 | 1 | $args{color} = 1; | |||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||
| 103 | elsif ( $opt =~ m/^f(.*)$/ ) { | ||||||||||||||||||||||||||||||||
| 104 | 0 | my $fmt = $1; | |||||||||||||||||||||||||||||||
| 105 | 0 | $fmt =~ s/-/::/g; | |||||||||||||||||||||||||||||||
| 106 | 0 | $args{formatter_class} = $fmt; | |||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||
| 108 | elsif ( $opt =~ m/^a(.*)$/ ) { | ||||||||||||||||||||||||||||||||
| 109 | 0 | my $archive = $1; | |||||||||||||||||||||||||||||||
| 110 | 0 | $class = 'TAP::Harness::Archive'; | |||||||||||||||||||||||||||||||
| 111 | 0 | $args{archive} = $archive; | |||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||
| 113 | else { | ||||||||||||||||||||||||||||||||
| 114 | 0 | die "Unknown HARNESS_OPTIONS item: $opt\n"; | |||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||
| 118 | 5 | return TAP::Object->_construct($class, { %args, %input }); | |||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | 7 | 1; | |||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||
| 123 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||
| 125 | TAP::Harness::Env - Parsing harness related environmental variables where appropriate | ||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||
| 127 | =head1 VERSION | ||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | Version 3.52 | ||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||
| 131 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||
| 133 | my $harness = TAP::Harness::Env->create(\%extra_args) | ||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||
| 135 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||
| 137 | This module implements the environmental variables that L<Test::Harness> uses with TAP::Harness, and instantiates the appropriate class with the appropriate arguments. | ||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||
| 139 | =head1 METHODS | ||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||
| 141 | =over 4 | ||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||
| 143 | =item * create( \%args ) | ||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||
| 145 | This function reads the environment and generates an appropriate argument hash from it. If given any arguments in C<%extra_args>, these will override the environmental defaults. In accepts C<harness_class> (which defaults to C<TAP::Harness>), and any argument the harness class accepts. | ||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||
| 147 | =back | ||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||
| 149 | =head1 ENVIRONMENTAL VARIABLES | ||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||
| 151 | =over 4 | ||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||
| 153 | =item C<HARNESS_PERL_SWITCHES> | ||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||
| 155 | Setting this adds perl command line switches to each test file run. | ||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||
| 157 | For example, C<HARNESS_PERL_SWITCHES=-T> will turn on taint mode. | ||||||||||||||||||||||||||||||||
| 158 | C<HARNESS_PERL_SWITCHES=-MDevel::Cover> will run C<Devel::Cover> for | ||||||||||||||||||||||||||||||||
| 159 | each test. | ||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||
| 161 | =item C<HARNESS_VERBOSE> | ||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||
| 163 | If true, C<TAP::Harness> will output the verbose results of running | ||||||||||||||||||||||||||||||||
| 164 | its tests. | ||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||
| 166 | =item C<HARNESS_SUBCLASS> | ||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||
| 168 | Specifies a TAP::Harness subclass to be used in place of TAP::Harness. | ||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||
| 170 | =item C<HARNESS_OPTIONS> | ||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||
| 172 | Provide additional options to the harness. Currently supported options are: | ||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||
| 174 | =over | ||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||
| 176 | =item C<< j<n> >> | ||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||
| 178 | Run <n> (default 9) parallel jobs. | ||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||
| 180 | =item C<< c >> | ||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||
| 182 | Try to color output. See L<TAP::Formatter::Base/"new">. | ||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||
| 184 | =item C<< a<file.tgz> >> | ||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||
| 186 | Will use L<TAP::Harness::Archive> as the harness class, and save the TAP to | ||||||||||||||||||||||||||||||||
| 187 | C<file.tgz> | ||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||
| 189 | =item C<< fPackage-With-Dashes >> | ||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||
| 191 | Set the formatter_class of the harness being run. Since the C<HARNESS_OPTIONS> | ||||||||||||||||||||||||||||||||
| 192 | is separated by C<:>, we use C<-> instead. | ||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||
| 194 | =back | ||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||
| 196 | Multiple options may be separated by colons: | ||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||
| 198 | HARNESS_OPTIONS=j9:c make test | ||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||
| 200 | =item C<HARNESS_TIMER> | ||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||
| 202 | Setting this to true will make the harness display the number of | ||||||||||||||||||||||||||||||||
| 203 | milliseconds each test took. You can also use F<prove>'s C<--timer> | ||||||||||||||||||||||||||||||||
| 204 | switch. | ||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||
| 206 | =item C<HARNESS_COLOR> | ||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||
| 208 | Attempt to produce color output. | ||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||
| 210 | =item C<HARNESS_IGNORE_EXIT> | ||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||
| 212 | If set to a true value instruct C<TAP::Parser> to ignore exit and wait | ||||||||||||||||||||||||||||||||
| 213 | status from test scripts. | ||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||
| 215 | =back | ||||||||||||||||||||||||||||||||