|
| 1 | +import assert from "node:assert/strict"; |
| 2 | +import { mkdtempSync, writeFileSync } from "node:fs"; |
| 3 | +import { fileURLToPath } from "node:url"; |
| 4 | +import { tmpdir } from "node:os"; |
| 5 | +import { join } from "node:path"; |
| 6 | +import { spawnSync } from "node:child_process"; |
| 7 | +import test from "node:test"; |
| 8 | + |
| 9 | +const BIN = fileURLToPath(new URL("../bin/moshcode.mjs", import.meta.url)); |
| 10 | + |
| 11 | +function run(args) { |
| 12 | + return spawnSync(process.execPath, [BIN, "run", ...args], { |
| 13 | + encoding: "utf8", |
| 14 | + }); |
| 15 | +} |
| 16 | + |
| 17 | +test("run rejects unknown options before treating them as files", () => { |
| 18 | + const result = run(["--dryrun"]); |
| 19 | + |
| 20 | + assert.equal(result.status, 1); |
| 21 | + assert.match(result.stderr, /moshcode run: unknown option --dryrun/); |
| 22 | +}); |
| 23 | + |
| 24 | +test("run rejects multiple script files", () => { |
| 25 | + const dir = mkdtempSync(join(tmpdir(), "moshcode-run-")); |
| 26 | + const first = join(dir, "first.mosh"); |
| 27 | + const second = join(dir, "second.mosh"); |
| 28 | + writeFileSync(first, 'say("one");\n'); |
| 29 | + writeFileSync(second, 'say("two");\n'); |
| 30 | + |
| 31 | + const result = run([first, second, "--dry-run"]); |
| 32 | + |
| 33 | + assert.equal(result.status, 1); |
| 34 | + assert.match(result.stderr, /moshcode run: expected one script file/); |
| 35 | +}); |
0 commit comments