-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide explicit
$PATH
value to which (#1142)
Update the implementation of `resolveExecutable` to accept the environment variables so that they can explicitly be provided to which [1]. All internal code and tests have been updated accordingly, no external changes. This is in an effort to fix a problem where environment variables aren't always passed on correctly to subprocesses. The problem is described in [2], though if Shescape is used in a forked process on Windows it would face the same problem. (As a problem found through the test runner, use of which [1] in tests has been updated similarly. As a result of this change, the integration and e2e test on Windows are quite a bit slower (because now they actually look up the executable). Hence, both of these suites have been updated to use separated test files in order to better leverage AVA's concurrency - speeding up individual files and avoiding timeouts as well as running tests quicker if cores are available. This change also allowed for including executables without a file extension in the integration and e2e tests, further improving coverage. (This replaced the `.EXE` coverage as extensionless executables are resolved to `.EXE`, thus reducing test count without reducing coverage.) As a side note, it was funny to see that `getShellName` name unit tests for both Unix and Windows already generated and provided environment variables (: -- 1. https://www.npmjs.com/package/which 2. avajs/ava#3014
- Loading branch information
1 parent
0d65610
commit 0b976da
Showing
68 changed files
with
1,174 additions
and
302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* @overview Provides common utilities for end-to-end tests. | ||
* @license MIT | ||
*/ | ||
|
||
import process from "node:process"; | ||
|
||
import test from "ava"; | ||
import isCI from "is-ci"; | ||
import which from "which"; | ||
|
||
import { injectionStrings } from "../../testing.js"; | ||
import * as constants from "../_constants.cjs"; | ||
|
||
/** | ||
* Get a list of strings to use as arguments in end-to-end tests. | ||
* | ||
* @returns {string[]} A list of test arguments. | ||
*/ | ||
export function getTestArgs() { | ||
return ["harmless", ...injectionStrings]; | ||
} | ||
|
||
/** | ||
* Get the AVA test function to use for the given shell. | ||
* | ||
* @param {string} shell The shell to run a test for. | ||
* @returns {Function} An AVA `test` function. | ||
*/ | ||
export function getTestFn(shell) { | ||
try { | ||
if (!isCI && typeof shell === "string") { | ||
which.sync(shell, { path: process.env.PATH || process.env.Path }); | ||
} | ||
|
||
return test; | ||
} catch (_) { | ||
return test.skip; | ||
} | ||
} | ||
|
||
/** | ||
* Get a list of `shell` option values to use in end-to-end tests. | ||
* | ||
* @returns {(boolean | string)[]} A list of `shell` option values. | ||
*/ | ||
export function getTestShells() { | ||
const systemShells = constants.isWindows | ||
? constants.shellsWindows | ||
: constants.shellsUnix; | ||
|
||
return [false, true, ...systemShells]; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* @overview Contains end-to-end tests of using Shescape with the child_process | ||
* package's `execFile` (and `execFileSync`) functions. | ||
* @license MIT | ||
*/ | ||
|
||
import { common, macros } from "./_.js"; | ||
|
||
for (const shell of common.getTestShells()) { | ||
const test = common.getTestFn(shell); | ||
for (const arg of common.getTestArgs()) { | ||
test(macros.execFile, { arg, shell }); | ||
test(macros.execFileSync, { arg, shell }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* @overview Contains end-to-end tests of using Shescape with the child_process | ||
* package's `exec` (and `execSync`) functions. | ||
* @license MIT | ||
*/ | ||
|
||
import { common, macros } from "./_.js"; | ||
|
||
for (const shell of common.getTestShells()) { | ||
const test = common.getTestFn(shell); | ||
for (const arg of common.getTestArgs()) { | ||
test(macros.exec, { arg, shell }); | ||
test(macros.execSync, { arg, shell }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* @overview Contains end-to-end tests of using Shescape with the child_process | ||
* package's `fork` functions. | ||
* @license MIT | ||
*/ | ||
|
||
import { common, macros } from "./_.js"; | ||
|
||
for (const arg of common.getTestArgs()) { | ||
const test = common.getTestFn(null); | ||
test(macros.fork, { arg }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* @overview Contains end-to-end tests of using Shescape with the child_process | ||
* package's `spawn` (and `spawnSync`) functions. | ||
* @license MIT | ||
*/ | ||
|
||
import { common, macros } from "./_.js"; | ||
|
||
for (const shell of common.getTestShells()) { | ||
const test = common.getTestFn(shell); | ||
for (const arg of common.getTestArgs()) { | ||
test(macros.spawn, { arg, shell }); | ||
test(macros.spawnSync, { arg, shell }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* @overview Contains integration tests for `shescape.escapeAll` for the | ||
* Bourne-again shell (Bash). | ||
* @license MIT | ||
*/ | ||
|
||
import test from "ava"; | ||
|
||
import { constants, generate } from "../_.js"; | ||
|
||
import { escapeAll } from "shescape"; | ||
|
||
const runTest = constants.isWindows ? test.skip : test; | ||
|
||
runTest(`input is escaped for ${constants.binBash}`, (t) => { | ||
for (const scenario of generate.escapeExamples(constants.binBash)) { | ||
const { expected, input, options } = scenario; | ||
const result = escapeAll([input], options); | ||
t.deepEqual(result, [expected]); | ||
} | ||
}); |
Oops, something went wrong.