File: above.t

package info (click to toggle)
libur-perl 0.470%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,192 kB
  • sloc: perl: 61,814; javascript: 255; xml: 108; sh: 13; makefile: 9
file content (50 lines) | stat: -rw-r--r-- 1,300 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env perl

use strict;
use warnings;
use File::Temp;
use Test::More tests => 4;
use IO::File;

BEGIN {
    $ENV{'PERL_ABOVE_QUIET'} = 1 if $ENV{'HARNESS_ACTIVE'};
}

my $d = File::Temp::tempdir(CLEANUP => 1);
ok($d, "created working directory $d");

mkdir "$d/lib1" or die $!;
mkdir "$d/lib2" or die $!;
IO::File->new(">$d/lib1/Foo.pm")->print('package Foo; 1');
IO::File->new(">$d/lib2/Foo.pm")->print('package Foo; 1');
mkdir "$d/lib1/Foo";
mkdir "$d/lib2/Foo";
eval 'use lib "$d/lib1/"';

chdir "$d/lib2/Foo";
eval "use above 'Foo'";
is(&clean_darwin($INC{"Foo.pm"}), "$d/lib2/Foo.pm",
   "used the expected module");
chdir "$d/" or die "Failed to chdir to $d/: $!";
my $src = $^X . q| -e 'use above "Foo"; print $INC{"Foo.pm"}'|;
my $v = `$src`; 
is(&clean_darwin($v), "$d/lib2/Foo.pm",
   "Got the original module, not the 2nd one, and not an error."); 

chdir "$d/lib1" or die "Failed to chdir to $d/lib1: $!";
$v = `$src`;
is(&clean_darwin($v), "$d/lib2/Foo.pm",
   "Got the original module, not the 2nd one, and not an error.");

chdir "$d/..";  # So File::Temp can remove $d

exit(0);

# remove the /private from Mac OS X paths
sub clean_darwin {
    my ($path) = @_;
    $path =~ s#//#/#g;
    return $path unless $^O eq 'darwin';
    $path =~ s{^/private}{};
    return $path;
}