@@ -178,7 +178,7 @@ func Build(pkgName, outpath string, options *compileopts.Options) error {
178
178
179
179
// Test runs the tests in the given package. Returns whether the test passed and
180
180
// 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 ) {
182
182
options .TestConfig .CompileTestBinary = true
183
183
config , err := builder .NewConfig (options )
184
184
if err != nil {
@@ -209,7 +209,7 @@ func Test(pkgName string, stdout, stderr io.Writer, options *compileopts.Options
209
209
}()
210
210
start := time .Now ()
211
211
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 )
213
213
if err != nil {
214
214
return err
215
215
}
@@ -235,7 +235,7 @@ func Test(pkgName string, stdout, stderr io.Writer, options *compileopts.Options
235
235
// runPackageTest runs a test binary that was previously built. The return
236
236
// values are whether the test passed and any errors encountered while trying to
237
237
// 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 ) {
239
239
var cmd * exec.Cmd
240
240
if len (config .Target .Emulator ) == 0 {
241
241
// Run directly.
@@ -249,6 +249,9 @@ func runPackageTest(config *compileopts.Config, stdout, stderr io.Writer, result
249
249
if testRunRegexp != "" {
250
250
flags = append (flags , "-test.run=" + testRunRegexp )
251
251
}
252
+ if testBenchRegexp != "" {
253
+ flags = append (flags , "-test.bench=" + testBenchRegexp )
254
+ }
252
255
cmd = executeCommand (config .Options , result .Binary , flags ... )
253
256
} else {
254
257
// Run in an emulator.
@@ -266,6 +269,9 @@ func runPackageTest(config *compileopts.Config, stdout, stderr io.Writer, result
266
269
if testRunRegexp != "" {
267
270
args = append (args , "-test.run=" + testRunRegexp )
268
271
}
272
+ if testBenchRegexp != "" {
273
+ args = append (args , "-test.bench=" + testBenchRegexp )
274
+ }
269
275
}
270
276
cmd = executeCommand (config .Options , config .Target .Emulator [0 ], args ... )
271
277
}
@@ -1189,12 +1195,14 @@ func main() {
1189
1195
flag .StringVar (& outpath , "o" , "" , "output filename" )
1190
1196
}
1191
1197
var testCompileOnlyFlag , testVerboseFlag , testShortFlag * bool
1198
+ var testBenchRegexp * string
1192
1199
var testRunRegexp * string
1193
1200
if command == "help" || command == "test" {
1194
1201
testCompileOnlyFlag = flag .Bool ("c" , false , "compile the test binary but do not run it" )
1195
1202
testVerboseFlag = flag .Bool ("v" , false , "verbose: print additional output" )
1196
1203
testShortFlag = flag .Bool ("short" , false , "short: run smaller test suite to save time" )
1197
1204
testRunRegexp = flag .String ("run" , "" , "run: regexp of tests to run" )
1205
+ testBenchRegexp = flag .String ("bench" , "" , "run: regexp of benchmarks to run" )
1198
1206
}
1199
1207
1200
1208
// Early command processing, before commands are interpreted by the Go flag
@@ -1418,7 +1426,7 @@ func main() {
1418
1426
defer close (buf .done )
1419
1427
stdout := (* testStdout )(buf )
1420
1428
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 )
1422
1430
if err != nil {
1423
1431
printCompilerError (func (args ... interface {}) {
1424
1432
fmt .Fprintln (stderr , args ... )
0 commit comments