import { assertEquals, assertMatch } from "@std/assert"; import { join } from "@std/path"; import { denoExecutable } from "./deno.ts"; import { tempDir } from "@berry/util"; Deno.test({ name: "subprocesses use the installed Deno before and after an atomic update", ignore: Deno.build.os !== "linux", async fn() { await using directoryDir = await tempDir({ prefix: "berry-deno-test-" }); const directory = directoryDir.path; const executable = join(directory, "deno"); const replacement = join(directory, "replacement"); await Deno.copyFile(denoExecutable(), executable); await Deno.chmod(executable, 0o755); await Deno.writeTextFile(replacement, "#!/bin/sh\nprintf 'updated deno\\n'\n"); await Deno.chmod(replacement, 0o755); const { success, stdout, stderr } = await new Deno.Command(executable, { args: [ "eval", `import { denoExecutable } from ${ JSON.stringify(new URL("./deno.ts", import.meta.url).href) }; const before = await new Deno.Command(denoExecutable(), { args: ["--version"] }).output(); await Deno.rename(${JSON.stringify(replacement)}, ${JSON.stringify(executable)}); const after = await new Deno.Command(denoExecutable(), { args: ["--version"] }).output(); console.log(JSON.stringify({ before: new TextDecoder().decode(before.stdout), after: new TextDecoder().decode(after.stdout), success: before.success && after.success, }));`, ], stdout: "piped", stderr: "piped", }).output(); assertEquals(success, true, new TextDecoder().decode(stderr)); const result = JSON.parse(new TextDecoder().decode(stdout)); assertEquals(result.success, true); assertMatch(result.before, /^deno /); assertEquals(result.after, "updated deno\n"); }, });