3 var path = require('path')
4 var fixture = path.resolve(__dirname, 'fixtures')
5 var meow = fixture + '/meow.cat'
6 var mine = fixture + '/mine.cat'
7 var ours = fixture + '/ours.cat'
8 var fail = fixture + '/fail.false'
9 var noent = fixture + '/enoent.exe'
10 var mkdirp = require('mkdirp')
11 var rimraf = require('rimraf')
13 var isWindows = process.platform === 'win32'
14 var hasAccess = typeof fs.access === 'function'
15 var winSkip = isWindows && 'windows'
16 var accessSkip = !hasAccess && 'no fs.access function'
17 var hasPromise = typeof Promise === 'function'
18 var promiseSkip = !hasPromise && 'no global Promise'
21 delete require.cache[require.resolve('../')]
25 t.test('setup fixtures', function (t) {
28 fs.writeFileSync(meow, '#!/usr/bin/env cat\nmeow\n')
29 fs.chmodSync(meow, parseInt('0755', 8))
30 fs.writeFileSync(fail, '#!/usr/bin/env false\n')
31 fs.chmodSync(fail, parseInt('0644', 8))
32 fs.writeFileSync(mine, '#!/usr/bin/env cat\nmine\n')
33 fs.chmodSync(mine, parseInt('0744', 8))
34 fs.writeFileSync(ours, '#!/usr/bin/env cat\nours\n')
35 fs.chmodSync(ours, parseInt('0754', 8))
39 t.test('promise', { skip: promiseSkip }, function (t) {
41 t.test('meow async', function (t) {
42 isexe(meow).then(function (is) {
47 t.test('fail async', function (t) {
48 isexe(fail).then(function (is) {
53 t.test('noent async', function (t) {
54 isexe(noent).catch(function (er) {
59 t.test('noent ignore async', function (t) {
60 isexe(noent, { ignoreErrors: true }).then(function (is) {
68 t.test('no promise', function (t) {
71 t.throws('try to meow a promise', function () {
77 t.test('access', { skip: accessSkip || winSkip }, function (t) {
81 t.test('mode', { skip: winSkip }, function (t) {
85 t.ok(isexe.sync(ours, { uid: 0, gid: 0 }))
86 t.ok(isexe.sync(mine, { uid: 0, gid: 0 }))
90 t.test('windows', function (t) {
91 global.TESTING_WINDOWS = true
92 var pathExt = '.EXE;.CAT;.CMD;.COM'
93 t.test('pathExt option', function (t) {
94 runTest(t, { pathExt: '.EXE;.CAT;.CMD;.COM' })
96 t.test('pathExt env', function (t) {
97 process.env.PATHEXT = pathExt
100 t.test('no pathExt', function (t) {
101 // with a pathExt of '', any filename is fine.
102 // so the "fail" one would still pass.
103 runTest(t, { pathExt: '', skipFail: true })
105 t.test('pathext with empty entry', function (t) {
106 // with a pathExt of '', any filename is fine.
107 // so the "fail" one would still pass.
108 runTest(t, { pathExt: ';' + pathExt, skipFail: true })
113 t.test('cleanup', function (t) {
118 function runTest (t, options) {
121 var optionsIgnore = Object.create(options || {})
122 optionsIgnore.ignoreErrors = true
124 if (!options || !options.skipFail) {
125 t.notOk(isexe.sync(fail, options))
127 t.notOk(isexe.sync(noent, optionsIgnore))
129 t.ok(isexe.sync(meow))
131 t.ok(isexe.sync(meow, options))
134 t.ok(isexe.sync(mine, options))
135 t.ok(isexe.sync(ours, options))
136 t.throws(function () {
137 isexe.sync(noent, options)
140 t.test('meow async', function (t) {
142 isexe(meow, function (er, is) {
150 isexe(meow, options, function (er, is) {
160 t.test('mine async', function (t) {
161 isexe(mine, options, function (er, is) {
170 t.test('ours async', function (t) {
171 isexe(ours, options, function (er, is) {
180 if (!options || !options.skipFail) {
181 t.test('fail async', function (t) {
182 isexe(fail, options, function (er, is) {
192 t.test('noent async', function (t) {
193 isexe(noent, options, function (er, is) {
200 t.test('noent ignore async', function (t) {
201 isexe(noent, optionsIgnore, function (er, is) {