-
Notifications
You must be signed in to change notification settings - Fork 8
/
03-mpath.t
111 lines (90 loc) · 3.6 KB
/
03-mpath.t
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!perl
use strict;
use warnings;
use Test::More 0.88;
use FindBin 0.05;
use File::Spec::Functions;
use Devel::FindPerl qw(find_perl_interpreter);
use Cwd qw/ abs_path /;
use File::Temp qw{ tempfile tempdir };
use File::Spec;
my $PERL = find_perl_interpreter() || die "can't find perl!\n";
my $MPATH = catfile( $FindBin::Bin, updir(), qw(bin mpath) );
my $path;
my $expected_path;
#
# The mpath script's hashbang line is:
#
# #!/usr/bin/env perl
#
# This can result in it being run with a different perl than being used to run
# this test. So the path to strict may be different. So we use $^X to run
# mpath with the same perl binary being used to run this test.
# Instead of explicitly using $^X, we use Devel::FindPerl to get the
# path to perl
#
chomp($path = `"$PERL" "$MPATH" strict 2>&1`);
# This test does "use strict", so %INC should include the path where
# strict.pm was found, and module_path should find the same
$expected_path = abs_path($INC{'strict.pm'});
ok($? == 0 && defined($path) && $path eq $expected_path,
"check 'mpath strict' matches \%INC") || do {
warn "\n",
" \%INC : $INC{'strict.pm'}\n",
" expected_path : $expected_path\n",
" module_path : $path\n",
" \$^O : $^O\n";
};
# module_path() returns undef if module not found in @INC
chomp($path = `"$PERL" "$MPATH" No::Such::Module 2>&1`);
ok($? != 0 && defined($path) && $path eq 'No::Such::Module not found',
"non-existent module should result in failure");
chomp($path = `"$PERL" "$MPATH" strict warnings 2>&1`);
ok($? == 0, 'exit status is 0');
ok(defined($path), 'path for both strict.pm and warnings.pm are defined');
is($path, abs_path($INC{'strict.pm'}).$/.abs_path($INC{'warnings.pm'}), 'and they match %INC');
chomp($path = `"$PERL" "$MPATH" strict warnings No::Such::Module 2>&1`);
ok($? != 0, 'exit status is not zero');
ok(defined($path), 'path is defined');
is(
$path,
abs_path($INC{'strict.pm'}).$/.abs_path($INC{'warnings.pm'})."$/No::Such::Module not found",
'got expected output'
);
chomp($path = `"$PERL" "$MPATH" --quiet strict warnings No::Such::Module 2>&1`);
ok($? != 0, 'exit status is not zero');
ok(defined($path), 'path is defined');
is(
$path,
abs_path($INC{'strict.pm'}).$/.abs_path($INC{'warnings.pm'}),
"error message should not be printed when the option --quiet is specified"
);
chomp($path = `"$PERL" "$MPATH" --full strict warnings 2>&1`);
ok($? == 0, 'exit status is zero');
ok(defined($path), 'path is defined');
is(
$path,
"strict ".abs_path($INC{'strict.pm'})."$/warnings ".abs_path($INC{'warnings.pm'}),
"module name should be printed right before its path if the option --full is specified"
);
{
my $temp_dir = tempdir( CLEANUP => 1 );
my ( $fh, $filename ) = tempfile( DIR => $temp_dir, SUFFIX => '.pm' );
my $module_name = ( File::Spec->splitpath($filename) )[-1];
$module_name =~ s/\.pm$//;
my $INC_PATH = catfile( $FindBin::Bin, updir(), 'lib' );
my $command =
"$PERL -I$INC_PATH $MPATH --dirs='$temp_dir' $module_name 2>&1";
chomp( $path = qx{$command} );
ok( $? == 0, 'exit status is zero' );
ok( defined($path), 'path is defined' );
is( $path, $filename, "--dirs option returns expected path" );
$command = "$PERL -I$INC_PATH $MPATH "
. "--dirs='$temp_dir,\'another/path\'' $module_name 2>&1";
chomp( $path = qx{$command} );
ok( $? == 0, 'exit status is zero' );
ok( defined($path), 'path is defined' );
is( $path, $filename,
"--dirs option returns expected path with multiple input dirs" );
}
done_testing;