You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
testing: Reuse of exported var name when using . import panics #10942
anacrolix@Matts-MBP:~/gopath/src/github.com/anacrolix/torrent$ go test .
2015/05/24 21:27:41 expvar.go:254: Reuse of exported var name: unusedDownloadedChunksCount
panic: Reuse of exported var name: unusedDownloadedChunksCount
The generated main package will import "torrent",
but the test file imports the same package under
a different import path ("."), as Go uses import
paths to differentiate packages, one package imported
under two import paths will be treated as two different
packages and thus it's init will be called twice.
That's also the reason why symlinks are not allowed
in GOPATH.
Do not use "." to import a package in a test.
A simple example:
// t.go
package t
var A int
func init() {
println("init called")
}
// t_test.go
package t_test
import (
t "."
"testing"
)
var _ = t.A
func TestA(t *testing.T) {}
$ go test -v
init called
init called
=== RUN TestA
--- PASS: TestA (0.00s)
PASS
ok t 0.002s
changed the title [-]Reuse of exported var name when using . import panics[/-][+]testing: Reuse of exported var name when using . import panics[/+]on May 26, 2015
Activity
minux commentedon May 24, 2015
It's working as intended.
The generated main package will import "torrent",
but the test file imports the same package under
a different import path ("."), as Go uses import
paths to differentiate packages, one package imported
under two import paths will be treated as two different
packages and thus it's init will be called twice.
That's also the reason why symlinks are not allowed
in GOPATH.
Do not use "." to import a package in a test.
A simple example:
// t.go
package t
var A int
func init() {
println("init called")
}
// t_test.go
package t_test
import (
t "."
"testing"
)
var _ = t.A
func TestA(t *testing.T) {}
$ go test -v
init called
init called
=== RUN TestA
--- PASS: TestA (0.00s)
PASS
ok t 0.002s
[-]Reuse of exported var name when using . import panics[/-][+]testing: Reuse of exported var name when using . import panics[/+]anacrolix commentedon Jun 17, 2015
https://github.com/golang/go/blob/master/src/strings/search_test.go#L9