mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-24 08:49:29 +00:00
cmd/evm: add --ndjson flag for streaming JSON output
This commit is contained in:
parent
ffc5899bad
commit
6f0ae114ab
5 changed files with 19 additions and 1 deletions
|
|
@ -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,
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
|
|
||||||
|
|
@ -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",
|
||||||
|
|
|
||||||
|
|
@ -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))
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue