github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/x/tools/go/gcimporter15/gcimporter17_test.go (about) 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. 4 5 // +build go1.7 6 7 package gcimporter 8 9 import ( 10 "fmt" 11 "os" 12 "os/exec" 13 "path/filepath" 14 "runtime" 15 "testing" 16 ) 17 18 // TODO(gri) Remove this function once we switched to new export format by default. 19 func compileNewExport(t *testing.T, dirname, filename string) string { 20 /* testenv. */ MustHaveGoBuild(t) 21 cmd := exec.Command("go", "tool", "compile", "-newexport", filename) 22 cmd.Dir = dirname 23 out, err := cmd.CombinedOutput() 24 if err != nil { 25 t.Logf("%s", out) 26 t.Fatalf("go tool compile %s failed: %s", filename, err) 27 } 28 // filename should end with ".go" 29 return filepath.Join(dirname, filename[:len(filename)-2]+"o") 30 } 31 32 // TODO(gri) Remove this function once we switched to new export format by default 33 // (and update the comment and want list in TestImportTestdata). 34 func TestImportTestdataNewExport(t *testing.T) { 35 // This package only handles gc export data. 36 if runtime.Compiler != "gc" { 37 t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler) 38 return 39 } 40 41 if outFn := compileNewExport(t, "testdata", "exports.go"); outFn != "" { 42 defer os.Remove(outFn) 43 } 44 45 if pkg := testPath(t, "./testdata/exports", "."); pkg != nil { 46 // The package's Imports list must include all packages 47 // explicitly imported by exports.go, plus all packages 48 // referenced indirectly via exported objects in exports.go. 49 want := `[package ast ("go/ast") package token ("go/token")]` 50 got := fmt.Sprint(pkg.Imports()) 51 if got != want { 52 t.Errorf(`Package("exports").Imports() = %s, want %s`, got, want) 53 } 54 } 55 }