Skip to content

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

Closed

Description

@l3x

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

Activity

  1. davecheney commented on Jan 29, 2017

    @davecheney
    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=.  ./... 
    
  2. l3x commented on Jan 30, 2017

    @l3x
    Author

    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

  3. locked and limited conversation to collaborators on Jan 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions