Skip to content

Commit

Permalink
testutils: add skip.UnderBazel and skip.UnderBazelWithIssue
Browse files Browse the repository at this point in the history
This is to skip individual tests under bazel. This seems a bit more
fine-grained than the broken_in_bazel tag in the bazel configuration
but also allows us to avoid skipping tests that work outside of bazel
in our main test suite.

Release note: None
  • Loading branch information
stevendanna committed Mar 31, 2021
1 parent 99c29ef commit 5d1dbb5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
22 changes: 19 additions & 3 deletions pkg/cmd/skip-test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ var flagUnderRace = flag.Bool(
false,
"if true, only skip under race",
)
var flagUnderBazel = flag.Bool(
"under_bazel",
false,
"if true, only skip under bazel",
)

func main() {
flag.Parse()
Expand Down Expand Up @@ -81,6 +86,10 @@ func main() {
log.Fatalf("expected test to be of format `TestName` or `pkg/to/test:TestName`, found %s", arg)
}

if *flagUnderBazel && *flagUnderRace {
log.Fatal("cannot use both -under_race and -under_bazel")
}

// Check git status is clean.
if err := spawn("git", "diff", "--exit-code"); err != nil {
log.Fatal(errors.Wrap(err, "git state may not be clean, please use `git stash` or commit changes before proceeding."))
Expand Down Expand Up @@ -131,9 +140,11 @@ func main() {
if err := spawn("git", "add", fileName); err != nil {
log.Fatal(errors.Wrapf(err, "failed to add %s to commit", fileName))
}
var underRaceStr string
var modifierStr string
if *flagUnderRace {
underRaceStr = " under race"
modifierStr = " under race"
} else if *flagUnderBazel {
modifierStr = " under bazel"
}
commitMsg := fmt.Sprintf(`%s: skip %s%s
Expand All @@ -146,7 +157,7 @@ Generated by bin/skip-test.
Release justification: non-production code changes
Release note: None
`, pkgPrefix, testName, underRaceStr, issueNum, *flagReason)
`, pkgPrefix, testName, modifierStr, issueNum, *flagReason)
if err := spawn("git", "commit", "-m", commitMsg); err != nil {
log.Fatal(errors.Wrapf(err, "failed to commit %s", fileName))
}
Expand Down Expand Up @@ -208,6 +219,11 @@ func replaceFile(fileName, testName string, issueNum int) {
newLines,
fmt.Sprintf(`skip.UnderRaceWithIssue(t, %d, "%s")`, issueNum, *flagReason),
)
} else if *flagUnderBazel {
newLines = append(
newLines,
fmt.Sprintf(`skip.UnderBazelWithIssue(t, %d, "%s")`, issueNum, *flagReason),
)
} else {
newLines = append(
newLines,
Expand Down
1 change: 1 addition & 0 deletions pkg/testutils/skip/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ go_library(
importpath = "github.com/cockroachdb/cockroach/pkg/testutils/skip",
visibility = ["//visibility:public"],
deps = [
"//pkg/build/bazel",
"//pkg/util",
"//pkg/util/envutil",
],
Expand Down
12 changes: 12 additions & 0 deletions pkg/testutils/skip/skip.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"fmt"
"testing"

"github.com/cockroachdb/cockroach/pkg/build/bazel"
"github.com/cockroachdb/cockroach/pkg/util"
)

Expand Down Expand Up @@ -66,6 +67,17 @@ func UnderRaceWithIssue(t SkippableTest, githubIssueID int, args ...interface{})
}
}

// UnderBazelWithIssue skips this test if we are building inside bazel,
// logging the given issue ID as the reason.
func UnderBazelWithIssue(t SkippableTest, githubIssueID int, args ...interface{}) {
t.Helper()
if bazel.BuiltWithBazel() {
t.Skip(append([]interface{}{fmt.Sprintf(
"disabled under bazel. issue: https://github.com/cockroachdb/cockroach/issue/%d", githubIssueID,
)}, args...))
}
}

// UnderShort skips this test if the -short flag is specified.
func UnderShort(t SkippableTest, args ...interface{}) {
t.Helper()
Expand Down

0 comments on commit 5d1dbb5

Please sign in to comment.