зеркало из https://github.com/golang/tools.git
x/tools: make tests agnostic as to whether gotypesalias="" => 0 or 1
This is required temporarily as we flip the default. Updates golang/go#65294 Change-Id: I552e40475cc48b949e2307af347ca98a428c55ea Reviewed-on: https://go-review.googlesource.com/c/tools/+/578041 Reviewed-by: Robert Findley <rfindley@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Alan Donovan <adonovan@google.com>
This commit is contained in:
Родитель
46a04010fc
Коммит
dcccb2dba2
|
@ -5,19 +5,17 @@
|
|||
package fillreturns_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/tools/go/analysis/analysistest"
|
||||
"golang.org/x/tools/gopls/internal/analysis/fillreturns"
|
||||
"golang.org/x/tools/internal/testenv"
|
||||
)
|
||||
|
||||
func Test(t *testing.T) {
|
||||
// TODO(golang/go#65294): delete once gotypesalias=1 is the default.
|
||||
if strings.Contains(os.Getenv("GODEBUG"), "gotypesalias=1") {
|
||||
t.Skip("skipping due to gotypesalias=1, which changes (improves) the result; reenable and update the expectations once it is the default")
|
||||
}
|
||||
// TODO(golang/go#65294): delete (and update expectations)
|
||||
// once gotypesalias=1 is the default.
|
||||
testenv.SkipMaterializedAliases(t, "expectations need updating for materialized aliases")
|
||||
|
||||
testdata := analysistest.TestData()
|
||||
analysistest.RunWithSuggestedFixes(t, testdata, fillreturns.Analyzer, "a", "typeparams")
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
package misc
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/tools/internal/testenv"
|
||||
|
@ -18,9 +16,7 @@ func TestStaticcheckGenerics(t *testing.T) {
|
|||
testenv.NeedsGo1Point(t, 20) // staticcheck requires go1.20+
|
||||
|
||||
// TODO(golang/go#65249): re-enable and fix this test with gotypesalias=1.
|
||||
if strings.Contains(os.Getenv("GODEBUG"), "gotypesalias=1") {
|
||||
t.Skipf("staticcheck needs updates for materialized aliases")
|
||||
}
|
||||
testenv.SkipMaterializedAliases(t, "staticcheck needs updates for materialized aliases")
|
||||
|
||||
const files = `
|
||||
-- go.mod --
|
||||
|
@ -88,9 +84,7 @@ func TestStaticcheckRelatedInfo(t *testing.T) {
|
|||
testenv.NeedsGo1Point(t, 20) // staticcheck is only supported at Go 1.20+
|
||||
|
||||
// TODO(golang/go#65249): re-enable and fix this test with gotypesalias=1.
|
||||
if strings.Contains(os.Getenv("GODEBUG"), "gotypesalias=1") {
|
||||
t.Skipf("staticcheck needs updates for materialized aliases")
|
||||
}
|
||||
testenv.SkipMaterializedAliases(t, "staticcheck needs updates for materialized aliases")
|
||||
|
||||
const files = `
|
||||
-- go.mod --
|
||||
|
|
|
@ -16,7 +16,7 @@ import (
|
|||
// NewAlias creates a new TypeName in Package pkg that
|
||||
// is an alias for the type rhs.
|
||||
//
|
||||
// When GoVersion>=1.22 and GODEBUG=gotypesalias=1,
|
||||
// When GoVersion>=1.22 and GODEBUG=gotypesalias=1 (or unset),
|
||||
// the Type() of the return value is a *types.Alias.
|
||||
func NewAlias(pos token.Pos, pkg *types.Package, name string, rhs types.Type) *types.TypeName {
|
||||
if enabled() {
|
||||
|
|
|
@ -20,7 +20,7 @@ var _ func(*aliases.Alias) *types.TypeName = (*aliases.Alias).Obj
|
|||
|
||||
// TestNewAlias tests that alias.NewAlias creates an alias of a type
|
||||
// whose underlying and Unaliased type is *Named.
|
||||
// When gotypesalias=1 and GoVersion >= 1.22, the type will
|
||||
// When gotypesalias=1 (or unset) and GoVersion >= 1.22, the type will
|
||||
// be an *aliases.Alias.
|
||||
func TestNewAlias(t *testing.T) {
|
||||
const source = `
|
||||
|
@ -46,7 +46,10 @@ func TestNewAlias(t *testing.T) {
|
|||
t.Fatalf("Eval(%s) failed: %v", expr, err)
|
||||
}
|
||||
|
||||
for _, godebug := range []string{"", "gotypesalias=1"} {
|
||||
for _, godebug := range []string{
|
||||
// "", // The default is in transition; suppress this case for now
|
||||
"gotypesalias=0",
|
||||
"gotypesalias=1"} {
|
||||
t.Run(godebug, func(t *testing.T) {
|
||||
t.Setenv("GODEBUG", godebug)
|
||||
|
||||
|
@ -62,7 +65,7 @@ func TestNewAlias(t *testing.T) {
|
|||
t.Errorf("Expected Unalias(A)==%q. got %q", want, got)
|
||||
}
|
||||
|
||||
if testenv.Go1Point() >= 22 && godebug == "gotypesalias=1" {
|
||||
if testenv.Go1Point() >= 22 && godebug != "gotypesalias=0" {
|
||||
if _, ok := A.Type().(*aliases.Alias); !ok {
|
||||
t.Errorf("Expected A.Type() to be a types.Alias(). got %q", A.Type())
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"reflect"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -190,3 +191,22 @@ func Command(t testing.TB, name string, args ...string) *exec.Cmd {
|
|||
t.Helper()
|
||||
return CommandContext(t, context.Background(), name, args...)
|
||||
}
|
||||
|
||||
// SkipMaterializedAliases skips the test if go/types would create
|
||||
// instances of types.Alias, which some tests do not yet handle
|
||||
// correctly.
|
||||
func SkipMaterializedAliases(t *testing.T, message string) {
|
||||
if hasMaterializedAliases(Go1Point()) {
|
||||
t.Skipf("%s", message)
|
||||
}
|
||||
}
|
||||
|
||||
func hasMaterializedAliases(minor int) bool {
|
||||
if minor >= 23 && !strings.Contains(os.Getenv("GODEBUG"), "gotypesalias=0") {
|
||||
return true // gotypesalias=1 became the default in go1.23
|
||||
}
|
||||
if minor == 22 && strings.Contains(os.Getenv("GODEBUG"), "gotypesalias=1") {
|
||||
return true // gotypesalias=0 was the default in go1.22
|
||||
}
|
||||
return false // types.Alias didn't exist in go1.21
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче