mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-22 05:59:31 +08:00
- 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.
57 lines
1.9 KiB
TypeScript
57 lines
1.9 KiB
TypeScript
import { spawnSync } 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";
|
|
|
|
const root = join(import.meta.dirname, "../..");
|
|
const entry = join(root, "tests/fixtures/npm/cases/process-argv.mts");
|
|
const args = [
|
|
"",
|
|
"héllo",
|
|
"中文",
|
|
"🌍",
|
|
"a b",
|
|
'double"quote',
|
|
"end\\",
|
|
'slashes\\\\"quote',
|
|
"&;$(hello)`test'",
|
|
"line\nbreak",
|
|
"tab\targ",
|
|
];
|
|
|
|
for (const backend of ["llvm"] as const) {
|
|
test(`island process.argv preserves Unicode, quoting, empty values and identity (${backend})`, async () => {
|
|
const dir = mkdtempSync(
|
|
join(process.platform === "win32" ? tmpdir() : "/tmp", "scriptc-argv-island-"),
|
|
);
|
|
try {
|
|
const built = await compile(entry, {
|
|
backend,
|
|
dynamic: true,
|
|
sanitize: process.env["SCRIPTC_SAN"] === "1",
|
|
optimization: "dev",
|
|
outDir: dir,
|
|
outPath: join(dir, process.platform === "win32" ? "argv.exe" : "argv"),
|
|
});
|
|
if (!built.ok)
|
|
throw new Error(built.diagnostics.map((d) => `${d.code}: ${d.message}`).join("\n"));
|
|
const oracle = spawnSync(process.execPath, [entry, ...args], {
|
|
encoding: "utf8",
|
|
timeout: 10_000,
|
|
});
|
|
const native = spawnSync(built.binaryPath, args, { encoding: "utf8", timeout: 10_000 });
|
|
expect(oracle.error).toBeUndefined();
|
|
expect(oracle.status, oracle.stderr).toBe(0);
|
|
expect(oracle.stdout).toBe(`${JSON.stringify(args)}\ntrue\n追加\n`);
|
|
expect(native.error).toBeUndefined();
|
|
expect(native.status, native.stderr).toBe(oracle.status);
|
|
expect(native.stdout).toBe(oracle.stdout);
|
|
expect(native.stderr).toBe(oracle.stderr);
|
|
} finally {
|
|
rmSync(dir, { recursive: true, force: true });
|
|
}
|
|
});
|
|
}
|