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{
DumpFlag,
HumanReadableFlag,
NDJSONFlag,
RunFlag,
WitnessCrossCheckFlag,
FuzzFlag,

View file

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

View file

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

View file

@ -85,3 +85,9 @@ func report(ctx *cli.Context, results []testResult) {
out, _ := json.MarshalIndent(results, "", " ")
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,
forkFlag,
HumanReadableFlag,
NDJSONFlag,
idxFlag,
RunFlag,
WorkersFlag,
@ -76,7 +77,9 @@ func stateTestCmd(ctx *cli.Context) error {
if err != nil {
return err
}
report(ctx, results)
if !ctx.Bool(NDJSONFlag.Name) {
report(ctx, results)
}
return nil
}
// Otherwise, read filenames from stdin and execute back-to-back.
@ -211,6 +214,9 @@ func runStateTest(ctx *cli.Context, fname string) ([]testResult, error) {
return
}
})
if ctx.Bool(NDJSONFlag.Name) {
reportNDJSON(*result)
}
results = append(results, *result)
}
}