Skip to content

Commit

Permalink
Handle ENOEXEC error for shell scripts on MacOS
Browse files Browse the repository at this point in the history
Signed-off-by: Timothy Johnson <[email protected]>
  • Loading branch information
t1m0thyj committed Nov 5, 2024
1 parent e3600e7 commit 2743305
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion __tests__/__packages__/cli-test-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All notable changes to the Zowe CLI test utils package will be documented in thi

## Recent Changes

- BugFix: Fixed an issue on MacOS where `runCliScript` method failed to run script that is missing shebang line. [#2314](https://github.com/zowe/zowe-cli/pull/2314)
- BugFix: Improved the error message shown on MacOS when `runCliScript` method fails to run script that is missing shebang line. [#2314](https://github.com/zowe/zowe-cli/pull/2314)

## `8.1.1`

Expand Down
10 changes: 7 additions & 3 deletions __tests__/__packages__/cli-test-utils/src/TestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/

import * as fs from "fs";
import * as path from "path";
import { spawnSync, SpawnSyncReturns, ExecFileException } from "child_process";
import { ITestEnvironment } from "./environment/doc/response/ITestEnvironment";
import { ICommandDefinition, IHandlerParameters } from "@zowe/imperative";
Expand Down Expand Up @@ -55,13 +56,16 @@ export function runCliScript(scriptPath: string, testEnvironment: ITestEnvironme
} catch {
fs.chmodSync(scriptPath, "755");
}
return spawnSync(scriptPath, args, {
const response = spawnSync(scriptPath, args, {
cwd: testEnvironment.workingDir,
env: childEnv,
encoding: "buffer",
shell: true // Don't require shebangs on MacOS
encoding: "buffer"
});
if (process.platform === "darwin" && (response.error as ExecFileException)?.errno === -8) {
throw new Error(`The script file ${path.basename(scriptPath)} failed to execute. Check that it starts with a shebang line.`);
}

return response;
} else {
throw new Error(`The script file ${scriptPath} doesn't exist`);

Expand Down

0 comments on commit 2743305

Please sign in to comment.