summaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/gotest/doc.go13
-rwxr-xr-xsrc/cmd/gotest/gotest14
2 files changed, 23 insertions, 4 deletions
diff --git a/src/cmd/gotest/doc.go b/src/cmd/gotest/doc.go
index e1a87c43c..40c40fc1f 100644
--- a/src/cmd/gotest/doc.go
+++ b/src/cmd/gotest/doc.go
@@ -19,6 +19,12 @@ They should have signature
func TestXXX(t *testing.T) { ... }
+Benchmark functions can be written as well; they will be run only
+when the -benchmarks flag is provided. Benchmarks should have
+signature
+
+ func BenchmarkXXX(b *testing.B) { ... }
+
See the documentation of the testing package for more information.
By default, gotest needs no arguments. It compiles all the .go files
@@ -36,14 +42,15 @@ The resulting binary, called (for amd64) 6.out, has a couple of
arguments.
Usage:
- 6.out [-v] [-match pattern]
+ 6.out [-v] [-match pattern] [-benchmarks pattern]
-The -v flag causes the tests to be logged as they run. The --match
+The -v flag causes the tests to be logged as they run. The -match
flag causes only those tests whose names match the regular expression
pattern to be run. By default all tests are run silently. If all
the specified test pass, 6.out prints PASS and exits with a 0 exit
code. If any tests fail, it prints FAIL and exits with a non-zero
-code.
+code. The -benchmarks flag is analogous to the -match flag, but
+applies to benchmarks. No benchmarks run by default.
*/
package documentation
diff --git a/src/cmd/gotest/gotest b/src/cmd/gotest/gotest
index 584578e91..5f87b4791 100755
--- a/src/cmd/gotest/gotest
+++ b/src/cmd/gotest/gotest
@@ -118,6 +118,9 @@ importpath=$(gomake -s importpath)
echo 'gotest: error: no tests matching '$pattern in _test/$importpath.a $xofile 1>&2
exit 2
fi
+ # benchmarks are named BenchmarkFoo.
+ pattern='Benchmark([^a-z].*)?'
+ benchmarks=$(6nm -s _test/$importpath.a $xofile | egrep ' T .*·'$pattern'$' | grep -v '·.*[.·]' | sed 's/.* //; s/·/./')
# package spec
echo 'package main'
@@ -140,10 +143,19 @@ importpath=$(gomake -s importpath)
echo ' testing.Test{ "'$i'", '$i' },'
done
echo '}'
+ # benchmark array
+ echo 'var benchmarks = []testing.Benchmark {'
+ for i in $benchmarks
+ do
+ echo ' testing.Benchmark{ "'$i'", '$i' },'
+ done
+ echo '}'
+
# body
echo
echo 'func main() {'
- echo ' testing.Main(tests)'
+ echo ' testing.Main(tests);'
+ echo ' testing.RunBenchmarks(benchmarks)'
echo '}'
}>_testmain.go