Files
scriptc/tests/harness/opaque-class-view.test.ts
Chris Tate c08ab955ae Enforce linting and consistent source formatting
- Enforce oxlint and oxfmt for owned JavaScript and TypeScript with independent CI checks.
- Preserve compiler import boundaries and protected fixtures while cleaning up lint findings.
- Standardize source formatting and validate import, fixture, and embedded-source protections.
2026-10-05 17:51:24 -05:00

33 lines
1.2 KiB
TypeScript

import { execFileSync } from "node:child_process";
import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { compile } from "@scriptc/compiler";
import { expect, test } from "vitest";
for (const backend of ["llvm"] as const) {
test(`opaque class fields refuse dynamic views while preserving exact recovery (${backend})`, async () => {
const dir = mkdtempSync(
join(process.platform === "win32" ? tmpdir() : "/tmp", "scriptc-opaque-class-"),
);
try {
const result = await compile(
join(import.meta.dirname, "../fixtures/self-hosting/opaque-class-view.ts"),
{
backend,
dynamic: false,
sanitize: process.env["SCRIPTC_SAN"] === "1",
optimization: "dev",
outDir: dir,
outPath: join(dir, process.platform === "win32" ? "test.exe" : "test"),
},
);
if (!result.ok)
throw new Error(result.diagnostics.map((d) => `${d.code}: ${d.message}`).join("\n"));
expect(execFileSync(result.binaryPath, { encoding: "utf8", timeout: 10_000 })).toBe("10 0\n");
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
}