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
|
use strict;
use warnings;
use Test::More tests => 10;
use File::Spec ();
use File::Which qw{which where};
use constant IS_VMS => ($^O eq 'VMS');
use constant IS_MAC => ($^O eq 'MacOS');
use constant IS_DOS => ($^O eq 'MSWin32' or $^O eq 'dos' or $^O eq 'os2');
use constant IS_CYGWIN => ($^O eq 'cygwin');
# Check that it returns undef if no file is passed
is(
scalar(which('')), undef,
'Null-length false result',
);
is(
scalar(which('non_existent_very_unlinkely_thingy_executable')), undef,
'Positive length false result',
);
# Where is the test application
my $test_bin = File::Spec->catdir( 't', 'test-bin' );
ok( -d $test_bin, 'Found test-bin' );
# Set up for running the test application
local $ENV{PATH} = $test_bin;
unless (
File::Which::IS_VMS
or
File::Which::IS_MAC
or
File::Which::IS_DOS
) {
my $test3 = File::Spec->catfile( $test_bin, 'test3' );
chmod 0755, $test3;
}
SKIP: {
skip("Not on DOS-like filesystem", 3) unless IS_DOS;
is( lc scalar which('test1'), 't\test-bin\test1.exe', 'Looking for test1.exe' );
is( lc scalar which('test2'), 't\test-bin\test2.bat', 'Looking for test2.bat' );
is( scalar which('test3'), undef, 'test3 returns undef' );
}
SKIP: {
skip("Not on a UNIX filesystem", 1) if IS_DOS;
skip("Not on a UNIX filesystem", 1) if IS_MAC;
skip("Not on a UNIX filesystem", 1) if IS_VMS;
is(
scalar(which('test3')),
File::Spec->catfile( $test_bin, 'test3'),
'Check test3 for Unix',
);
}
SKIP: {
skip("Not on a cygwin filesystem", 2) unless IS_CYGWIN;
# Cygwin: should make test1.exe transparent
is(
scalar(which('test1')),
File::Spec->catfile( $test_bin, 'test1' ),
'Looking for test1 on Cygwin: transparent to test1.exe',
);
is(
scalar(which('test4')),
undef,
'Make sure that which() doesn\'t return a directory',
);
}
# Make sure that .\ stuff works on DOSish, VMS, MacOS (. is in PATH implicitly).
SKIP: {
unless ( IS_DOS or IS_VMS ) {
skip("Not on a DOS or VMS filesystem", 1);
}
chdir( $test_bin );
is(
lc scalar which('test1'),
File::Spec->catfile(File::Spec->curdir(), 'test1.exe'),
'Looking for test1.exe in curdir',
);
}
|