From 72292f0c83ea51e7c11dd4c00018b4c599ec865c Mon Sep 17 00:00:00 2001 From: Ian Cottrell Date: Wed, 21 Nov 2018 13:55:09 -0500 Subject: [PATCH] go/packages/packagestest: adds a benchmark version of TestAll This is needed because testing.TB does not have a "Run" method for sub tests, and the signature of the function it takes needs to match the testing parameter. Change-Id: I9201dd75891ed1bda300a4247fe7eac1e25bd30d Reviewed-on: https://go-review.googlesource.com/c/150857 Run-TryBot: Ian Cottrell Reviewed-by: Michael Matloob TryBot-Result: Gobot Gobot --- go/packages/packagestest/export.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/go/packages/packagestest/export.go b/go/packages/packagestest/export.go index 4f2b3272..7214eddc 100644 --- a/go/packages/packagestest/export.go +++ b/go/packages/packagestest/export.go @@ -94,6 +94,19 @@ func TestAll(t *testing.T, f func(*testing.T, Exporter)) { } } +// BenchmarkAll invokes the testing function once for each exporter registered in +// the All global. +// Each exporter will be run as a sub-test named after the exporter being used. +func BenchmarkAll(b *testing.B, f func(*testing.B, Exporter)) { + b.Helper() + for _, e := range All { + b.Run(e.Name(), func(b *testing.B) { + b.Helper() + f(b, e) + }) + } +} + // Export is called to write out a test directory from within a test function. // It takes the exporter and the build system agnostic module descriptions, and // uses them to build a temporary directory.