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

cmd/go: go test -list does things other than listing tests #25339

Open
echlebek opened this issue May 10, 2018 · 3 comments
Open

cmd/go: go test -list does things other than listing tests #25339

echlebek opened this issue May 10, 2018 · 3 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@echlebek
Copy link

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 go test -list does things other than listing tests cmd/go: go test -list does things other than listing tests May 10, 2018
@ianlancetaylor
Copy link
Contributor

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.

@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 10, 2018
@ianlancetaylor ianlancetaylor added this to the Unplanned milestone May 10, 2018
@vedujoshi
Copy link

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)
}

@fredrikaverpil
Copy link

fredrikaverpil commented Apr 15, 2024

This problem has existed for quite some time: #17209

But yes, it would be super useful to have tests listed (not executed) even if the subtests/table tests cannot be found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants