1#!/usr/bin/perl -w
2
3# Test that @INC is propogated from the harness process to the test
4# process.
5
6use strict;
7use warnings;
8use lib 't/lib';
9use Config;
10
11local
12  $ENV{PERL5OPT};   # avoid any user-provided PERL5OPT from contaminating @INC
13
14sub has_crazy_patch {
15    my $sentinel = 'blirpzoffle';
16    local $ENV{PERL5LIB} = $sentinel;
17    my $command = join ' ',
18      map {qq{"$_"}} ( $^X, '-e', 'print join q(:), @INC' );
19    my $path = `$command`;
20    my @got = ( $path =~ /($sentinel)/g );
21    return @got > 1;
22}
23
24use Test::More (
25      $^O eq 'VMS' ? ( skip_all => 'VMS' )
26    : has_crazy_patch() ? ( skip_all => 'Incompatible @INC patch' )
27    : exists $ENV{HARNESS_PERL_SWITCHES}
28    ? ( skip_all => 'Someone messed with HARNESS_PERL_SWITCHES' )
29    : ( tests => 2 )
30);
31
32use Test::Harness;
33
34# Change @INC so we ensure it's preserved.
35use lib 'wibble';
36
37my $test_template = <<'END';
38#!/usr/bin/perl %s
39
40use Test::More tests => 1;
41
42is $INC[0], "wibble", 'basic order of @INC preserved' or diag "\@INC: @INC";
43
44END
45
46open TEST, ">inc_check.t.tmp";
47printf TEST $test_template, '';
48close TEST;
49
50open TEST, ">inc_check_taint.t.tmp";
51printf TEST $test_template, '-T';
52close TEST;
53END { 1 while unlink 'inc_check_taint.t.tmp', 'inc_check.t.tmp'; }
54
55for my $test ( 'inc_check_taint.t.tmp', 'inc_check.t.tmp' ) {
56    my ( $tot, $failed ) = Test::Harness::execute_tests( tests => [$test] );
57    is $tot->{bad}, 0;
58}
591;
60