develooper Front page | perl.perl5.porters | Postings from May 2003

Re: [perl #22209] Test::Harness::Straps vs. $Config{path_sep}

Thread Previous | Thread Next
From:
Michael G Schwern
Date:
May 15, 2003 15:23
Subject:
Re: [perl #22209] Test::Harness::Straps vs. $Config{path_sep}
Message ID:
20030515222254.GB24598@windhund.schwern.org
On Thu, May 15, 2003 at 02:42:55PM -0000, Mike Stok wrote:
> Test::Harness::Straps uses
> 
>    local $ENV{PERL5LIB} = $self->_INC2PERL5LIB;
> 
> to set up te environment for the test scripts.  Once something containing 
> $Config{path_sep} has been wedged into a string using  $Config{path_sep} as
> a separator it will become multiple elements of @INC in the test scripts,
> and will not do what is expected.

This behavior is not new, the older Test::harness did it this way as well,
it just didn't put it in a function where you can easily find it. :)

    my $new5lib;
    if ($^O eq 'VMS') {
        $new5lib = join($Config{path_sep}, grep {!/perl_root/i;} @INC);
        $switches =~ s/-(\S*[A-Z]\S*)/"-$1"/g;
    }
    else {
        $new5lib = join($Config{path_sep}, @INC);
    }

    local($ENV{'PERL5LIB'}) = $new5lib;

The difference is not Test::Harness but MakeMaker.  Older versions would
put ./blib/lib and ./blib/arch on @INC.  This caused a problem if your
test did something like:

    chdir 't/foo';
    require My::Module;

My::Module would not be found if it was in blib/lib because of the relative
directory on @INC.  The new MakeMaker uses an absolute path, which now
includes your /tmp/A:B/.

As I can't think of any way to fix this without breaking other more important
things, I guess the below makes some sense though it may want to warn
instead and only talk about the specificly offending directories.

--- lib/Test/Harness/Straps.pm	2 Feb 2003 05:27:44 -0000	1.16
+++ lib/Test/Harness/Straps.pm	15 May 2003 22:22:23 -0000
@@ -358,7 +358,13 @@
 
     $self->{_old5lib} = $ENV{PERL5LIB};
 
-    return join $Config{path_sep}, $self->_filtered_INC;
+    my @filtered_inc = $self->_filtered_INC;
+    my @clean_inc   = grep !/\Q$Config{path_sep}/, @filtered_inc;
+    my @naughty_inc = grep /\Q$Config{path_sep}/, @filtered_inc;
+    warn "Test::Harness can't handle \@INC directories with ".
+         "'$Config{path_sep}': @naughty_inc\n" if @naughty_inc;
+
+    return join $Config{path_sep}, @clean_inc;
 }
 
 =item B<_filtered_INC>



> Should there at least be a warning issued by Test::Harness::Straps if
> we're about to do encounter this behaviour?  Something like
> 
> --- Straps.pm.dist	2003-05-12 09:22:18.000000000 -0400
> +++ Straps.pm	2003-05-15 09:58:16.000000000 -0400
> @@ -356,7 +356,11 @@
>  
>      $self->{_old5lib} = $ENV{PERL5LIB};
>  
> -    return join $Config{path_sep}, $self->_filtered_INC;
> +    my @new =  $self->_filtered_INC;
> +    die "$0: Directory shouldn't contain '$Config{path_sep}' (@new)\n"
> +        if grep /\Q$Config{path_sep}/, @new;
> +
> +    return join $Config{path_sep}, @new;
>  }

-- 
Do not try comedy at home!  Milk & Cheese are advanced experts!  Attempts at
comedy can be dangerously unfunny!

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About