From 5d1dbb5e67233bc07d730e1838ac80940424be37 Mon Sep 17 00:00:00 2001 From: Steven Danna Date: Wed, 31 Mar 2021 12:32:19 +0100 Subject: [PATCH] testutils: add skip.UnderBazel and skip.UnderBazelWithIssue 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 --- pkg/cmd/skip-test/main.go | 22 +++++++++++++++++++--- pkg/testutils/skip/BUILD.bazel | 1 + pkg/testutils/skip/skip.go | 12 ++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/pkg/cmd/skip-test/main.go b/pkg/cmd/skip-test/main.go index 6b45f65c2d2e..bbc33f043654 100644 --- a/pkg/cmd/skip-test/main.go +++ b/pkg/cmd/skip-test/main.go @@ -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() @@ -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.")) @@ -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 @@ -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)) } @@ -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, diff --git a/pkg/testutils/skip/BUILD.bazel b/pkg/testutils/skip/BUILD.bazel index 4ea8aaececc7..5f9a6a694c66 100644 --- a/pkg/testutils/skip/BUILD.bazel +++ b/pkg/testutils/skip/BUILD.bazel @@ -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", ], diff --git a/pkg/testutils/skip/skip.go b/pkg/testutils/skip/skip.go index 010e0e5f31cd..ca87583f4d18 100644 --- a/pkg/testutils/skip/skip.go +++ b/pkg/testutils/skip/skip.go @@ -15,6 +15,7 @@ import ( "fmt" "testing" + "github.com/cockroachdb/cockroach/pkg/build/bazel" "github.com/cockroachdb/cockroach/pkg/util" ) @@ -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()