Skip to content
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

Can't find package test #39937

Closed
kstenerud opened this issue Jun 30, 2020 · 1 comment
Closed

Can't find package test #39937

kstenerud opened this issue Jun 30, 2020 · 1 comment

Comments

@kstenerud
Copy link

@kstenerud kstenerud commented Jun 30, 2020

What version of Go are you using (go version)?

$ go version
go version go1.14.4 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/karl/.cache/go-build"
GOENV="/home/karl/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/karl/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go-1.14"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go-1.14/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/karl/tmp/x/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build520807521=/tmp/go-build -gno-record-gcc-switches"

What did you do?

go.mod:

module x

go 1.14

main.go:

package main

main_test.go:

package main

import (
	"testing"
	"x/test"
)

func TestX(t *testing.T) {
	var x test.TEvent
	if x != 0 {
		t.Error("Not 0")
	}
}

test/common_test.go

package test

type TEvent int

test/hack.go:

package test

// Workaround for "no non-test Go files in x/test"

What did you expect to see?

I expected the tests to compile

What did you see instead?

# x [x.test]
./main_test.go:9:8: undefined: test.TEvent
FAIL	x [build failed]
@davecheney
Copy link
Contributor

@davecheney davecheney commented Jun 30, 2020

The underlying issue is when testing package A only the files in that package are compiled in testing mode--files ending in _test.go are included in the scope. In your case package test is imported, but common_test.go is not part of the import set because package test is not compiled in test mode.

nb. I say package A rather than package main because this is not specific to package main.

This is working as designed, although perhaps not how you intended. Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For asking questions, see:

@davecheney davecheney closed this Jun 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.