Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/tui.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ function printPrds() {
async function runFile(args) {
// Parse /run options the same way the CLI does (R3: two entrypoints agree).
let max, dryRun = false, file = null;
const argv = [];
for (let i = 0; i < args.length; i++) {
const a = args[i];
if (a === "--max" || a === "-n") {
Expand All @@ -290,6 +291,8 @@ async function runFile(args) {
return;
} else if (!file) {
file = a;
} else {
argv.push(a);
}
}
if (!file) { console.log(err("usage: /run <file.mosh> [--max N] [--dry-run]")); return; }
Expand All @@ -300,7 +303,7 @@ async function runFile(args) {
console.log(hr());
if (dryRun) console.log(info("dry run — narrating without executing"));
let result = { iterations: 0 };
const opts = { commands: moshVocabulary(), dryRun, out: (s) => console.log(s) };
const opts = { commands: moshVocabulary(), dryRun, argv, out: (s) => console.log(s) };
if (max !== undefined) opts.max = max;
try {
result = await runScript(src, opts);
Expand Down
27 changes: 26 additions & 1 deletion test/tui.test.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import assert from "node:assert/strict";
import { spawn } from "node:child_process";
import { spawn, spawnSync } from "node:child_process";
import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import test from "node:test";
import { fileURLToPath } from "node:url";

Expand Down Expand Up @@ -55,3 +58,25 @@ test("TUI /run rejects unknown options before reading a script file", async () =
assert.match(result.stdout, /unknown option --dryrun/);
assert.doesNotMatch(result.stdout, /can't read --dryrun/);
});

test("TUI /run passes positional args through to moshscript argv", () => {
const dir = mkdtempSync(join(tmpdir(), "moshcode-tui-"));
mkdirSync(join(dir, "space dir"));
const script = join(dir, "space dir", "argv.mosh");
writeFileSync(script, 'say(argv[0]); say(argv[1]);\n');
const scriptArg = script.replaceAll("\\", "/");

const result = spawnSync(
process.execPath,
["bin/moshcode.mjs"],
{
cwd: join(import.meta.dirname, ".."),
input: `/run "${scriptArg}" alpha "two words"\n/quit\n`,
encoding: "utf8",
},
);

assert.equal(result.status, 0, result.stderr || result.stdout);
assert.match(result.stdout, /alpha/);
assert.match(result.stdout, /two words/);
});
Loading