File: gcimporter17_test.go

package info (click to toggle)
golang-golang-x-tools 1%3A0.0~git20161028.0.b814a3b%2Bds-3~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 5,644 kB
  • sloc: yacc: 155; sh: 95; makefile: 27; asm: 18; xml: 11; ansic: 10
file content (52 lines) | stat: -rw-r--r-- 1,468 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// 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.7,!go1.8

package gcimporter

import (
	"fmt"
	"os"
	"os/exec"
	"path/filepath"
	"runtime"
	"testing"
)

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 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)
		}
	}
}