Skip to content

Commit

Permalink
logictest: avoid a lint failure
Browse files Browse the repository at this point in the history
The go compiler treats calls to `bazel.BuiltWithBazel()` as a
compile-time constant. Therefore,

```go
if !bazel.BuiltWithBazel() {
   skip.XXX()
}
```

is considered to always terminate execution (because `skip` does its
job by raising a panic), and any code coming after that is treated as
dead/unreachable.

Release note: None
  • Loading branch information
knz committed Nov 28, 2022
1 parent 8e4d3df commit 8782424
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/sql/logictest/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,10 @@ func getFreePort() (int, error) {
return port, err
}

// Prevent a lint failure "this value is never used" in
// `(*logicTest).setup` when bazel.BuiltWithBazel returns false.
var _ = ((*logicTest)(nil)).newTestServerCluster

// newTestServerCluster creates a 3-node cluster using the cockroach-go library.
// bootstrapBinaryPath is given by the config's CockroachGoBootstrapVersion.
// upgradeBinaryPath is given by the config's CockroachGoUpgradeVersion, or
Expand Down Expand Up @@ -1823,6 +1827,11 @@ func (t *logicTest) setup(
if err != nil {
t.Fatal(err)
}

// Prevent a lint failure "this value is never used" when
// bazel.BuiltWithBazel returns false above.
_ = bootstrapBinaryPath

localBinaryPath, found := bazel.FindBinary("pkg/cmd/cockroach-short/cockroach-short_/", "cockroach-short")
if !found {
t.Fatal(errors.New("cockroach binary not found"))
Expand Down

0 comments on commit 8782424

Please sign in to comment.