@@ -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.
@@ -274,6 +277,9 @@ func runPackageTest(config *compileopts.Config, stdout, stderr io.Writer, result
274
277
if testRunRegexp != "" {
275
278
args = append (args , "-test.run=" + testRunRegexp )
276
279
}
280
+ if testBenchRegexp != "" {
281
+ args = append (args , "-test.bench=" + testBenchRegexp )
282
+ }
277
283
}
278
284
cmd = executeCommand (config .Options , config .Target .Emulator [0 ], args ... )
279
285
}
@@ -1197,12 +1203,14 @@ func main() {
1197
1203
flag .StringVar (& outpath , "o" , "" , "output filename" )
1198
1204
}
1199
1205
var testCompileOnlyFlag , testVerboseFlag , testShortFlag * bool
1206
+ var testBenchRegexp * string
1200
1207
var testRunRegexp * string
1201
1208
if command == "help" || command == "test" {
1202
1209
testCompileOnlyFlag = flag .Bool ("c" , false , "compile the test binary but do not run it" )
1203
1210
testVerboseFlag = flag .Bool ("v" , false , "verbose: print additional output" )
1204
1211
testShortFlag = flag .Bool ("short" , false , "short: run smaller test suite to save time" )
1205
1212
testRunRegexp = flag .String ("run" , "" , "run: regexp of tests to run" )
1213
+ testBenchRegexp = flag .String ("bench" , "" , "run: regexp of benchmarks to run" )
1206
1214
}
1207
1215
1208
1216
// Early command processing, before commands are interpreted by the Go flag
@@ -1426,7 +1434,7 @@ func main() {
1426
1434
defer close (buf .done )
1427
1435
stdout := (* testStdout )(buf )
1428
1436
stderr := (* testStderr )(buf )
1429
- passed , err := Test (pkgName , stdout , stderr , options , * testCompileOnlyFlag , * testVerboseFlag , * testShortFlag , * testRunRegexp , outpath )
1437
+ passed , err := Test (pkgName , stdout , stderr , options , * testCompileOnlyFlag , * testVerboseFlag , * testShortFlag , * testRunRegexp , * testBenchRegexp , outpath )
1430
1438
if err != nil {
1431
1439
printCompilerError (func (args ... interface {}) {
1432
1440
fmt .Fprintln (stderr , args ... )
0 commit comments