skelterjohn/go-gb

Support running Benchmarks

tones111 opened this issue · 2 comments

When I run gb -t it runs tests, but not benchmarks. Could a feature be added such that it runs benchmarks with -t (or a new flag added)?

$ find .
.
./bench
./bench/my_test.go
./bench/main.go

$ cat bench/main.go
package main

import "fmt"

func main() {
fmt.Println("Hello World")
}

$ cat bench/my_test.go
package test

import (
"fmt"
"testing"
)

func Test001(t *testing.T) {
fmt.Println("Running test 001")
}

func Test002(t *testing.T) {
fmt.Println("Running test 002")
}

func Benchmark001(b *testing.B) {
fmt.Println("Running bench 001")
}

func Benchmark002(b *testing.B) {
fmt.Println("Running bench 002")
}

$ gb -t
(in bench) building cmd "bench"
(in bench) testing "bench"
Running test 001
Running test 002
PASS
Built 1 target

I swear it used to run benchmarks :)

When gotest was rewritten entirely in go I think they must have messed with testing in general. I'll take a look in the near future and see what exactly changed.

You can now run benchmarks. gb will pass any command line args that begin with "-test." to the test executable, just like gotest does. So if you run "gb -t -test.bench=BenchmarkX", it will behave like it's running "gotest -test.bench=BenchmarkX" in all relevant targets (all known local targets in this case, since none are specified).