1 package TAP::Harness::Env;
6 use constant IS_VMS => ( $^O eq 'VMS' );
8 use Text::ParseWords qw/shellwords/;
10 our $VERSION = '3.36_01';
12 # Get the parts of @INC which are changed from the stock list AND
13 # preserve reordering of stock directories.
14 sub _filtered_inc_vms {
15 my @inc = grep { !ref } @INC; #28567
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 @inc = grep { !/perl_root/i } @inc;
21 my @default_inc = _default_inc();
26 next if $seen{$dir}++;
28 if ( $dir eq ( $default_inc[0] || '' ) ) {
35 shift @default_inc while @default_inc and $seen{ $default_inc[0] };
40 # Cache this to avoid repeatedly shelling out to Perl.
49 my $perl = $ENV{HARNESS_PERL} || $^X;
51 # Avoid using -l for the benefit of Perl 6
52 chomp( @inc = `"$perl" -e "print join qq[\\n], \@INC, q[]"` );
58 my %input = %{ shift || {} };
60 my @libs = @{ delete $input{libs} || [] };
61 my @raw_switches = @{ delete $input{switches} || [] };
63 = ( @raw_switches, shellwords( $ENV{HARNESS_PERL_SWITCHES} || '' ) );
65 while ( my $opt = shift @opt ) {
66 if ( $opt =~ /^ -I (.*) $ /x ) {
67 push @libs, length($1) ? $1 : shift @opt;
74 # Do things the old way on VMS...
75 push @libs, _filtered_inc_vms() if IS_VMS;
77 # If $Verbose isn't numeric default to 1. This helps core.
79 = $ENV{HARNESS_VERBOSE}
80 ? $ENV{HARNESS_VERBOSE} !~ /\d/
82 : $ENV{HARNESS_VERBOSE}
87 timer => $ENV{HARNESS_TIMER} || 0,
88 switches => \@switches,
89 color => $ENV{HARNESS_COLOR} || 0,
90 verbosity => $verbose,
91 ignore_exit => $ENV{HARNESS_IGNORE_EXIT} || 0,
94 my $class = delete $input{harness_class} || $ENV{HARNESS_SUBCLASS} || 'TAP::Harness';
95 if ( defined( my $env_opt = $ENV{HARNESS_OPTIONS} ) ) {
96 for my $opt ( split /:/, $env_opt ) {
97 if ( $opt =~ /^j(\d*)$/ ) {
98 $args{jobs} = $1 || 9;
100 elsif ( $opt eq 'c' ) {
103 elsif ( $opt =~ m/^f(.*)$/ ) {
106 $args{formatter_class} = $fmt;
108 elsif ( $opt =~ m/^a(.*)$/ ) {
110 $class = 'TAP::Harness::Archive';
111 $args{archive} = $archive;
114 die "Unknown HARNESS_OPTIONS item: $opt\n";
118 return TAP::Object->_construct($class, { %args, %input });
125 TAP::Harness::Env - Parsing harness related environmental variables where appropriate
133 my $harness = TAP::Harness::Env->create(\%extra_args)
137 This module implements the environmental variables that L<Test::Harness> uses with TAP::Harness, and instantiates the appropriate class with the appropriate arguments.
143 =item * create( \%args )
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.
149 =head1 ENVIRONMENTAL VARIABLES
153 =item C<HARNESS_PERL_SWITCHES>
155 Setting this adds perl command line switches to each test file run.
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
161 =item C<HARNESS_VERBOSE>
163 If true, C<TAP::Harness> will output the verbose results of running
166 =item C<HARNESS_SUBCLASS>
168 Specifies a TAP::Harness subclass to be used in place of TAP::Harness.
170 =item C<HARNESS_OPTIONS>
172 Provide additional options to the harness. Currently supported options are:
178 Run <n> (default 9) parallel jobs.
182 Try to color output. See L<TAP::Formatter::Base/"new">.
184 =item C<< a<file.tgz> >>
186 Will use L<TAP::Harness::Archive> as the harness class, and save the TAP to
189 =item C<< fPackage-With-Dashes >>
191 Set the formatter_class of the harness being run. Since the C<HARNESS_OPTIONS>
192 is seperated by C<:>, we use C<-> instead.
196 Multiple options may be separated by colons:
198 HARNESS_OPTIONS=j9:c make test
200 =item C<HARNESS_TIMER>
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>
206 =item C<HARNESS_COLOR>
208 Attempt to produce color output.
210 =item C<HARNESS_IGNORE_EXIT>
212 If set to a true value instruct C<TAP::Parser> to ignore exit and wait
213 status from test scripts.