shelljs/test/which.js
Isiah Meadows eaa771033e Search PATHEXT for which, do a lowercase comparison on Windows
Redo of #134

`which` now searches through PATHEXT on Windows, and it also now does a
case-insensitive comparison. This better fits the Windows environment, where
the OS usually ignores case.
2016-01-29 13:34:20 -05:00

40 lines
762 B
JavaScript

var shell = require('..');
var assert = require('assert'),
fs = require('fs');
shell.config.silent = true;
shell.rm('-rf', 'tmp');
shell.mkdir('tmp');
//
// Invalids
//
shell.which();
assert.ok(shell.error());
var result = shell.which('asdfasdfasdfasdfasdf'); // what are the odds...
assert.ok(!shell.error());
assert.ok(!result);
//
// Valids
//
var node = shell.which('node');
assert.ok(!shell.error());
assert.ok(fs.existsSync(node));
if (process.platform === 'win32') {
// This should be equivalent on Windows
var nodeExe = shell.which('node.exe');
assert.ok(!shell.error());
// If the paths are equal, then this file *should* exist, since that's
// already been checked.
assert.equal(node, nodeExe);
}
shell.exit(123);