Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(434)

Unified Diff: src/pkg/go/types/gcimporter_test.go

Issue 4314054: code review 4314054: go/types: New Go type hierarchy implementation for AST. (Closed)
Patch Set: diff -r ebef2da9ab43 https://go.googlecode.com/hg/ Created 13 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/pkg/go/types/gcimporter.go ('k') | src/pkg/go/types/testdata/exports.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pkg/go/types/gcimporter_test.go
===================================================================
new file mode 100644
--- /dev/null
+++ b/src/pkg/go/types/gcimporter_test.go
@@ -0,0 +1,106 @@
+// Copyright 2011 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package types
+
+import (
+ "exec"
+ "io/ioutil"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+ "time"
+)
+
+
+var gcName, gcPath string // compiler name and path
+
+func init() {
+ // find a compiler
+ for _, char := range []string{"5", "6", "8"} {
+ var err os.Error
+ gcName = char + "g"
+ gcPath, err = exec.LookPath(gcName)
+ if err == nil {
+ return
+ }
+ }
+}
+
+
+func compile(t *testing.T, dirname, filename string) {
+ cmd, err := exec.Run(gcPath, []string{gcPath, filename}, nil, dirname, exec.DevNull, exec.Pipe, exec.MergeWithStdout)
+ if err != nil {
+ t.Errorf("%s %s failed: %s", gcName, filename, err)
+ return
+ }
+ defer cmd.Close()
+
+ msg, err := cmd.Wait(0)
+ if err != nil {
+ t.Errorf("%s %s failed: %s", gcName, filename, err)
+ return
+ }
+
+ if !msg.Exited() || msg.ExitStatus() != 0 {
+ t.Errorf("%s %s failed: exit status = %d", gcName, filename, msg.ExitStatus())
+ output, _ := ioutil.ReadAll(cmd.Stdout)
+ t.Log(string(output))
+ }
+}
+
+
+func testPath(t *testing.T, path string) bool {
+ _, _, err := GcImporter(path)
+ if err != nil {
+ t.Errorf("testPath(%s): %s", path, err)
+ return false
+ }
+ return true
+}
+
+
+const maxTime = 3e9 // maximum allotted testing time in ns
+
+func testDir(t *testing.T, dir string, endTime int64) (nimports int) {
+ dirname := filepath.Join(pkgRoot, dir)
+ list, err := ioutil.ReadDir(dirname)
+ if err != nil {
+ t.Errorf("testDir(%s): %s", dirname, err)
+ }
+ for _, f := range list {
+ if time.Nanoseconds() >= endTime {
+ t.Log("testing time used up")
+ return
+ }
+ switch {
+ case f.IsRegular():
+ // try extensions
+ for _, ext := range pkgExts {
+ if strings.HasSuffix(f.Name, ext) {
+ name := f.Name[0 : len(f.Name)-len(ext)] // remove extension
+ if testPath(t, filepath.Join(dir, name)) {
+ nimports++
+ }
+ }
+ }
+ case f.IsDirectory():
+ nimports += testDir(t, filepath.Join(dir, f.Name), endTime)
+ }
+ }
+ return
+}
+
+
+func TestGcImport(t *testing.T) {
+ compile(t, "testdata", "exports.go")
+
+ nimports := 0
+ if testPath(t, "./testdata/exports") {
+ nimports++
+ }
+ nimports += testDir(t, "", time.Nanoseconds()+maxTime) // installed packages
+ t.Logf("tested %d imports", nimports)
+}
« no previous file with comments | « src/pkg/go/types/gcimporter.go ('k') | src/pkg/go/types/testdata/exports.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b