1 // Copyright 2015 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.
15 "golang.org/x/tools/go/packages/packagestest"
18 func TestBundle(t *testing.T) { packagestest.TestAll(t, testBundle) }
19 func testBundle(t *testing.T, x packagestest.Exporter) {
20 load := func(name string) string {
21 data, err := ioutil.ReadFile(name)
28 e := packagestest.Export(t, x, []packagestest.Module{
31 Files: map[string]interface{}{
32 "a.go": load("testdata/src/initial/a.go"),
33 "b.go": load("testdata/src/initial/b.go"),
34 "c.go": load("testdata/src/initial/c.go"),
38 Name: "domain.name/importdecl",
39 Files: map[string]interface{}{
40 "p.go": load("testdata/src/domain.name/importdecl/p.go"),
45 testingOnlyPackagesConfig = e.Config
47 os.Args = os.Args[:1] // avoid e.g. -test=short in the output
48 out, err := bundle("initial", "github.com/dest", "dest", "prefix", "tag")
53 if got, want := string(out), load("testdata/out.golden"); got != want {
54 t.Errorf("-- got --\n%s\n-- want --\n%s\n-- diff --", got, want)
56 if err := ioutil.WriteFile("testdata/out.got", out, 0644); err != nil {
59 t.Log(diff("testdata/out.golden", "testdata/out.got"))
63 func diff(a, b string) string {
67 cmd = exec.Command("/bin/diff", "-c", a, b)
69 cmd = exec.Command("/usr/bin/diff", "-u", a, b)
74 cmd.Run() // nonzero exit is expected
76 return "(failed to compute diff)"