From 4c3c0f68c510f59809e79f5a61116dbbf0449032 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 28 Aug 2014 15:19:30 -0700 Subject: [PATCH] go.tools/go/importer: use platform-specific word size in tests Hopefully Fixes golang/go#8366. LGTM=adonovan R=adonovan CC=golang-codereviews https://golang.org/cl/138810043 --- go/importer/import_test.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/go/importer/import_test.go b/go/importer/import_test.go index 14d218ae003..a14efd0b2f8 100644 --- a/go/importer/import_test.go +++ b/go/importer/import_test.go @@ -16,6 +16,7 @@ import ( "path/filepath" "runtime" "sort" + "strconv" "testing" "time" @@ -127,6 +128,12 @@ func TestImportStdLib(t *testing.T) { } size, gcsize := testExportImport(t, pkg, lib) + if gcsize == 0 { + // if gc import didn't happen, assume same size + // (and avoid division by zero below) + gcsize = size + } + if testing.Verbose() { fmt.Printf("%s\t%d\t%d\t%d%%\n", lib, size, gcsize, int(float64(size)*100/float64(gcsize))) } @@ -194,7 +201,15 @@ func pkgForSource(src string) (*types.Package, error) { } // typecheck file - return types.Check("import-test", fset, []*ast.File{f}) + conf := types.Config{ + // strconv exports IntSize as a constant. The type-checker must + // use the same word size otherwise the result of the type-checker + // and gc imports is different. We don't care about alignment + // since none of the tests have exported constants depending + // on alignment (see also issue 8366). + Sizes: &types.StdSizes{WordSize: strconv.IntSize / 8, MaxAlign: 8}, + } + return conf.Check("import-test", fset, []*ast.File{f}, nil) } func pkgForPath(path string) (*types.Package, error) {