Skip to content

Commit

Permalink
x/tools: make tests agnostic as to whether gotypesalias="" => 0 or 1
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
adonovan authored and gopherbot committed Apr 12, 2024
1 parent e81c307 commit 78889ab
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions internal/testenv/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"reflect"
"runtime"
"strconv"
"strings"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -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
}

0 comments on commit 78889ab

Please sign in to comment.