internal/lsp/analysis: add typeparams tests for nonewvars and noresultvalues

Also, change the way we test fillreturns to match the other analyzers.

Change-Id: If2124775c583524ff61017452bf065965a6cc97e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/353171
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Rebecca Stambler 2021-09-29 15:24:39 -04:00
parent 24389d4d0c
commit 378b9e1d59
11 changed files with 52 additions and 23 deletions

View File

@ -9,9 +9,14 @@ import (
"golang.org/x/tools/go/analysis/analysistest"
"golang.org/x/tools/internal/lsp/analysis/fillreturns"
"golang.org/x/tools/internal/typeparams"
)
func Test(t *testing.T) {
testdata := analysistest.TestData()
analysistest.RunWithSuggestedFixes(t, testdata, fillreturns.Analyzer, "a")
tests := []string{"a"}
if typeparams.Enabled {
tests = append(tests, "typeparams")
}
analysistest.RunWithSuggestedFixes(t, testdata, fillreturns.Analyzer, tests...)
}

View File

@ -1,10 +0,0 @@
//go:build go1.18
// +build go1.18
package fillreturns
type Any interface{}
func hello[T any]() int {
return
}

View File

@ -1,10 +0,0 @@
//go:build go1.18
// +build go1.18
package fillreturns
type Any interface{}
func hello[T any]() int {
return
}

View File

@ -0,0 +1,5 @@
package fillreturns
func hello[T any]() int {
return
}

View File

@ -0,0 +1,5 @@
package fillreturns
func hello[T any]() int {
return
}

View File

@ -9,9 +9,14 @@ import (
"golang.org/x/tools/go/analysis/analysistest"
"golang.org/x/tools/internal/lsp/analysis/nonewvars"
"golang.org/x/tools/internal/typeparams"
)
func Test(t *testing.T) {
testdata := analysistest.TestData()
analysistest.RunWithSuggestedFixes(t, testdata, nonewvars.Analyzer, "a")
tests := []string{"a"}
if typeparams.Enabled {
tests = append(tests, "typeparams")
}
analysistest.RunWithSuggestedFixes(t, testdata, nonewvars.Analyzer, tests...)
}

View File

@ -0,0 +1,6 @@
package nonewvars
func hello[T any]() int {
var z T
z := 1 // want "no new variables on left side of :="
}

View File

@ -0,0 +1,6 @@
package nonewvars
func hello[T any]() int {
var z T
z = 1 // want "no new variables on left side of :="
}

View File

@ -9,9 +9,14 @@ import (
"golang.org/x/tools/go/analysis/analysistest"
"golang.org/x/tools/internal/lsp/analysis/noresultvalues"
"golang.org/x/tools/internal/typeparams"
)
func Test(t *testing.T) {
testdata := analysistest.TestData()
analysistest.RunWithSuggestedFixes(t, testdata, noresultvalues.Analyzer, "a")
tests := []string{"a"}
if typeparams.Enabled {
tests = append(tests, "typeparams")
}
analysistest.RunWithSuggestedFixes(t, testdata, noresultvalues.Analyzer, tests...)
}

View File

@ -0,0 +1,6 @@
package noresult
func hello[T any]() {
var z T
return z // want "no result values expected"
}

View File

@ -0,0 +1,6 @@
package noresult
func hello[T any]() {
var z T
return // want "no result values expected"
}