-
-
Notifications
You must be signed in to change notification settings - Fork 682
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support the go1.21
testing.Testing()
function (#4190)
**What type of PR is this?** Feature **What does this PR do? Why is it needed?** This change adds in the necessary flags in `go test` to allow [`testing.Testing`] to work as expected. According to the [upstream source], it is set with a `-X` option in the `go` tooling, so this change makes `rules_go` operate accordingly. This should be safe for older Go versions too, given that the link command [docs](https://pkg.go.dev/cmd/link) say that the `-X` arg is not "effective" when the target variable is not defined in the code. Tests are also provided, and `buildifier` moved around some unrelated lines. I'd be happy to undo the unrelated changes. [`testing.Testing`]: https://pkg.go.dev/testing#Testing [upstream source]: https://cs.opensource.google/go/go/+/refs/tags/go1.21.0:src/testing/testing.go;l=647-661 **Which issues(s) does this PR fix?** Fixes #3686. Closes #4096 **Other notes for review** This is intended to replace #4096, which seems to be inactive. The functional code change in this PR was done at the same location.
- Loading branch information
1 parent
4874f9a
commit 6e4fdcf
Showing
5 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
"os" | ||
) | ||
|
||
func main() { | ||
if testing.Testing() { | ||
panic("testing.Testing() returned 'true' in a binary") | ||
} | ||
|
||
file, err := os.Create(os.Args[1]) | ||
if err != nil { | ||
panic(fmt.Sprintf("Failed to open output file %s", err)) | ||
} | ||
file.Close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package testing_testing | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
if ! testing.Testing() { | ||
panic("testing.Testing() returned 'false' in a test") | ||
} | ||
} |