Skip to content

Commit 6c47868

Browse files
timothy-kingGo LUCI
authored andcommitted
internal/gcimporter: run larger tests with and without aliases
Run larger and standard library tests both with and without the gotypesaliases GODEBUG enabled. Skips two know failures on 1.22. Fixes an incorrectly copied constant in an expectation. Change-Id: I8054bf5609b7a0e6fb544bd906a00f2f02f75b31 Reviewed-on: https://go-review.googlesource.com/c/tools/+/616157 Reviewed-by: Alan Donovan <[email protected]> Reviewed-by: Robert Findley <[email protected]> Commit-Queue: Tim King <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent c6f2f8e commit 6c47868

File tree

5 files changed

+58
-2
lines changed

5 files changed

+58
-2
lines changed

internal/gcimporter/gcimporter_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ func TestImportTestdata(t *testing.T) {
120120
needsCompiler(t, "gc")
121121
testenv.NeedsGoBuild(t) // to find stdlib export data in the build cache
122122

123+
testAliases(t, testImportTestdata)
124+
}
125+
126+
func testImportTestdata(t *testing.T) {
123127
tmpdir := mktmpdir(t)
124128
defer os.RemoveAll(tmpdir)
125129

@@ -168,9 +172,22 @@ func TestImportTypeparamTests(t *testing.T) {
168172
t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler)
169173
}
170174

175+
testAliases(t, testImportTypeparamTests)
176+
}
177+
178+
func testImportTypeparamTests(t *testing.T) {
171179
tmpdir := mktmpdir(t)
172180
defer os.RemoveAll(tmpdir)
173181

182+
// GoVersion -> GoDebug -> filename -> reason to skip
183+
skips := map[int]map[string]map[string]string{
184+
22: {aliasesOn: {
185+
"issue50259.go": "internal compiler error: unexpected types2.Invalid",
186+
"struct.go": "badly formatted expectation E[int]",
187+
}},
188+
}
189+
dbg, version := os.Getenv("GODEBUG"), testenv.Go1Point()
190+
174191
// Check go files in test/typeparam, except those that fail for a known
175192
// reason.
176193
rootDir := filepath.Join(runtime.GOROOT(), "test", "typeparam")
@@ -186,6 +203,11 @@ func TestImportTypeparamTests(t *testing.T) {
186203
}
187204

188205
t.Run(entry.Name(), func(t *testing.T) {
206+
if reason := skips[version][dbg][entry.Name()]; reason != "" {
207+
t.Skipf("Skipping file %q with GODEBUG=%q due to %q at version 1.%d",
208+
entry.Name(), dbg, reason, version)
209+
}
210+
189211
filename := filepath.Join(rootDir, entry.Name())
190212
src, err := os.ReadFile(filename)
191213
if err != nil {
@@ -333,6 +355,10 @@ func TestImportStdLib(t *testing.T) {
333355
needsCompiler(t, "gc")
334356
testenv.NeedsGoBuild(t) // to find stdlib export data in the build cache
335357

358+
testAliases(t, testImportStdLib)
359+
}
360+
361+
func testImportStdLib(t *testing.T) {
336362
// Get list of packages in stdlib. Filter out test-only packages with {{if .GoFiles}} check.
337363
var stderr bytes.Buffer
338364
cmd := exec.Command("go", "list", "-f", "{{if .GoFiles}}{{.ImportPath}}{{end}}", "std")
@@ -1001,3 +1027,16 @@ const (
10011027
aliasesOff = "gotypesalias=0" // default GODEBUG in 1.22 (like x/tools)
10021028
aliasesOn = "gotypesalias=1" // default after 1.23
10031029
)
1030+
1031+
// testAliases runs f within subtests with the GODEBUG gotypesalias enables and disabled.
1032+
func testAliases(t *testing.T, f func(*testing.T)) {
1033+
for _, dbg := range []string{
1034+
aliasesOff,
1035+
aliasesOn,
1036+
} {
1037+
t.Run(dbg, func(t *testing.T) {
1038+
t.Setenv("GODEBUG", dbg)
1039+
f(t)
1040+
})
1041+
}
1042+
}

internal/gcimporter/iexport_go118_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ func testExportSrc(t *testing.T, src []byte) {
9999
func TestIndexedImportTypeparamTests(t *testing.T) {
100100
testenv.NeedsGoBuild(t) // to find stdlib export data in the build cache
101101

102+
testAliases(t, testIndexedImportTypeparamTests)
103+
}
104+
105+
func testIndexedImportTypeparamTests(t *testing.T) {
102106
// Check go files in test/typeparam.
103107
rootDir := filepath.Join(runtime.GOROOT(), "test", "typeparam")
104108
list, err := os.ReadDir(rootDir)

internal/gcimporter/iexport_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ func TestIExportData_stdlib(t *testing.T) {
4747
t.Skip("skipping RAM hungry test in -short mode")
4848
}
4949

50+
testAliases(t, testIExportData_stdlib)
51+
}
52+
53+
func testIExportData_stdlib(t *testing.T) {
5054
var errorsDir string // GOROOT/src/errors directory
5155
{
5256
cfg := packages.Config{
@@ -105,7 +109,7 @@ type UnknownType undefined
105109
})
106110

107111
// Assert that we saw a plausible sized library.
108-
const minStdlibPackages = 284
112+
const minStdlibPackages = 248
109113
if n := len(allPkgs); n < minStdlibPackages {
110114
t.Errorf("Loaded only %d packages, want at least %d", n, minStdlibPackages)
111115
}
@@ -225,6 +229,9 @@ func TestIExportData_long(t *testing.T) {
225229
}
226230

227231
func TestIExportData_typealiases(t *testing.T) {
232+
testAliases(t, testIExportData_typealiases)
233+
}
234+
func testIExportData_typealiases(t *testing.T) {
228235
// parse and typecheck
229236
fset1 := token.NewFileSet()
230237
f, err := parser.ParseFile(fset1, "p.go", src, 0)

internal/gcimporter/shallow_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ func TestShallowStd(t *testing.T) {
2727
}
2828
testenv.NeedsTool(t, "go")
2929

30+
testAliases(t, testShallowStd)
31+
}
32+
func testShallowStd(t *testing.T) {
3033
// Load import graph of the standard library.
3134
// (No parsing or type-checking.)
3235
cfg := &packages.Config{

internal/gcimporter/stdlib_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ import (
1919
)
2020

2121
// TestStdlib ensures that all packages in std and x/tools can be
22-
// type-checked using export data. Takes around 3s.
22+
// type-checked using export data.
2323
func TestStdlib(t *testing.T) {
2424
testenv.NeedsGoPackages(t)
2525

26+
testAliases(t, testStdlib)
27+
}
28+
func testStdlib(t *testing.T) {
2629
// gcexportdata.Read rapidly consumes FileSet address space,
2730
// so disable the test on 32-bit machines.
2831
// (We could use a fresh FileSet per type-check, but that

0 commit comments

Comments
 (0)