Skip to content

Commit

Permalink
tests: revert "tests: remove whitelist feature (ethereum#23297)"
Browse files Browse the repository at this point in the history
This reverts commit 85afdee.
  • Loading branch information
holiman committed Jul 30, 2021
1 parent 4884220 commit d98ff81
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions tests/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ func findLine(data []byte, offset int64) (line int) {

// testMatcher controls skipping and chain config assignment to tests.
type testMatcher struct {
configpat []testConfig
failpat []testFailure
skiploadpat []*regexp.Regexp
slowpat []*regexp.Regexp
configpat []testConfig
failpat []testFailure
skiploadpat []*regexp.Regexp
slowpat []*regexp.Regexp
whitelistpat *regexp.Regexp
}

type testConfig struct {
Expand Down Expand Up @@ -123,6 +124,10 @@ func (tm *testMatcher) fails(pattern string, reason string) {
tm.failpat = append(tm.failpat, testFailure{regexp.MustCompile(pattern), reason})
}

func (tm *testMatcher) whitelist(pattern string) {
tm.whitelistpat = regexp.MustCompile(pattern)
}

// config defines chain config for tests matching the pattern.
func (tm *testMatcher) config(pattern string, cfg params.ChainConfig) {
tm.configpat = append(tm.configpat, testConfig{regexp.MustCompile(pattern), cfg})
Expand Down Expand Up @@ -212,6 +217,11 @@ func (tm *testMatcher) runTestFile(t *testing.T, path, name string, runTest inte
if r, _ := tm.findSkip(name); r != "" {
t.Skip(r)
}
if tm.whitelistpat != nil {
if !tm.whitelistpat.MatchString(name) {
t.Skip("Skipped by whitelist")
}
}
t.Parallel()

// Load the file as map[string]<testType>.
Expand Down Expand Up @@ -265,3 +275,14 @@ func runTestFunc(runTest interface{}, t *testing.T, name string, m reflect.Value
m.MapIndex(reflect.ValueOf(key)),
})
}

func TestMatcherWhitelist(t *testing.T) {
t.Parallel()
tm := new(testMatcher)
tm.whitelist("invalid*")
tm.walk(t, rlpTestDir, func(t *testing.T, name string, test *RLPTest) {
if name[:len("invalidRLPTest.json")] != "invalidRLPTest.json" {
t.Fatalf("invalid test found: %s != invalidRLPTest.json", name)
}
})
}

0 comments on commit d98ff81

Please sign in to comment.