3 var rimraf = require('rimraf')
4 var mkdirp = require('mkdirp')
5 var fixture = __dirname + '/fixture'
6 var which = require('../which.js')
7 var path = require('path')
9 var isWindows = process.platform === 'win32' ||
10 process.env.OSTYPE === 'cygwin' ||
11 process.env.OSTYPE === 'msys'
13 var skip = { skip: isWindows ? 'not relevant on windows' : false }
15 t.test('setup', function (t) {
18 fs.writeFileSync(fixture + '/foo.sh', 'echo foo\n')
22 t.test('does not find non-executable', skip, function (t) {
25 t.test('absolute', function (t) {
27 which(fixture + '/foo.sh', function (er) {
31 t.throws(function () {
32 which.sync(fixture + '/foo.sh')
36 t.test('with path', function (t) {
38 which('foo.sh', { path: fixture }, function (er) {
42 t.throws(function () {
43 which.sync('foo.sh', { path: fixture })
48 t.test('make executable', function (t) {
49 fs.chmodSync(fixture + '/foo.sh', '0755')
53 t.test('find when executable', function (t) {
55 var opt = { pathExt: '.sh' }
56 var expect = path.resolve(fixture, 'foo.sh').toLowerCase()
57 var PATH = process.env.PATH
59 t.test('absolute', function (t) {
60 runTest(fixture + '/foo.sh', t)
63 t.test('with process.env.PATH', function (t) {
64 process.env.PATH = fixture
68 t.test('with process.env.Path', {
69 skip: isWindows ? false : 'Only for Windows'
72 process.env.Path = fixture
76 t.test('with path opt', function (t) {
81 function runTest(exec, t) {
83 which(exec, opt, function (er, found) {
86 t.equal(found.toLowerCase(), expect)
87 process.env.PATH = PATH
90 var found = which.sync(exec, opt).toLowerCase()
91 t.equal(found, expect)
96 t.test('clean', function (t) {