cmd/evm: add --ndjson flag for streaming JSON output

This commit is contained in:
spencer-tb 2026-04-05 20:15:33 +01:00
parent ffc5899bad
commit 6f0ae114ab
5 changed files with 19 additions and 1 deletions

View file

@ -42,6 +42,7 @@ var blockTestCommand = &cli.Command{
Flags: slices.Concat([]cli.Flag{ Flags: slices.Concat([]cli.Flag{
DumpFlag, DumpFlag,
HumanReadableFlag, HumanReadableFlag,
NDJSONFlag,
RunFlag, RunFlag,
WitnessCrossCheckFlag, WitnessCrossCheckFlag,
FuzzFlag, FuzzFlag,

View file

@ -51,6 +51,7 @@ var engineTestCommand = &cli.Command{
Flags: slices.Concat([]cli.Flag{ Flags: slices.Concat([]cli.Flag{
DumpFlag, DumpFlag,
HumanReadableFlag, HumanReadableFlag,
NDJSONFlag,
RunFlag, RunFlag,
FuzzFlag, FuzzFlag,
WorkersFlag, WorkersFlag,

View file

@ -75,6 +75,10 @@ var (
Name: "human", Name: "human",
Usage: "\"Human-readable\" output", Usage: "\"Human-readable\" output",
} }
NDJSONFlag = &cli.BoolFlag{
Name: "ndjson",
Usage: "Output one JSON result per line as tests complete (streaming)",
}
StatDumpFlag = &cli.BoolFlag{ StatDumpFlag = &cli.BoolFlag{
Name: "statdump", Name: "statdump",
Usage: "displays stack and heap memory information", Usage: "displays stack and heap memory information",

View file

@ -85,3 +85,9 @@ func report(ctx *cli.Context, results []testResult) {
out, _ := json.MarshalIndent(results, "", " ") out, _ := json.MarshalIndent(results, "", " ")
fmt.Println(string(out)) fmt.Println(string(out))
} }
// reportNDJSON prints one JSON object per result as it completes.
func reportNDJSON(r testResult) {
out, _ := json.Marshal(r)
fmt.Println(string(out))
}

View file

@ -56,6 +56,7 @@ var stateTestCommand = &cli.Command{
DumpFlag, DumpFlag,
forkFlag, forkFlag,
HumanReadableFlag, HumanReadableFlag,
NDJSONFlag,
idxFlag, idxFlag,
RunFlag, RunFlag,
WorkersFlag, WorkersFlag,
@ -76,7 +77,9 @@ func stateTestCmd(ctx *cli.Context) error {
if err != nil { if err != nil {
return err return err
} }
report(ctx, results) if !ctx.Bool(NDJSONFlag.Name) {
report(ctx, results)
}
return nil return nil
} }
// Otherwise, read filenames from stdin and execute back-to-back. // Otherwise, read filenames from stdin and execute back-to-back.
@ -211,6 +214,9 @@ func runStateTest(ctx *cli.Context, fname string) ([]testResult, error) {
return return
} }
}) })
if ctx.Bool(NDJSONFlag.Name) {
reportNDJSON(*result)
}
results = append(results, *result) results = append(results, *result)
} }
} }