diff --git a/exhaustive.go b/exhaustive.go index 8632fe1..f918fef 100644 --- a/exhaustive.go +++ b/exhaustive.go @@ -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 */ diff --git a/exhaustive_go118_test.go b/exhaustive_go118_test.go deleted file mode 100644 index b9e2312..0000000 --- a/exhaustive_go118_test.go +++ /dev/null @@ -1,12 +0,0 @@ -//go:build go1.18 -// +build go1.18 - -package exhaustive - -import ( - "testing" -) - -func TestExhaustiveGo118(t *testing.T) { - runTest(t, "typeparam/...") -} diff --git a/exhaustive_test.go b/exhaustive_test.go index c2644b7..484713a 100644 --- a/exhaustive_test.go +++ b/exhaustive_test.go @@ -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. @@ -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/...") diff --git a/testdata/src/complexpkg/complexpkg.go b/testdata/src/complexpkg/complexpkg.go index f355c16..b700ca5 100644 --- a/testdata/src/complexpkg/complexpkg.go +++ b/testdata/src/complexpkg/complexpkg.go @@ -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()) } diff --git a/testdata/src/typeparam/build.go b/testdata/src/typeparam/build.go new file mode 100644 index 0000000..8856492 --- /dev/null +++ b/testdata/src/typeparam/build.go @@ -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.