Skip to content

Commit 2dfae90

Browse files
bshastryclaude
andcommitted
cmd/evm: add stdin support to blocktest command
Enable blocktest to read filenames from stdin when no path argument is provided, matching the existing statetest behavior. This allows efficient batch processing of blockchain tests. Usage: - Single file: evm blocktest <path> - Batch mode: find tests/ -name "*.json" | evm blocktest 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent fc8c8c1 commit 2dfae90

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

cmd/evm/blockrunner.go

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
package main
1818

1919
import (
20+
"bufio"
2021
"encoding/json"
21-
"errors"
2222
"fmt"
2323
"maps"
2424
"os"
@@ -34,7 +34,7 @@ import (
3434
var blockTestCommand = &cli.Command{
3535
Action: blockTestCmd,
3636
Name: "blocktest",
37-
Usage: "Executes the given blockchain tests",
37+
Usage: "Executes the given blockchain tests. Filenames can be fed via standard input (batch mode) or as an argument (one-off execution).",
3838
ArgsUsage: "<path>",
3939
Flags: slices.Concat([]cli.Flag{
4040
DumpFlag,
@@ -46,21 +46,36 @@ var blockTestCommand = &cli.Command{
4646

4747
func blockTestCmd(ctx *cli.Context) error {
4848
path := ctx.Args().First()
49-
if len(path) == 0 {
50-
return errors.New("path argument required")
49+
50+
// If path is provided, run the tests at that path.
51+
if len(path) != 0 {
52+
var (
53+
collected = collectFiles(path)
54+
results []testResult
55+
)
56+
for _, fname := range collected {
57+
r, err := runBlockTest(ctx, fname)
58+
if err != nil {
59+
return err
60+
}
61+
results = append(results, r...)
62+
}
63+
report(ctx, results)
64+
return nil
5165
}
52-
var (
53-
collected = collectFiles(path)
54-
results []testResult
55-
)
56-
for _, fname := range collected {
57-
r, err := runBlockTest(ctx, fname)
66+
// Otherwise, read filenames from stdin and execute back-to-back.
67+
scanner := bufio.NewScanner(os.Stdin)
68+
for scanner.Scan() {
69+
fname := scanner.Text()
70+
if len(fname) == 0 {
71+
return nil
72+
}
73+
results, err := runBlockTest(ctx, fname)
5874
if err != nil {
5975
return err
6076
}
61-
results = append(results, r...)
77+
report(ctx, results)
6278
}
63-
report(ctx, results)
6479
return nil
6580
}
6681

0 commit comments

Comments
 (0)