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
3 changes: 3 additions & 0 deletions src/tui.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ async function runFile(args) {
max = v;
} else if (a === "--dry-run") {
dryRun = true;
} else if (a.startsWith("-") && !file) {
console.log(err(`unknown option ${a}`));
return;
} else if (!file) {
file = a;
}
Expand Down
25 changes: 25 additions & 0 deletions test/tui.test.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
import assert from "node:assert/strict";
import { spawn } from "node:child_process";
import test from "node:test";
import { fileURLToPath } from "node:url";

import { splitCommandLine } from "../src/tui.mjs";

const BIN = fileURLToPath(new URL("../bin/moshcode.mjs", import.meta.url));

function runTui(input) {
return new Promise((resolve, reject) => {
const child = spawn(process.execPath, [BIN], { stdio: ["pipe", "pipe", "pipe"] });
let stdout = "";
let stderr = "";
child.stdout.on("data", (chunk) => { stdout += chunk; });
child.stderr.on("data", (chunk) => { stderr += chunk; });
child.on("error", reject);
child.on("close", (status, signal) => resolve({ status, signal, stdout, stderr }));
child.stdin.end(input);
});
}

test("TUI command parsing preserves quoted native CLI arguments", () => {
assert.deepEqual(
splitCommandLine('/coinpay card pay --description "Fix the build" --note \'ship it\''),
Expand All @@ -23,3 +40,11 @@ test("TUI command parsing rejects incomplete quoting", () => {
assert.throws(() => splitCommandLine('/coinpay --description "unfinished'), /unterminated/);
assert.throws(() => splitCommandLine("/ugig trailing\\"), /trailing escape/);
});

test("TUI /run rejects unknown options before reading a script file", async () => {
const result = await runTui("/run --dryrun\n/quit\n");

assert.equal(result.status, 0);
assert.match(result.stdout, /unknown option --dryrun/);
assert.doesNotMatch(result.stdout, /can't read --dryrun/);
});
Loading