Skip to content

Commit

Permalink
Try to format output JSON
Browse files Browse the repository at this point in the history
For example tomlc99 outputs its JSON without spaces or newlines; this is
perfectly valid, but failing test cases are hard to read.
  • Loading branch information
arp242 committed Sep 29, 2023
1 parent 563acb8 commit a7ddf40
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ should run in most environments. It's recommended you use a binary, or a tagged
release if you build from source especially in CI environments. This prevents
your tests from breaking on changes to tests in this tool.

To compile from source you will need Go 1.16 or newer (older versions will *not*
work):
To compile from source you will need Go 1.18 or newer:

$ git clone https://github.com/toml-lang/toml-test.git
$ cd toml-test
$ go build ./cmd/toml-test
$ go install github.com/toml-lang/toml-test/cmd/toml-test@latest

This will build a `./toml-test` binary.

Expand Down
11 changes: 11 additions & 0 deletions cmd/toml-test/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"encoding/json"
"fmt"
"io/fs"
"os"
Expand Down Expand Up @@ -191,6 +192,16 @@ func detailed(r tomltest.Runner, t tomltest.Test) string {
b.WriteByte('\n')
}
showStream(b, "input sent to parser-cmd", t.Input)

var j map[string]any
err := json.Unmarshal([]byte(t.Output), &j)
if err == nil {
out, err := json.MarshalIndent(j, "", " ")
if err == nil {
t.Output = string(out)
}
}

if t.OutputFromStderr {
showStream(b, "output from parser-cmd (stderr)", t.Output)
} else {
Expand Down

0 comments on commit a7ddf40

Please sign in to comment.