-
Notifications
You must be signed in to change notification settings - Fork 740
Fix(which): match only executable files (#657) #874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
79b8feb
644e632
9157b53
ce70542
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
text file, not an executable |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
import test from 'ava'; | ||
|
||
|
@@ -69,5 +70,25 @@ test('Searching with -a flag returns an array with first item equals to the regu | |
t.falsy(shell.error()); | ||
t.truthy(resultForWhich); | ||
t.truthy(resultForWhichA); | ||
t.is(resultForWhich.toString(), resultForWhichA[0].toString()); | ||
t.is(resultForWhich.toString(), resultForWhichA[0]); | ||
}); | ||
|
||
test('None executable files does not appear in the result list', t => { | ||
const commandName = 'node'; // Should be an existing command | ||
const pathEnv = process.env.path || process.env.Path || process.env.PATH; | ||
const extraPath = path.resolve(__dirname, 'resources', 'which'); | ||
const matchingFile = path.resolve(extraPath, commandName); | ||
|
||
// make sure that file is exists (will throw error otherwise) | ||
fs.statSync(matchingFile); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: can you make this |
||
|
||
process.env.path = process.env.Path = process.env.PATH = extraPath + path.delimiter + pathEnv; | ||
const resultForWhich = shell.which(commandName); | ||
const resultForWhichA = shell.which('-a', commandName); | ||
t.falsy(shell.error()); | ||
t.truthy(resultForWhich); | ||
t.truthy(resultForWhichA); | ||
t.truthy(resultForWhichA.length); | ||
t.not(resultForWhich.toString(), matchingFile); | ||
t.not(resultForWhichA[0], matchingFile); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you rewrite this as: t.falsy(resultForWhichA.includes(matchingFile)); Also, I think it makes sense to skip this test on Windows, or to assert the array does contain the value on Windows. WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I thought t.is(resultForWhichA.indexOf(matchingFile), -1); That way we have the correct semantics for the assertion. |
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look right. This should be
process.env.PATH
.Only all-caps
$PATH
works on unix. On Windows,process.env.path
is totally the same asprocess.env.PATH
(and all variations of capitalization of "path").