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 <iancottrell@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/go/packages/packagestest/export.go b/go/packages/packagestest/export.go
index 4f2b327..7214edd 100644
--- a/go/packages/packagestest/export.go
+++ b/go/packages/packagestest/export.go
@@ -94,6 +94,19 @@
 	}
 }
 
+// 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.