From 285202aae2a580b82f30ebd909c1819b22d90066 Mon Sep 17 00:00:00 2001 From: Mario Vega Date: Tue, 31 Oct 2023 08:23:51 -0600 Subject: [PATCH] cmd/evm: add --run option to blocktest command (#28421) Co-authored-by: lightclient --- cmd/evm/blockrunner.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/cmd/evm/blockrunner.go b/cmd/evm/blockrunner.go index 42be6726b..ff6557458 100644 --- a/cmd/evm/blockrunner.go +++ b/cmd/evm/blockrunner.go @@ -21,6 +21,7 @@ import ( "errors" "fmt" "os" + "regexp" "sort" "github.com/ethereum/go-ethereum/core/rawdb" @@ -30,11 +31,18 @@ import ( "github.com/urfave/cli/v2" ) +var RunFlag = &cli.StringFlag{ + Name: "run", + Value: ".*", + Usage: "Run only those tests matching the regular expression.", +} + var blockTestCommand = &cli.Command{ Action: blockTestCmd, Name: "blocktest", Usage: "executes the given blockchain tests", ArgsUsage: "", + Flags: []cli.Flag{RunFlag}, } func blockTestCmd(ctx *cli.Context) error { @@ -61,13 +69,21 @@ func blockTestCmd(ctx *cli.Context) error { if err = json.Unmarshal(src, &tests); err != nil { return err } - // run them in order + re, err := regexp.Compile(ctx.String(RunFlag.Name)) + if err != nil { + return fmt.Errorf("invalid regex -%s: %v", RunFlag.Name, err) + } + + // Run them in order var keys []string for key := range tests { keys = append(keys, key) } sort.Strings(keys) for _, name := range keys { + if !re.MatchString(name) { + continue + } test := tests[name] if err := test.Run(false, rawdb.HashScheme, tracer); err != nil { return fmt.Errorf("test %v: %w", name, err)