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 bin/moshcode.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ function readScript(arg) {

function parseMax(value) {
if (value === undefined) throw new Error("moshcode run: --max requires a positive integer");
if (!/^\d+$/.test(String(value))) {
throw new Error(`moshcode run: --max must be a positive integer, got ${JSON.stringify(value)}`);
}
const max = Number(value);
if (!Number.isInteger(max) || max < 1) {
throw new Error(`moshcode run: --max must be a positive integer, got ${JSON.stringify(value)}`);
Expand Down
9 changes: 9 additions & 0 deletions test/run-options.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ test("run accepts equals-form max option", async () => {
assert.match(result.stdout, /1 loop\(s\)/);
});

test("run rejects non-decimal max values", async () => {
for (const value of ["1e1", "0x2"]) {
const result = await run([`--max=${value}`, "--dry-run"]);

assert.equal(result.status, 1);
assert.match(result.stderr, /moshcode run: --max must be a positive integer/);
}
});

test("run() marks the nested moshcode child as nested", async () => {
const dir = mkdtempSync(join(tmpdir(), "moshcode-nested-"));
const child = join(dir, "child.mosh");
Expand Down
Loading