Skip to content

fix(output): keep the console blank line out of json and junit - #1244

Merged
Chemaclass merged 1 commit into
mainfrom
fix/machine-output-leading-blank-line
Aug 14, 2026
Merged

fix(output): keep the console blank line out of json and junit#1244
Chemaclass merged 1 commit into
mainfrom
fix/machine-output-leading-blank-line

Conversation

@Chemaclass

Copy link
Copy Markdown
Member

🤔 Background

Related #1243

$ bashunit --output junit tests/ > report.xml
$ xmllint --noout report.xml
report.xml:2: parser error : XML declaration allowed only at the start of the document

The document's first byte is a newline. Only the parallel path was correct — and parallel is not the default — so the plain documented command was the broken one. run_tear_down_after_script prints a blank line between files, guarded against --simple, --failures-only, --no-progress and --parallel, but not against a machine --output.

--output json gained the same leading blank line, unnoticed because JSON tolerates leading whitespace: jq accepted it, and the existing test only checks that it parses.

💡 Changes

  • Suppress the blank line for json and junit, naming those two formats rather than using is_machine_output_enabled — that also covers tap, where a blank line between files is valid, streams fine and is recorded in its snapshots
  • Add the sequential counterpart to the JUnit guard, which only ever pinned --parallel (the path that already worked)
  • Add a real well-formedness check with xmllint, since asserting the first line is not the same as asserting a parser accepts the document
  • Assert the JSON document starts where it should, not merely that it parses

Human output is unchanged: the blank line still separates files. Verified separately that escaping was never the problem — <, &, ", ]]> and backslashes, tabs and unicode all round-trip correctly in both formats, and the on-disk --report-junit/--report-json writers were unaffected.

`bashunit --output junit` produced XML no parser accepts: the first byte was a
newline, so the declaration was not first. Sequential is the default, and only
the parallel path was correct -- which is also the only path the existing guard
test covers.

run_tear_down_after_script prints a blank line between a file's tests and the
next when the file has no tear_down_after_script hook. It was guarded against
--simple, --failures-only, --no-progress and --parallel, but not against a
machine --output, and both documents are written at the end of the run. The
json document gained the same leading blank line, unnoticed because JSON
tolerates leading whitespace, so `jq` accepted it and the test that only checks
it parses stayed green.

Name json and junit rather than using is_machine_output_enabled, which also
covers tap: TAP streams line by line, so a blank line between files is valid
there and is what its snapshots record.

Closes #1243
@Chemaclass Chemaclass added the bug Something isn't working label Aug 14, 2026
@Chemaclass Chemaclass self-assigned this Aug 14, 2026
@Chemaclass
Chemaclass merged commit 51b3020 into main Aug 14, 2026
37 checks passed
@Chemaclass
Chemaclass deleted the fix/machine-output-leading-blank-line branch August 14, 2026 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant