import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import { afterEach, beforeEach, describe, expect, it } from "vitest"; import { captureEnv } from "../test-utils/env.js"; import {
detectRuntimeShell,
getShellConfig,
resolvePowerShellPath,
resolveShellFromPath,
} from "./shell-utils.js";
it("prefers bash when fish is default and bash is on PATH", () => { const binDir = createTempCommandDir(tempDirs, [{ name: "bash" }]);
process.env.PATH = binDir; const { shell } = getShellConfig();
expect(shell).toBe(path.join(binDir, "bash"));
});
it("falls back to sh when fish is default and bash is missing", () => { const binDir = createTempCommandDir(tempDirs, [{ name: "sh" }]);
process.env.PATH = binDir; const { shell } = getShellConfig();
expect(shell).toBe(path.join(binDir, "sh"));
});
it("falls back to env shell when fish is default and no sh is available", () => {
process.env.PATH = ""; const { shell } = getShellConfig();
expect(shell).toBe("/usr/bin/fish");
});
it("uses sh when SHELL is unset", () => { delete process.env.SHELL;
process.env.PATH = ""; const { shell } = getShellConfig();
expect(shell).toBe("sh");
});
it("falls back to sh on PATH when SHELL is /usr/bin/false", () => { const binDir = createTempCommandDir(tempDirs, [{ name: "sh" }]);
process.env.SHELL = "/usr/bin/false";
process.env.PATH = binDir; const { shell, args } = getShellConfig();
expect(shell).toBe(path.join(binDir, "sh"));
expect(args).toEqual(["-c"]);
});
it("falls back to sh on PATH when SHELL is /sbin/nologin", () => { const binDir = createTempCommandDir(tempDirs, [{ name: "sh" }]);
process.env.SHELL = "/sbin/nologin";
process.env.PATH = binDir; const { shell } = getShellConfig();
expect(shell).toBe(path.join(binDir, "sh"));
});
it("falls back to bare sh when SHELL is a placeholder and no sh is on PATH", () => {
process.env.SHELL = "/usr/bin/false";
process.env.PATH = ""; const { shell } = getShellConfig();
expect(shell).toBe("sh");
});
});
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.