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: go test -list does things other than listing tests #25339

Open
echlebek opened this Issue May 10, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@echlebek

echlebek commented May 10, 2018

This is a small quibble, but caused me some surprise recently.

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

go version go1.10.2 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/eric/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/eric/go"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
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-build753721336=/tmp/go-build -gno-record-gcc-switches"

What did you do?

foo_test.go

package foo

import (
	"fmt"
	"testing"
)

func init() {
	fmt.Println("Hello, world!")
}

func TestFoo(t *testing.T) {}
$ go test -list=TestFoo

What did you expect to see?

TestFoo

What did you see instead?

Hello, world!
TestFoo
ok  	github.com/echlebek/foo	0.001s

In #17209, Nemith proposes that go test -list would list the tests, but no tests would be run or any other operation.

I think that since it can be statically determined what the tests in a package are, the -list functionality should not depend on executing the test binary.

@ianlancetaylor ianlancetaylor changed the title from go test -list does things other than listing tests to cmd/go: go test -list does things other than listing tests May 10, 2018

@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented May 10, 2018

Perhaps it was a mistake to add a -test.list option to test binaries. Now that we've done that, it seems clearly desirable for go test -list and go test -c; ./pkg.test -test.list do the same thing.

@vedujoshi

This comment has been minimized.

vedujoshi commented May 17, 2018

Same issue was seen with below code as well...when asked to list, BeforeSuite() and AfterSuite() methods too get called

func TestMain(m *testing.M) {
	BeforeSuite()
	exitCode := m.Run()
	AfterSuite()
	os.Exit(exitCode)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment