FAQ
Hi gophers,

I had been using symlinks from my GOPATH to disparate projects, to:

- allow a single project repo per-project which mixes golang and other code
(so the golang code doesn't have a single repo of it's own)
- avoid the need for an ever-growing GOPATH with one entry per project

I hit a problem (details below) and have subsequently discovered that
symlinks from GOPATH are not supported - so I'm now using multiple-entry
GOPATH to support the "golang code in a larger repo" use case.


I'm posting to describe a failure mode in this case, which was sufficiently
interesting to me that I think some might consider it a tooling bug. If
others agree, please let me know and I'll raise an issue. Even if not, I
scratched my head long enough that describing the symptoms here might help
someone else chasing the same problem.


Basically in this case (symlink from GOPATH to code), go test fails to
detect a test-only import cycle.

This can mean we end up "successfully" compiling with the cycle in place,
resulting in running code which is sufficiently confused about types that
whether type-asserting succeeds or not depends on which package you do it
in. If you do an unchecked type assertion you can get a nicely confusing
panic: "interface is foo.Quux, not foo.Quux".

Steps to reproduce below.

regards,

jb

# Pretend our golang code is part of a larger repo
mkdir -p proj/foo proj/bar
cat << EOF > proj/foo/foo.go
package foo

type Quux int
EOF
cat << EOF > proj/foo/foo_test.go
package foo

import (
         "proj/bar"
         "testing"
)

func TestFoo(t *testing.T) {
         var i interface{}
         i = Quux(10)
         bar.DoBar(i)
}
EOF
cat << EOF > proj/bar/bar.go
package bar

import (
         "proj/foo"
         "fmt"
)

func DoBar(i interface{}) {
         q := i.(foo.Quux)
         fmt.Printf("q has type %T\n", q) // not reached - panic on previous
line
}
EOF
# Symlink from GOPATH (assumes you have single-entry GOPATH)
ln -s $PWD/proj $GOPATH/src/proj
# Run your tests...
cd proj
go test -v ./foo


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 3 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedNov 20, '14 at 6:09p
activeNov 21, '14 at 3:58p
posts3
users2
websitegolang.org

2 users in discussion

John Berthels: 2 posts Jan Mercl: 1 post

People

Translate

site design / logo © 2022 Grokbase