|
1 | 1 | import assert from "node:assert/strict"; |
2 | | -import { spawn } from "node:child_process"; |
| 2 | +import { spawn, spawnSync } from "node:child_process"; |
| 3 | +import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs"; |
| 4 | +import { tmpdir } from "node:os"; |
| 5 | +import { join } from "node:path"; |
3 | 6 | import test from "node:test"; |
4 | 7 | import { fileURLToPath } from "node:url"; |
5 | 8 |
|
@@ -55,3 +58,25 @@ test("TUI /run rejects unknown options before reading a script file", async () = |
55 | 58 | assert.match(result.stdout, /unknown option --dryrun/); |
56 | 59 | assert.doesNotMatch(result.stdout, /can't read --dryrun/); |
57 | 60 | }); |
| 61 | + |
| 62 | +test("TUI /run passes positional args through to moshscript argv", () => { |
| 63 | + const dir = mkdtempSync(join(tmpdir(), "moshcode-tui-")); |
| 64 | + mkdirSync(join(dir, "space dir")); |
| 65 | + const script = join(dir, "space dir", "argv.mosh"); |
| 66 | + writeFileSync(script, 'say(argv[0]); say(argv[1]);\n'); |
| 67 | + const scriptArg = script.replaceAll("\\", "/"); |
| 68 | + |
| 69 | + const result = spawnSync( |
| 70 | + process.execPath, |
| 71 | + ["bin/moshcode.mjs"], |
| 72 | + { |
| 73 | + cwd: join(import.meta.dirname, ".."), |
| 74 | + input: `/run "${scriptArg}" alpha "two words"\n/quit\n`, |
| 75 | + encoding: "utf8", |
| 76 | + }, |
| 77 | + ); |
| 78 | + |
| 79 | + assert.equal(result.status, 0, result.stderr || result.stdout); |
| 80 | + assert.match(result.stdout, /alpha/); |
| 81 | + assert.match(result.stdout, /two words/); |
| 82 | +}); |
0 commit comments