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: test binaries ignore -short and -v options #28463

Closed
dobegor opened this issue Oct 29, 2018 · 5 comments
Closed

cmd/go: test binaries ignore -short and -v options #28463

dobegor opened this issue Oct 29, 2018 · 5 comments
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.

Comments

@dobegor
Copy link

dobegor commented Oct 29, 2018

go test -c produces binary that ignores -test.short and -test.v

What version of Go are you using (go version

go version go1.11.1 darwin/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="/Users/dobegor/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/dobegor/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/9h/8ghw84gx02l6__ryvxp4yzwh0000gn/T/go-build622504579=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

m_test.go:

package main

import (
	"fmt"
	"testing"
)

func TestBug(t *testing.T) {
	if testing.Short() {
		t.Skip("skipping test")
	}

	fmt.Println("this should not happen")
}

Then:

go test -c -test.v -test.short -o test
./test

What did you expect to see?

=== RUN   TestBug
--- SKIP: TestBug (0.00s)
    m_test.go:10: skipping test
PASS
ok  	temp	0.005s

What did you see instead?

this should not happen
PASS
@mvdan
Copy link
Member

mvdan commented Oct 29, 2018

You're misusing the -c flag - you should instead do:

go test -c -o test
./test -test.short -test.v

Perhaps the -c flag should give an error if any other test flags are given but take zero effect, since the tests aren't actually run.

@mvdan mvdan added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Oct 29, 2018
@dobegor
Copy link
Author

dobegor commented Oct 29, 2018

I've forgot to replace the command in my steps to reproduce. I did use -test.short with same result. I'll update issue description.

@dobegor
Copy link
Author

dobegor commented Oct 29, 2018

Also, I don't think returning an error if -c flag is set is a right solution - there's no reason -test.short flag shouldn't work in a compiled binary.

That also breaks the use case of IDEs - in my case GoLand - it compiles the test via -c flag and runs it via go tool test2json to obtain a parse-able test output in order to correctly display it.

@mvdan
Copy link
Member

mvdan commented Oct 29, 2018

What I meant is that go test -c -short should be an error, since the -short doesn't actually do anything there. It should be used on the binary itself.

When you update the commands you ran to encounter the issue, please include a Go source file or repository to reproduce the problem too. I can't reproduce it on a package of mine.

@dobegor
Copy link
Author

dobegor commented Oct 29, 2018

I've figured out that passing -test.short to the compiled binary actually works. I'll close this issue as it's incorrect.

Thanks for pointing out!

@dobegor dobegor closed this as completed Oct 29, 2018
@golang golang locked and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

3 participants