Skip to content

Commit

Permalink
Revert "mantle/kola: enhance allTestsDenyListed detection"
Browse files Browse the repository at this point in the history
This still isn't right because it doesn't consider when a test
is matched based on tag. Let's revert e070cb1 and do it a different
way.
  • Loading branch information
dustymabe committed Jun 15, 2023
1 parent 453afe6 commit 7ce07d8
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions mantle/kola/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,18 +679,14 @@ func runProvidedTests(testsBank map[string]*register.Test, patterns []string, mu
plog.Fatal(err)
}

// Find all tests matching the given pattern(s) and make sure all given
// patterns by the user match at least one test.
patternMatchingTests := []register.Test{}
// Make sure all given patterns by the user match at least one test
for _, pattern := range patterns {
matches, err := findPatternMatchingTests(pattern, testsBank)
match, err := patternMatchesTests(pattern, testsBank)
if err != nil {
plog.Fatal(err)
}
if len(matches) == 0 {
if !match {
plog.Fatalf("The user provided pattern didn't match any tests: %s", pattern)
} else {
patternMatchingTests = append(patternMatchingTests, matches...)
}
}

Expand All @@ -699,7 +695,7 @@ func runProvidedTests(testsBank map[string]*register.Test, patterns []string, mu
plog.Fatal(err)
}

if len(tests) == 0 && allTestsDenyListed(patternMatchingTests) {
if len(tests) == 0 && allTestsDenyListed(tests) {
fmt.Printf("There are no tests to run because all tests are denylisted. Output in %v\n", outputDir)
return nil
}
Expand Down Expand Up @@ -846,9 +842,9 @@ func runProvidedTests(testsBank map[string]*register.Test, patterns []string, mu
return runErr
}

func allTestsDenyListed(tests []register.Test) bool {
for _, test := range tests {
isDenylisted, err := testIsDenyListed(test.Name)
func allTestsDenyListed(tests map[string]*register.Test) bool {
for name := range tests {
isDenylisted, err := testIsDenyListed(name)
if err != nil {
plog.Warningf("Error while checking denylist for test: %s", err)
continue
Expand Down Expand Up @@ -1244,16 +1240,15 @@ func testIsDenyListed(testname string) (bool, error) {
}

// Function that returns true if at least one test matches the given pattern
func findPatternMatchingTests(pattern string, tests map[string]*register.Test) ([]register.Test, error) {
matchingTests := []register.Test{}
for testname, test := range tests {
func patternMatchesTests(pattern string, tests map[string]*register.Test) (bool, error) {
for testname := range tests {
if match, err := filepath.Match(pattern, testname); err != nil {
return matchingTests, err
return false, err
} else if match {
matchingTests = append(matchingTests, *test)
return true, nil
}
}
return matchingTests, nil
return false, nil
}

// registerTestDir parses one test directory and registers it as a test
Expand Down

0 comments on commit 7ce07d8

Please sign in to comment.