mirror of https://github.com/golang/go.git
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:
parent
24389d4d0c
commit
378b9e1d59
|
|
@ -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...)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
//go:build go1.18
|
||||
// +build go1.18
|
||||
|
||||
package fillreturns
|
||||
|
||||
type Any interface{}
|
||||
|
||||
func hello[T any]() int {
|
||||
return
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
//go:build go1.18
|
||||
// +build go1.18
|
||||
|
||||
package fillreturns
|
||||
|
||||
type Any interface{}
|
||||
|
||||
func hello[T any]() int {
|
||||
return
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package fillreturns
|
||||
|
||||
func hello[T any]() int {
|
||||
return
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package fillreturns
|
||||
|
||||
func hello[T any]() int {
|
||||
return
|
||||
}
|
||||
|
|
@ -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...)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
package nonewvars
|
||||
|
||||
func hello[T any]() int {
|
||||
var z T
|
||||
z := 1 // want "no new variables on left side of :="
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
package nonewvars
|
||||
|
||||
func hello[T any]() int {
|
||||
var z T
|
||||
z = 1 // want "no new variables on left side of :="
|
||||
}
|
||||
|
|
@ -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...)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
package noresult
|
||||
|
||||
func hello[T any]() {
|
||||
var z T
|
||||
return z // want "no result values expected"
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
package noresult
|
||||
|
||||
func hello[T any]() {
|
||||
var z T
|
||||
return // want "no result values expected"
|
||||
}
|
||||
Loading…
Reference in New Issue