-
-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SA1019: account for all combinations of test packages using each other
A single Go package results in three packages when testing: the package under test with its internal tests, a package for external tests, and a package main that runs the tests. We need to allow external tests to import the package under test, and the test's main to import both the package under test as well as its external tests, and to use the objects defined in them. Closes gh-1285
- Loading branch information
Showing
4 changed files
with
85 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
18 changes: 18 additions & 0 deletions
18
staticcheck/testdata/src/example.com/CheckDeprecated/CheckDeprecated_test.go
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,18 @@ | ||
package pkg | ||
|
||
import "testing" | ||
|
||
// Deprecated: deprecating tests is silly but possible. | ||
func TestFoo(t *testing.T) { | ||
var s S | ||
// Internal tests can use deprecated objects from the package they test. | ||
_ = s.Field | ||
} | ||
|
||
// This test isn't deprecated, to test that s.Field doesn't get flagged because it's from the package under test. If | ||
// TestBar was itself deprecated, it could use any deprecated objects it wanted. | ||
func TestBar(t *testing.T) { | ||
var s S | ||
// Internal tests can use deprecated objects from the package under test | ||
_ = s.Field | ||
} |
21 changes: 21 additions & 0 deletions
21
staticcheck/testdata/src/example.com/CheckDeprecated/external_test.go
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,21 @@ | ||
// Deprecated: deprecating external test packages is silly but possible. | ||
package pkg_test | ||
|
||
import ( | ||
"testing" | ||
|
||
// External tests can import deprecated packages under test. | ||
pkg "example.com/CheckDeprecated" | ||
) | ||
|
||
// Deprecated: deprecating tests is silly but possible. | ||
func TestFoo(t *testing.T) { | ||
} | ||
|
||
// This test isn't deprecated, to test that s.Field doesn't get flagged because it's from the package under test. If | ||
// TestBar was itself deprecated, it could use any deprecated objects it wanted. | ||
func TestBar(t *testing.T) { | ||
var s pkg.S | ||
// External tests can use deprecated objects from the package under test | ||
_ = s.Field | ||
} |