1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
18 var gcName, gcPath string // compiler name and path
22 switch runtime.GOARCH {
30 gcName = "unknown-GOARCH-compiler"
34 gcPath, _ = exec.LookPath(gcName)
37 func compile(t *testing.T, dirname, filename string) {
38 cmd := exec.Command(gcPath, filename)
40 out, err := cmd.CombinedOutput()
42 t.Errorf("%s %s failed: %s", gcName, filename, err)
45 t.Logf("%s", string(out))
48 // Use the same global imports map for all tests. The effect is
49 // as if all tested packages were imported into a single package.
50 var imports = make(map[string]*ast.Object)
52 func testPath(t *testing.T, path string) bool {
53 _, err := GcImporter(imports, path)
55 t.Errorf("testPath(%s): %s", path, err)
61 const maxTime = 3 * time.Second
63 func testDir(t *testing.T, dir string, endTime time.Time) (nimports int) {
64 dirname := filepath.Join(pkgRoot, dir)
65 list, err := ioutil.ReadDir(dirname)
67 t.Errorf("testDir(%s): %s", dirname, err)
69 for _, f := range list {
70 if time.Now().After(endTime) {
71 t.Log("testing time used up")
77 for _, ext := range pkgExts {
78 if strings.HasSuffix(f.Name(), ext) {
79 name := f.Name()[0 : len(f.Name())-len(ext)] // remove extension
80 if testPath(t, filepath.Join(dir, name)) {
86 nimports += testDir(t, filepath.Join(dir, f.Name()), endTime)
92 func TestGcImport(t *testing.T) {
93 compile(t, "testdata", "exports.go")
96 if testPath(t, "./testdata/exports") {
99 nimports += testDir(t, "", time.Now().Add(maxTime)) // installed packages
100 t.Logf("tested %d imports", nimports)