xref: /openbsd-src/gnu/usr.bin/perl/cpan/Test-Harness/t/perl5lib.t (revision 6fb12b7054efc6b436584db6cef9c2f85c0d7e27)
1b39c5158Smillert#!/usr/bin/perl -w
2b39c5158Smillert
3b39c5158Smillert# Test that PERL5LIB is propogated from the harness process to the test
4b39c5158Smillert# process.
5b39c5158Smillert
6b39c5158Smillertuse strict;
7*6fb12b70Safresh1use warnings;
8b39c5158Smillertuse lib 't/lib';
9b39c5158Smillertuse Config;
10b39c5158Smillert
11b39c5158Smillertmy $path_sep = $Config{path_sep};
12b39c5158Smillert
13b39c5158Smillertsub has_crazy_patch {
14b39c5158Smillert    my $sentinel = 'blirpzoffle';
15b39c5158Smillert    local $ENV{PERL5LIB} = $sentinel;
16b39c5158Smillert    my $command = join ' ',
17b39c5158Smillert      map {qq{"$_"}} ( $^X, '-e', 'print join q(:), @INC' );
18b39c5158Smillert    my $path = `$command`;
19b39c5158Smillert    my @got = ( $path =~ /($sentinel)/g );
20b39c5158Smillert    return @got > 1;
21b39c5158Smillert}
22b39c5158Smillert
23b39c5158Smillertuse Test::More (
24b39c5158Smillert      $^O eq 'VMS' ? ( skip_all => 'VMS' )
25b39c5158Smillert    : has_crazy_patch() ? ( skip_all => 'Incompatible @INC patch' )
26b39c5158Smillert    : ( tests => 1 )
27b39c5158Smillert);
28b39c5158Smillert
29b39c5158Smillertuse Test::Harness;
30b39c5158Smillertuse App::Prove;
31b39c5158Smillert
32b39c5158Smillert# Change PERL5LIB so we ensure it's preserved.
33b39c5158Smillert$ENV{PERL5LIB} = join(
34b39c5158Smillert    $path_sep, 'wibble',
35898184e3Ssthen    $ENV{PERL5LIB} || ''
36b39c5158Smillert);
37b39c5158Smillert
38b39c5158Smillertopen TEST, ">perl5lib_check.t.tmp";
39b39c5158Smillertprint TEST <<"END";
40b39c5158Smillert#!/usr/bin/perl
41b39c5158Smillertuse strict;
42b39c5158Smillertuse Test::More tests => 1;
43b39c5158Smillertlike \$ENV{PERL5LIB}, qr/(^|${path_sep})wibble${path_sep}/;
44b39c5158SmillertEND
45b39c5158Smillertclose TEST;
46b39c5158Smillert
47b39c5158SmillertEND { 1 while unlink 'perl5lib_check.t.tmp'; }
48b39c5158Smillert
49b39c5158Smillertmy $h = TAP::Harness->new( { lib => ['something'], verbosity => -3 } );
50b39c5158Smillertok( !$h->runtests('perl5lib_check.t.tmp')->has_errors );
51b39c5158Smillert
52b39c5158Smillert1;
53