From da68c2fcf8843cb4628a3ecc85420f7d7483b2b7 Mon Sep 17 00:00:00 2001 From: Kjell Tore Guttormsen Date: Mon, 4 May 2026 20:33:23 +0200 Subject: [PATCH] test(tally): add 4 tests for --regex/-r path covering SC #1, #2, #4, #5 Step 4 (final) of plan.md (Spor B B3 pipeline run). Adds 4 new tests in a contiguous block at the end of tests/tally.test.mjs, mirroring the existing spawnSync style. All 4 test names contain --regex or -r. Coverage map: - SC #1 (long form, exit 0): test 1 - SC #2 (-r short form): test 2 - SC #4 (invalid exits 2 with /^tally: invalid regex/): test 3 - SC #5 (--json includes flags.regex): test 4 Total: 14 tests, all green, 3.16s wall-clock (under 5s cap). [skip-docs] --- .../examples/02-real-cli/tests/tally.test.mjs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/plugins/ultraplan-local/examples/02-real-cli/tests/tally.test.mjs b/plugins/ultraplan-local/examples/02-real-cli/tests/tally.test.mjs index 0b132bb..e01d798 100644 --- a/plugins/ultraplan-local/examples/02-real-cli/tests/tally.test.mjs +++ b/plugins/ultraplan-local/examples/02-real-cli/tests/tally.test.mjs @@ -91,3 +91,37 @@ test('--help: stdout contains "Usage:", exit 0', () => { assert.match(r.stdout, /Usage:/); assert.match(r.stdout, /--ignore-case/); }); + +// --- Tests for --regex / -r mode (added in plan step 4, Spor B B3) --- + +test("--regex 'fo+' counts more matches than literal 'foo' (long form, exit 0)", () => { + const literal = run('foo', SAMPLE); + const regex = run('--regex', 'fo+', SAMPLE); + assert.equal(literal.status, 0); + assert.equal(regex.status, 0); + assert.ok(Number(regex.stdout) >= Number(literal.stdout), + `regex count (${regex.stdout.trim()}) should be >= literal count (${literal.stdout.trim()})`); +}); + +test("-r short form equals --regex long form (same stdout)", () => { + const short = run('-r', 'fo+', SAMPLE); + const long = run('--regex', 'fo+', SAMPLE); + assert.equal(short.status, 0); + assert.equal(long.status, 0); + assert.equal(short.stdout, long.stdout); +}); + +test("--regex '[' exits 2 with stderr 'tally: invalid regex'", () => { + const r = run('--regex', '[', SAMPLE); + assert.equal(r.status, 2); + assert.equal(r.stdout, ''); + assert.match(r.stderr, /^tally: invalid regex/); +}); + +test("--json --regex 'fo+' includes flags.regex === true in output", () => { + const r = run('--json', '--regex', 'fo+', SAMPLE); + assert.equal(r.status, 0); + const parsed = JSON.parse(r.stdout); + assert.equal(parsed.flags.regex, true); + assert.ok(typeof parsed.count === 'number' && parsed.count > 0); +});