cmd/evm: run tests based on regexp in blockrunner

This commit is contained in:
lightclient 2023-10-30 17:41:32 -06:00
parent ba928796db
commit a900186dbe
No known key found for this signature in database
GPG key ID: 75C916AFEE20183E

View file

@ -21,6 +21,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"os" "os"
"regexp"
"sort" "sort"
"github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/rawdb"
@ -30,10 +31,10 @@ import (
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
var singleTestFlag = &cli.StringFlag{ var RunFlag = &cli.StringFlag{
Name: "single-test", Name: "run",
Value: "", Value: ".*",
Usage: "Run a single test from the json file", Usage: "Run only those tests matching the regular expression.",
} }
var blockTestCommand = &cli.Command{ var blockTestCommand = &cli.Command{
@ -41,9 +42,7 @@ var blockTestCommand = &cli.Command{
Name: "blocktest", Name: "blocktest",
Usage: "executes the given blockchain tests", Usage: "executes the given blockchain tests",
ArgsUsage: "<file>", ArgsUsage: "<file>",
Flags: []cli.Flag{ Flags: []cli.Flag{RunFlag},
singleTestFlag,
},
} }
func blockTestCmd(ctx *cli.Context) error { func blockTestCmd(ctx *cli.Context) error {
@ -70,24 +69,21 @@ func blockTestCmd(ctx *cli.Context) error {
if err = json.Unmarshal(src, &tests); err != nil { if err = json.Unmarshal(src, &tests); err != nil {
return err return err
} }
singleTest := ctx.String(singleTestFlag.Name) re, err := regexp.Compile(ctx.String(RunFlag.Name))
if singleTest != "" { if err != nil {
if test, ok := tests[singleTest]; ok { return fmt.Errorf("invalid regex -%s: %v", RunFlag.Name, err)
if err := test.Run(false, rawdb.HashScheme, tracer); err != nil {
return fmt.Errorf("test %v: %w", singleTest, err)
}
} else {
return fmt.Errorf("test %v not found", singleTest)
}
return nil
} }
// run them in order
// Run them in order
var keys []string var keys []string
for key := range tests { for key := range tests {
keys = append(keys, key) keys = append(keys, key)
} }
sort.Strings(keys) sort.Strings(keys)
for _, name := range keys { for _, name := range keys {
if !re.MatchString(name) {
continue
}
test := tests[name] test := tests[name]
if err := test.Run(false, rawdb.HashScheme, tracer); err != nil { if err := test.Run(false, rawdb.HashScheme, tracer); err != nil {
return fmt.Errorf("test %v: %w", name, err) return fmt.Errorf("test %v: %w", name, err)