Skip to content

feat(cli): --output json and --output junit to stdout #1018

Closed

Description

@Chemaclass

Problem

--output <format> accepts exactly one value: tap (bashunit test --help, parsed at src/main/test.sh:72). Every other machine-readable format is file-only (--report-json, --report-junit, --report-tap, --report-html).

That forces a temp file into any pipeline that wants to post-process results:

./bashunit tests/ --report-json /tmp/r.json >/dev/null && jq '.tests[]|select(.status=="failed")' /tmp/r.json

when it should be:

./bashunit tests/ --output json | jq '.tests[]|select(.status=="failed")'

The formats and the writers already exist; only the destination is hard-coded.

Proposal

Extend --output to text (default) | tap | json | junit.

Where to change

  • src/main/test.sh:72 (--output parsing) and src/main/validate.sh:60 (value validation).
  • src/main/run.sh:132-150 — the reporters currently take a file path; give them a stdout path, or write to /dev/stdout consistently.
  • src/reports/json.sh, src/reports/junit.sh, src/reports/tap.sh.
  • src/console/* — the suppression switch that tap already uses.

Acceptance criteria

  • --output json emits a single JSON document on stdout, valid per jq .
  • --output junit emits XML on stdout
  • --output tap is byte-identical to today (no regression)
  • --output text equals no flag
  • No console decoration, progress or header leaks into stdout for the machine formats
  • Errors and warnings still reach stderr
  • Exit codes unchanged across all formats
  • --output json --report-json f.json produces both
  • Unknown value exits non-zero with the valid list
  • Works under --parallel (regression guard for fix(reports): every report format is empty under --parallel #1004)
  • Acceptance tests piping each format through a parser

Repo checklist (agent)

  • TDD: RED → GREEN → REFACTOR. Write the failing test first.
  • Bash 3.0+ only: no printf -v, no += append, no declare -A, no [[ ]], no ${var,,}, no &>>, no ${arr[-1]}. Expanding a possibly-empty array under set -u needs ${arr[@]+"${arr[@]}"}.
  • A new CLI flag must be wired in all of these or a parity test fails:
  • Gates: make sa, make lint, ./bashunit tests/, ./bashunit --parallel tests/. Never run shfmt -w.
  • Docs: update docs/command-line.md. Editing docs/assertions.md invalidates the bashunit doc acceptance snapshot — regenerate it.
  • CHANGELOG.md: add one line under ## Unreleased.
  • Fixtures under tests/acceptance/fixtures/ must not end in *test.sh.
  • One issue = one PR.

Activity

  1. self-assigned this
    on Aug 11, 2026
  2. Chemaclass commented on Aug 11, 2026

    @Chemaclass
    MemberAuthor

    Done in #1064 (merged).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions