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

Test binary ignores arguments after the first unrecognized one #26561

Closed
Geod24 opened this issue Jul 24, 2018 · 2 comments
Closed

Test binary ignores arguments after the first unrecognized one #26561

Geod24 opened this issue Jul 24, 2018 · 2 comments

Comments

@Geod24
Copy link

Geod24 commented Jul 24, 2018

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

go version go1.10.3 darwin/amd64
Also tested on linux/amd64 with 1.10.3 and 1.9.0

Does this issue reproduce with the latest release?

Yes

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

Irrelevant, but:

GOARCH="amd64"
GOCACHE="/Users/geod24/Library/Caches/go-build"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/5l/cz1hkqt92nj3r44__pwfzdkm0000gn/T/go-build547748127=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do / expect to see / see instead?

TL;DR: The test binaries should not ignore arguments after the first unrecognized one, but only after --.

I built a test binary instrumented for code coverage.
I used the command go test -coverpkg=./... ./cmd -c -o experiment for building it.
I ran ./experiment some_argument -test.coverprofile=coverage.txt
=> No coverage.txt is generated
I ran ./experiment -test.coverprofile=coverage.txt some_argument
=> coverage.txt is generated as expected

The complete test, along with a more verbose description of my use case (integration tests with coverage reports integrated into a CI) is available in this Github repository.

@cznic
Copy link
Contributor

cznic commented Jul 24, 2018

From the flag package docs:

Flag parsing stops just before the first non-flag argument ("-" is a non-flag argument) or after the terminator "--".

(dup of #26104)

@Geod24
Copy link
Author

Geod24 commented Jul 24, 2018

I see, it comes from the package, hence why looking that the command documentation didn't yield any result. It's a rather odd behavior IMHO, but since it works as intended and is documented...

@Geod24 Geod24 closed this as completed Jul 24, 2018
@golang golang locked and limited conversation to collaborators Jul 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants