@@ -178,7 +178,7 @@ func Build(pkgName, outpath string, options *compileopts.Options) error {
178178
179179// Test runs the tests in the given package. Returns whether the test passed and
180180// possibly an error if the test failed to run.
181- func Test (pkgName string , stdout , stderr io.Writer , options * compileopts.Options , testCompileOnly , testVerbose , testShort bool , testRunRegexp string , outpath string ) (bool , error ) {
181+ func Test (pkgName string , stdout , stderr io.Writer , options * compileopts.Options , testCompileOnly , testVerbose , testShort bool , testRunRegexp string , testBenchRegexp string , outpath string ) (bool , error ) {
182182 options .TestConfig .CompileTestBinary = true
183183 config , err := builder .NewConfig (options )
184184 if err != nil {
@@ -209,7 +209,7 @@ func Test(pkgName string, stdout, stderr io.Writer, options *compileopts.Options
209209 }()
210210 start := time .Now ()
211211 var err error
212- passed , err = runPackageTest (config , stdout , stderr , result , testVerbose , testShort , testRunRegexp )
212+ passed , err = runPackageTest (config , stdout , stderr , result , testVerbose , testShort , testRunRegexp , testBenchRegexp )
213213 if err != nil {
214214 return err
215215 }
@@ -235,7 +235,7 @@ func Test(pkgName string, stdout, stderr io.Writer, options *compileopts.Options
235235// runPackageTest runs a test binary that was previously built. The return
236236// values are whether the test passed and any errors encountered while trying to
237237// run the binary.
238- func runPackageTest (config * compileopts.Config , stdout , stderr io.Writer , result builder.BuildResult , testVerbose , testShort bool , testRunRegexp string ) (bool , error ) {
238+ func runPackageTest (config * compileopts.Config , stdout , stderr io.Writer , result builder.BuildResult , testVerbose , testShort bool , testRunRegexp string , testBenchRegexp string ) (bool , error ) {
239239 var cmd * exec.Cmd
240240 if len (config .Target .Emulator ) == 0 {
241241 // Run directly.
@@ -249,6 +249,9 @@ func runPackageTest(config *compileopts.Config, stdout, stderr io.Writer, result
249249 if testRunRegexp != "" {
250250 flags = append (flags , "-test.run=" + testRunRegexp )
251251 }
252+ if testBenchRegexp != "" {
253+ flags = append (flags , "-test.bench=" + testBenchRegexp )
254+ }
252255 cmd = executeCommand (config .Options , result .Binary , flags ... )
253256 } else {
254257 // Run in an emulator.
@@ -266,6 +269,9 @@ func runPackageTest(config *compileopts.Config, stdout, stderr io.Writer, result
266269 if testRunRegexp != "" {
267270 args = append (args , "-test.run=" + testRunRegexp )
268271 }
272+ if testBenchRegexp != "" {
273+ args = append (args , "-test.bench=" + testBenchRegexp )
274+ }
269275 }
270276 cmd = executeCommand (config .Options , config .Target .Emulator [0 ], args ... )
271277 }
@@ -1189,12 +1195,14 @@ func main() {
11891195 flag .StringVar (& outpath , "o" , "" , "output filename" )
11901196 }
11911197 var testCompileOnlyFlag , testVerboseFlag , testShortFlag * bool
1198+ var testBenchRegexp * string
11921199 var testRunRegexp * string
11931200 if command == "help" || command == "test" {
11941201 testCompileOnlyFlag = flag .Bool ("c" , false , "compile the test binary but do not run it" )
11951202 testVerboseFlag = flag .Bool ("v" , false , "verbose: print additional output" )
11961203 testShortFlag = flag .Bool ("short" , false , "short: run smaller test suite to save time" )
11971204 testRunRegexp = flag .String ("run" , "" , "run: regexp of tests to run" )
1205+ testBenchRegexp = flag .String ("bench" , "" , "run: regexp of benchmarks to run" )
11981206 }
11991207
12001208 // Early command processing, before commands are interpreted by the Go flag
@@ -1418,7 +1426,7 @@ func main() {
14181426 defer close (buf .done )
14191427 stdout := (* testStdout )(buf )
14201428 stderr := (* testStderr )(buf )
1421- passed , err := Test (pkgName , stdout , stderr , options , * testCompileOnlyFlag , * testVerboseFlag , * testShortFlag , * testRunRegexp , outpath )
1429+ passed , err := Test (pkgName , stdout , stderr , options , * testCompileOnlyFlag , * testVerboseFlag , * testShortFlag , * testRunRegexp , * testBenchRegexp , outpath )
14221430 if err != nil {
14231431 printCompilerError (func (args ... interface {}) {
14241432 fmt .Fprintln (stderr , args ... )
0 commit comments