1
0
mirror of https://github.com/golang/go synced 2024-11-18 19:24:39 -07:00

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
This commit is contained in:
Robert Griesemer 2014-08-28 15:19:30 -07:00
parent cd91e8d096
commit 4c3c0f68c5

View File

@ -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) {