Files
scriptc/packages/compiler/test/process-builtin-values.test.ts
Chris Tate 3f66c8e20b Make LLVM the sole production backend
- Remove C emission, debugging options, and automatic backend fallback.
- Complete LLVM lowering and native bootstrap coverage across supported targets.
- Link executables and libraries with precompiled C runtime packs, including iOS and Android.
2026-09-29 20:54:09 -05:00

39 lines
2.0 KiB
TypeScript

import { spawnSync } from "node:child_process";
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { expect, test } from "vitest";
import { compile } from "../src/index.js";
test.each(["llvm"] as const)("native builtin values refuse unimplemented modules and exports (%s)", async (backend) => {
const dir = mkdtempSync("/tmp/scriptc-builtin-values-");
try {
const entry = join(dir, "main.js");
writeFileSync(entry, `
const load = process.getBuiltinModule;
try { load("node:fs"); } catch (error) { console.log(error.code, error.message.includes("native builtin 'fs'")); }
const path = load("path");
try { path.parse("/a"); } catch (error) { console.log(error.code, error.message.includes(".parse'")); }
const worker = load("worker_threads");
try { console.log(worker.Worker); } catch (error) { console.log(error.code, error.message.includes("worker_threads.Worker")); }
console.log(path.posix.join("still", "works"), worker.isMainThread);
var scope = globalThis;
try { console.log(scope.process); } catch (error) { console.log(error.code, error.message.includes("globalThis.process")); }
const segmenter = new Intl.Segmenter();
try { segmenter.resolvedOptions(); } catch (error) { console.log(error.message.includes("Intl.Segmenter locale negotiation")); }
try { console.log(segmenter.segment); } catch (error) { console.log(error.message.includes("not supported")); }
`);
const result = await compile(entry, {
backend, dynamic: false, sanitize: process.env["SCRIPTC_SAN"] === "1",
outDir: dir, outPath: join(dir, "program"),
});
expect(result.ok, JSON.stringify(result.diagnostics)).toBe(true);
if (!result.ok) return;
const child = spawnSync(result.binaryPath, [], { encoding: "utf8" });
expect(child.status, child.stderr).toBe(0);
expect(child.stderr).toBe("");
expect(child.stdout).toBe("SC2020 true\nSC2020 true\nSC2020 true\nstill/works true\nSC2020 true\ntrue\ntrue\n");
} finally {
rmSync(dir, { recursive: true, force: true });
}
});