Skip to content

Commit

Permalink
typeparam test file does not need to be separate
Browse files Browse the repository at this point in the history
The typeparam test was in a separate file with a go1.18 build
constraint. However the test doesn't necessarily have to be in a
separate file; we can instead make the typeparam testdata package, that
is used by the test, build with all go versions.
  • Loading branch information
nishanths committed Nov 27, 2022
1 parent 746c972 commit 228d3b5
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 37 deletions.
2 changes: 1 addition & 1 deletion exhaustive.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ To ignore specific constants in exhaustiveness checks, use the
-ignore-enum-members flag. Similarly, to ignore specific types, use the
-ignore-enum-types flag. For example:
exhaustive -ignore-enum-types '^time\.Duration$|^example.org/measure\.Unit$'
exhaustive -ignore-enum-types '^time\.Duration$|^example\.org/measure\.Unit$'
[language spec]: https://golang.org/ref/spec
*/
Expand Down
12 changes: 0 additions & 12 deletions exhaustive_go118_test.go

This file was deleted.

39 changes: 20 additions & 19 deletions exhaustive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ import (
"golang.org/x/tools/go/analysis/analysistest"
)

func runTest(t *testing.T, pattern string, setup ...func()) {
t.Helper()
t.Run(pattern, func(t *testing.T) {
resetFlags()
// default to checking switch and map for test.
fCheck = stringsFlag{
[]string{
string(elementSwitch),
string(elementMap),
},
nil,
}
for _, f := range setup {
f()
}
analysistest.Run(t, analysistest.TestData(), Analyzer, pattern)
})
}

func TestExhaustive(t *testing.T) {
runTest := func(t *testing.T, pattern string, setup ...func()) {
t.Helper()
t.Run(pattern, func(t *testing.T) {
resetFlags()
// default to checking switch and map for test.
fCheck = stringsFlag{
[]string{
string(elementSwitch),
string(elementMap),
},
nil,
}
for _, f := range setup {
f()
}
analysistest.Run(t, analysistest.TestData(), Analyzer, pattern)
})
}

if !testing.Short() {
// Analysis of code that uses complex packages, such as package os and
// package reflect, should not fail.
Expand Down Expand Up @@ -76,6 +76,7 @@ func TestExhaustive(t *testing.T) {
runTest(t, "duplicate-enum-value/...")

runTest(t, "typealias/...")
runTest(t, "typeparam/...")

// mixture of general tests.
runTest(t, "general/...")
Expand Down
11 changes: 6 additions & 5 deletions testdata/src/complexpkg/complexpkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import (
func useComplexPackages() {
// see issue 25: https://github.com/nishanths/exhaustive/issues/25
var (
_ http.Server
_ elliptic.Curve
_ tls.Conn
_ reflect.ChanDir
_ json.Encoder
_ elliptic.Curve
_ time.Ticker
_ fmt.Formatter
_ http.Server
_ os.File
_ reflect.ChanDir
_ time.Ticker
)
fmt.Println(os.LookupEnv(""))
fmt.Println(os.Getgid())
}
4 changes: 4 additions & 0 deletions testdata/src/typeparam/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package typeparam

// This file exists so that the package (which, otherwise, consists only of
// go1.18 files) can build with all go versions.

0 comments on commit 228d3b5

Please sign in to comment.