mirror of
https://github.com/golang/go
synced 2024-11-18 09:04:49 -07:00
cmd/bundle: fix broken test
Change-Id: I95bd6cd1b63a1d1b5bd255546fbf571010a67266 Reviewed-on: https://go-review.googlesource.com/19745 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
9aae8f06b5
commit
f7268ab39b
@ -159,7 +159,10 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
code := bundle(args[0], *dstPath, *pkgName, *prefix)
|
||||
code, err := bundle(args[0], *dstPath, *pkgName, *prefix)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if *outputFile != "" {
|
||||
err := ioutil.WriteFile(*outputFile, code, 0666)
|
||||
if err != nil {
|
||||
@ -175,7 +178,7 @@ func main() {
|
||||
|
||||
var ctxt = &build.Default
|
||||
|
||||
func bundle(src, dst, dstpkg, prefix string) []byte {
|
||||
func bundle(src, dst, dstpkg, prefix string) ([]byte, error) {
|
||||
// Load the initial package.
|
||||
conf := loader.Config{ParserMode: parser.ParseComments, Build: ctxt}
|
||||
conf.TypeCheckFuncBodies = func(p string) bool { return p == src }
|
||||
@ -183,7 +186,7 @@ func bundle(src, dst, dstpkg, prefix string) []byte {
|
||||
|
||||
lprog, err := conf.Load()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := lprog.Package(src)
|
||||
@ -251,7 +254,7 @@ func bundle(src, dst, dstpkg, prefix string) []byte {
|
||||
for _, f := range info.Files {
|
||||
for _, imp := range f.Imports {
|
||||
if imp.Name != nil {
|
||||
log.Fatalf("%s: renaming imports not supported",
|
||||
return nil, fmt.Errorf("%s: renaming imports not supported",
|
||||
lprog.Fset.Position(imp.Pos()))
|
||||
}
|
||||
}
|
||||
@ -326,7 +329,7 @@ func bundle(src, dst, dstpkg, prefix string) []byte {
|
||||
log.Fatalf("formatting failed: %v", err)
|
||||
}
|
||||
|
||||
return result
|
||||
return result, nil
|
||||
}
|
||||
|
||||
type flagFunc func(string)
|
||||
|
@ -7,6 +7,7 @@ package main
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"testing"
|
||||
@ -33,17 +34,18 @@ func TestBundle(t *testing.T) {
|
||||
},
|
||||
})
|
||||
|
||||
var out bytes.Buffer
|
||||
if err := bundle(&out, "initial", "dest", "prefix"); err != nil {
|
||||
os.Args = os.Args[:1] // avoid e.g. -test=short in the output
|
||||
out, err := bundle("initial", "github.com/dest", "dest", "prefix")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got, want := out.String(), load("testdata/out.golden"); got != want {
|
||||
if got, want := string(out), load("testdata/out.golden"); got != want {
|
||||
t.Errorf("-- got --\n%s\n-- want --\n%s\n-- diff --", got, want)
|
||||
|
||||
if err := ioutil.WriteFile("testdata/out.got", out.Bytes(), 0644); err != nil {
|
||||
if err := ioutil.WriteFile("testdata/out.got", out, 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(diff("testdata/out.got", "testdata/out.golden"))
|
||||
t.Log(diff("testdata/out.golden", "testdata/out.got"))
|
||||
}
|
||||
}
|
||||
|
||||
|
4
cmd/bundle/testdata/out.golden
vendored
4
cmd/bundle/testdata/out.golden
vendored
@ -1,5 +1,5 @@
|
||||
// Code generated by golang.org/x/tools/cmd/bundle command:
|
||||
// $ bundle initial dest prefix
|
||||
// Code generated by golang.org/x/tools/cmd/bundle.
|
||||
// $ bundle
|
||||
|
||||
// The package doc comment
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user