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

testing: -bench does not honor the import path wild cards #18847

Closed
l3x opened this issue Jan 29, 2017 · 2 comments
Closed

testing: -bench does not honor the import path wild cards #18847

l3x opened this issue Jan 29, 2017 · 2 comments

Comments

@l3x
Copy link

l3x commented Jan 29, 2017

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

go version go1.7.4 darwin/amd64

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

GOARCH="amd64"
GOBIN="/Users/lex/dev/go/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/lex/clients/packt/dev/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.7.4_2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.7.4_2/libexec/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/vl/zj0n4b_9015_22chhpcjjw4h0000gn/T/go-build724604650=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"

What did you do?

My project directory looks like this:

book
+ chapter1
   + 01_fib
   + 02_recursive
   chapter1.go
+ chapter2 
( etc...) 

I would like to run tests for all chapters from the root (book) directory.

go test ./... works as expected, running all tests found in all subdirectories.

$ go test  ./...
?   	bitbucket.org/lsheehan/fp-in-go	[no test files]
?   	bitbucket.org/lsheehan/fp-in-go/chapter1	[no test files]
ok  	bitbucket.org/lsheehan/fp-in-go/chapter1/01_fib	2.860s

go test -bench ./... does not. Here's what it does:

$ go test -bench ./...
?   	bitbucket.org/lsheehan/fp-in-go	[no test files]

I can, however, move into the directory that contains the tests and get good results from the benchmark test:

... chapter1/fib $ go test -bench=.
1
BenchmarkFibFunc-8   	100
10000
1000000
3000000
 3000000	       570 ns/op
PASS
ok  	bitbucket.org/lsheehan/fp-in-go/chapter1/fib	5.100s
@davecheney
Copy link
Contributor

This is working as intended.

-bench takes an argument, a regex to match against benchmarks in the _test.go files.

Your non working example passes ./... as that regex which doesn't match anything and will only run in the current directory.

try

go test -bench=.  ./... 

@l3x
Copy link
Author

l3x commented Jan 30, 2017

Yup. Works like a charm when called properly. Thank you for sharing your wisdom with articles like: https://dave.cheney.net/2013/06/30/how-to-write-benchmarks-in-go

@golang golang locked and limited conversation to collaborators Jan 30, 2018
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