New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/go: main_test must depend on main.a, not main binary #3417
Labels
Milestone
Comments
I just encountered this problem again. Here's the output of go test -v -x: % go test -v -x WORK=/tmp/go-build386097667 mkdir -p $WORK/launchpad.net/juju/go/cmd/juju/_test/launchpad.net/juju/go/cmd/ mkdir -p $WORK/launchpad.net/juju/go/cmd/juju/_test/ cd /home/rog/src/go/src/launchpad.net/juju/go/cmd/juju /home/rog/go/pkg/tool/linux_amd64/6g -o $WORK/launchpad.net/juju/go/cmd/juju/_test/_go_.6 -p launchpad.net/juju/go/cmd/juju_test -D _/home/rog/src/go/src/launchpad.net/juju/go/cmd/juju -I $WORK -I /home/rog/src/go/pkg/linux_amd64 ./cmd_test.go ./main_test.go # launchpad.net/juju/go/cmd/juju_test ./cmd_test.go:7: can't find import: "launchpad.net/juju/go/cmd/juju" $WORK/launchpad.net/juju/go/cmd/juju/_test/juju.test -test.v=true FAIL launchpad.net/juju/go/cmd/juju [build failed] % i've archived my $GOPATH directory in the hope that i might be able to reproduce the problem later. |
The presence of the -D_... option suggests that the go command believes you are outside the go root and any GOPATH directories. Instead of go test -v -x what does 'go list -json' say? Specifically, what does the Root field say? If it is "", that confirms my theory. And yet the output line beginning with # makes clear that at least part of the go command believes that you are in a directory with a root. Is it possible that there is a stale juju directory tree earlier in your GOPATH or in the GOROOT itself? In that situation the go command does try to avoid believing that the current directory might be the canonical juju package (since it is shadowed by that other one). |
unfortunately, and possibly significantly, unarchiving $GOPATH (inc. restoring mtimes) did not allow me to reproduce the issue. i should probably have archived $GOROOT too. i'll have to wait until i see the issue again. let's hope it's magically gone away forever. it's highly unlikely that the was a stale juju directory tree earlier in GOPATH or GOROOT. (i use a single directory in GOPATH, and there's nothing in GOROOT now and i haven't removed anything since then). if there *was*, then it seems to me that the issue would probably not be resolved by touching the files in the package directory, which it was; another indication that that's probably not the case. |
the issue just came up again. same directory, exactly the same symptoms as before. theory not validated, i'm afraid - Root is not empty. here's the output of go list -json. { "Dir": "/home/rog/src/go/src/launchpad.net/juju/go/cmd/juju", "ImportPath": "launchpad.net/juju/go/cmd/juju", "Name": "main", "Target": "/home/rog/src/go/bin/juju", "Root": "/home/rog/src/go", "GoFiles": [ "bootstrap.go", "destroy.go", "main.go" ], "Imports": [ "launchpad.net/gnuflag", "launchpad.net/juju/go/cmd", "launchpad.net/juju/go/environs/ec2", "launchpad.net/juju/go/juju", "os" ], "Deps": [ "archive/tar", "archive/zip", "bufio", "bytes", "compress/flate", "compress/gzip", "crypto", "crypto/aes", "crypto/cipher", "crypto/des", "crypto/dsa", "crypto/elliptic", "crypto/hmac", "crypto/md5", "crypto/rand", "crypto/rc4", "crypto/rsa", "crypto/sha1", "crypto/sha256", "crypto/subtle", "crypto/tls", "crypto/x509", "crypto/x509/pkix", "encoding/asn1", "encoding/base64", "encoding/binary", "encoding/hex", "encoding/pem", "encoding/xml", "errors", "fmt", "hash", "hash/crc32", "io", "io/ioutil", "launchpad.net/gnuflag", "launchpad.net/goamz/aws", "launchpad.net/goamz/ec2", "launchpad.net/goamz/s3", "launchpad.net/goyaml", "launchpad.net/gozk/zookeeper", "launchpad.net/juju/go/charm", "launchpad.net/juju/go/cloudinit", "launchpad.net/juju/go/cmd", "launchpad.net/juju/go/environs", "launchpad.net/juju/go/environs/ec2", "launchpad.net/juju/go/juju", "launchpad.net/juju/go/log", "launchpad.net/juju/go/schema", "launchpad.net/juju/go/state", "launchpad.net/juju/go/state/presence", "launchpad.net/juju/go/state/watcher", "launchpad.net/juju/go/version", "launchpad.net/mgo/bson", "launchpad.net/tomb", "log", "math", "math/big", "math/rand", "mime", "mime/multipart", "net", "net/http", "net/http/httputil", "net/textproto", "net/url", "os", "os/exec", "path", "path/filepath", "reflect", "regexp", "regexp/syntax", "runtime", "runtime/cgo", "runtime/debug", "sort", "strconv", "strings", "sync", "sync/atomic", "syscall", "time", "unicode", "unicode/utf8", "unsafe" ], "XTestGoFiles": [ "cmd_test.go", "main_test.go" ], "XTestImports": [ "flag", "fmt", "io/ioutil", "launchpad.net/gnuflag", "launchpad.net/gocheck", "launchpad.net/juju/go/cmd", "launchpad.net/juju/go/cmd/juju", "launchpad.net/juju/go/environs", "launchpad.net/juju/go/environs/dummy", "launchpad.net/juju/go/version", "os", "os/exec", "path/filepath", "reflect", "sort", "strings", "testing" ] } other info: % whatis GOPATH GOPATH=/home/rog/src/go % whatis GOROOT GOROOT=/home/rog/go % whatis GOBIN GOBIN: not found % |
I think this may be the way we're testing our main packages. Our package main tests declare themselves package main_test. Looking at the standard library, this practice appears to be unique. Adding a shim like this lucky(~/src/launchpad.net/juju/go/cmd/jujud) % more export_test.go package main // this file exists only to trick go test into creating a .a for this package. // works around https://golang.org/issue/3417 works around the issue for me. |
I believe this was caused by using package main_test to test commands. Since juju moved away from this practice, we have not seen the issue reoccur. I think this issue can be closed. For extra credit stopping go test from accepting main_test as a package name would probably prevent it reoccurring. |
See also issue #5198. |
The problem is that cmd/go does not distinguish the main.a from the generated binary. If the binary is up to date, it does not rebuild main.a, so main_test cannot import it. Here is a simple test case. g% cat foo.go package main func F() {} func main() {} g% cat foo_test.go package main_test import "testing" import . "foo" func Test1(t *testing.T) { F() } g% touch foo.go g% go test PASS ok foo 0.016s g% go install g% go test # foo_test ./foo_test.go:4: can't find import: "foo" FAIL foo [build failed] g% |
This issue was closed by revision 627d17c. Status changed to Fixed. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: