go/gcimporter15: only test binary export when running against Go 1.6
Also: rename setname15.go to setname.go for consistency Change-Id: I3f7e37ef4ade716ce64674edb4d53a543a1150c5 Reviewed-on: https://go-review.googlesource.com/18772 Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
parent
e6d5370703
commit
7912bef4df
|
@ -87,20 +87,6 @@ func compile(t *testing.T, dirname, filename string) string {
|
|||
return filepath.Join(dirname, filename[:len(filename)-2]+"o")
|
||||
}
|
||||
|
||||
// TODO(gri) Remove this function once we switched to new export format by default.
|
||||
func compileNewExport(t *testing.T, dirname, filename string) string {
|
||||
/* testenv. */ MustHaveGoBuild(t)
|
||||
cmd := exec.Command("go", "tool", "compile", "-newexport", filename)
|
||||
cmd.Dir = dirname
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
t.Logf("%s", out)
|
||||
t.Fatalf("go tool compile %s failed: %s", filename, err)
|
||||
}
|
||||
// filename should end with ".go"
|
||||
return filepath.Join(dirname, filename[:len(filename)-2]+"o")
|
||||
}
|
||||
|
||||
func testPath(t *testing.T, path, srcDir string) *types.Package {
|
||||
t0 := time.Now()
|
||||
pkg, err := Import(make(map[string]*types.Package), path, srcDir)
|
||||
|
@ -171,31 +157,6 @@ func TestImportTestdata(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO(gri) Remove this function once we switched to new export format by default
|
||||
// (and update the comment and want list in TestImportTestdata).
|
||||
func TestImportTestdataNewExport(t *testing.T) {
|
||||
// This package only handles gc export data.
|
||||
if runtime.Compiler != "gc" {
|
||||
t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler)
|
||||
return
|
||||
}
|
||||
|
||||
if outFn := compileNewExport(t, "testdata", "exports.go"); outFn != "" {
|
||||
defer os.Remove(outFn)
|
||||
}
|
||||
|
||||
if pkg := testPath(t, "./testdata/exports", "."); pkg != nil {
|
||||
// The package's Imports list must include all packages
|
||||
// explicitly imported by exports.go, plus all packages
|
||||
// referenced indirectly via exported objects in exports.go.
|
||||
want := `[package ast ("go/ast") package token ("go/token")]`
|
||||
got := fmt.Sprint(pkg.Imports())
|
||||
if got != want {
|
||||
t.Errorf(`Package("exports").Imports() = %s, want %s`, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestImportStdLib(t *testing.T) {
|
||||
skipSpecialPlatforms(t)
|
||||
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
// 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.
|
||||
|
||||
// +build go1.6
|
||||
|
||||
package gcimporter
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TODO(gri) Remove this function once we switched to new export format by default.
|
||||
func compileNewExport(t *testing.T, dirname, filename string) string {
|
||||
/* testenv. */ MustHaveGoBuild(t)
|
||||
cmd := exec.Command("go", "tool", "compile", "-newexport", filename)
|
||||
cmd.Dir = dirname
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
t.Logf("%s", out)
|
||||
t.Fatalf("go tool compile %s failed: %s", filename, err)
|
||||
}
|
||||
// filename should end with ".go"
|
||||
return filepath.Join(dirname, filename[:len(filename)-2]+"o")
|
||||
}
|
||||
|
||||
// TODO(gri) Remove this function once we switched to new export format by default
|
||||
// (and update the comment and want list in TestImportTestdata).
|
||||
func TestImportTestdataNewExport(t *testing.T) {
|
||||
// This package only handles gc export data.
|
||||
if runtime.Compiler != "gc" {
|
||||
t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler)
|
||||
return
|
||||
}
|
||||
|
||||
if outFn := compileNewExport(t, "testdata", "exports.go"); outFn != "" {
|
||||
defer os.Remove(outFn)
|
||||
}
|
||||
|
||||
if pkg := testPath(t, "./testdata/exports", "."); pkg != nil {
|
||||
// The package's Imports list must include all packages
|
||||
// explicitly imported by exports.go, plus all packages
|
||||
// referenced indirectly via exported objects in exports.go.
|
||||
want := `[package ast ("go/ast") package token ("go/token")]`
|
||||
got := fmt.Sprint(pkg.Imports())
|
||||
if got != want {
|
||||
t.Errorf(`Package("exports").Imports() = %s, want %s`, got, want)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue