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 -bench ./subpackage tests current package instead #23053

Closed
mrwonko opened this issue Dec 8, 2017 · 5 comments
Closed

cmd/go: go test -bench ./subpackage tests current package instead #23053

mrwonko opened this issue Dec 8, 2017 · 5 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@mrwonko
Copy link

mrwonko commented Dec 8, 2017

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

go version go1.9.2 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=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/willi/code/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9.2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9.2/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/3r/dwl9v9356c53dhj71_xl28980000gn/T/go-build918572228=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
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"

What did you do?

go test -bench ./sortbenchmark/

What did you expect to see?

goos: darwin
goarch: amd64
pkg: github.com/mrwonko/goplayground/sortbenchmark
BenchmarkSortInterface-8   	10000000	       183 ns/op
BenchmarkSortSlice-8       	 3000000	       404 ns/op
PASS
ok  	github.com/mrwonko/goplayground/sortbenchmark	3.764s

What did you see instead?

# github.com/mrwonko/goplayground
./interfacecompat.go:16:3: cannot use F2 (type func(B)) as type func(A) in argument to F
FAIL	github.com/mrwonko/goplayground [build failed]

This happens regardless of the code inside the package.

@ianlancetaylor
Copy link
Contributor

Can you show us how to recreate the problem? It works fine on my packages, and I can't go get the package you mention (I get "fatal: could not read Username for 'https://github.com': terminal prompts disabled").

@bradfitz bradfitz added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Dec 8, 2017
@mrwonko
Copy link
Author

mrwonko commented Dec 8, 2017

Right, sorry. The error is somewhat misleading, that's a compile error I had in my local version of github.com/mrwonko/goplayground.

I've tested some more, it actually seems like go test -bench ./subpackage actually has the semantic of go test -bench ..

@mrwonko mrwonko changed the title go test -bench ./subpackage fails go test -bench ./subpackage tests current package instead Dec 8, 2017
@ianlancetaylor ianlancetaylor changed the title go test -bench ./subpackage tests current package instead cmd/go: go test -bench ./subpackage tests current package instead Dec 8, 2017
@ianlancetaylor ianlancetaylor added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Dec 8, 2017
@ianlancetaylor ianlancetaylor added this to the Go1.10 milestone Dec 8, 2017
@odeke-em
Copy link
Member

@mrwonko I get a 404, for your repro repository https://github.com/mrwonko/goplayground, could you please provide a way of reproducing this?

@mrwonko
Copy link
Author

mrwonko commented Dec 10, 2017

This is reproducible with any package containing a benchmark, e.g.

$ go get github.com/ChristianSiegert/go-testing-example
$ cd $GOPATH/src/github.com/ChristianSiegert
$ go test -bench ./go-testing-example/
can't load package: package github.com/ChristianSiegert: no Go files in /Users/willi/code/go/src/github.com/ChristianSiegert

The output clearly states the incorrect package, I would have expected output

goos: darwin
goarch: amd64
pkg: github.com/ChristianSiegert/go-testing-example
BenchmarkFibonacci-8          	       2	 629984153 ns/op
BenchmarkFibonacciFast-8      	50000000	        27.8 ns/op
BenchmarkFibonacciFastest-8   	100000000	        16.8 ns/op
PASS
ok  	github.com/ChristianSiegert/go-testing-example	5.026s

@vcabbage
Copy link
Member

The -bench flag takes a regexp parameter, which in your example is ./go-testing-example/. You'd need to run go test -bench . ./go-testing-example to run all benchmark.
(Note the . after -bench.)

	-bench regexp
	    Run only those benchmarks matching a regular expression.
	    By default, no benchmarks are run.
	    To run all benchmarks, use '-bench .' or '-bench=.'.

I'm going to go ahead and close this issue as it doesn't appear to be a bug. Let me know if I misinterpreted anything here. If you have questions about Go please se the resources here https://github.com/golang/go/wiki/Questions.

@golang golang locked and limited conversation to collaborators Dec 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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

6 participants