mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 13:16:42 +00:00
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 <noreply@anthropic.com>
This commit is contained in:
parent
fc8c8c1314
commit
2dfae90ccb
1 changed files with 27 additions and 12 deletions
|
|
@ -17,8 +17,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"maps"
|
"maps"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -34,7 +34,7 @@ import (
|
||||||
var blockTestCommand = &cli.Command{
|
var blockTestCommand = &cli.Command{
|
||||||
Action: blockTestCmd,
|
Action: blockTestCmd,
|
||||||
Name: "blocktest",
|
Name: "blocktest",
|
||||||
Usage: "Executes the given blockchain tests",
|
Usage: "Executes the given blockchain tests. Filenames can be fed via standard input (batch mode) or as an argument (one-off execution).",
|
||||||
ArgsUsage: "<path>",
|
ArgsUsage: "<path>",
|
||||||
Flags: slices.Concat([]cli.Flag{
|
Flags: slices.Concat([]cli.Flag{
|
||||||
DumpFlag,
|
DumpFlag,
|
||||||
|
|
@ -46,21 +46,36 @@ var blockTestCommand = &cli.Command{
|
||||||
|
|
||||||
func blockTestCmd(ctx *cli.Context) error {
|
func blockTestCmd(ctx *cli.Context) error {
|
||||||
path := ctx.Args().First()
|
path := ctx.Args().First()
|
||||||
if len(path) == 0 {
|
|
||||||
return errors.New("path argument required")
|
// If path is provided, run the tests at that path.
|
||||||
|
if len(path) != 0 {
|
||||||
|
var (
|
||||||
|
collected = collectFiles(path)
|
||||||
|
results []testResult
|
||||||
|
)
|
||||||
|
for _, fname := range collected {
|
||||||
|
r, err := runBlockTest(ctx, fname)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
results = append(results, r...)
|
||||||
|
}
|
||||||
|
report(ctx, results)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
var (
|
// Otherwise, read filenames from stdin and execute back-to-back.
|
||||||
collected = collectFiles(path)
|
scanner := bufio.NewScanner(os.Stdin)
|
||||||
results []testResult
|
for scanner.Scan() {
|
||||||
)
|
fname := scanner.Text()
|
||||||
for _, fname := range collected {
|
if len(fname) == 0 {
|
||||||
r, err := runBlockTest(ctx, fname)
|
return nil
|
||||||
|
}
|
||||||
|
results, err := runBlockTest(ctx, fname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
results = append(results, r...)
|
report(ctx, results)
|
||||||
}
|
}
|
||||||
report(ctx, results)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue