@@ -235,8 +235,8 @@ func pkgnames(pkgs []*pkg.LocalPackage) string {
235
235
return s
236
236
}
237
237
238
- func testRunCmd (cmd * cobra.Command , args []string , exclude string , executeShell bool ) {
239
- if len (args ) < 1 {
238
+ func testRunCmd (cmd * cobra.Command , args []string , exclude string , executeShell bool , list bool ) {
239
+ if (( len (args ) < 1 ) && ! list ) || (( len ( args ) > 0 ) && list ) {
240
240
NewtUsage (cmd , nil )
241
241
}
242
242
@@ -247,6 +247,22 @@ func testRunCmd(cmd *cobra.Command, args []string, exclude string, executeShell
247
247
// Verify and resolve each specified package.
248
248
testAll := false
249
249
packs := []* pkg.LocalPackage {}
250
+
251
+ if list {
252
+ packItfs := proj .PackagesOfType (pkg .PACKAGE_TYPE_UNITTEST )
253
+ packs = make ([]* pkg.LocalPackage , len (packItfs ))
254
+ for i , p := range packItfs {
255
+ packs [i ] = p .(* pkg.LocalPackage )
256
+ }
257
+
258
+ packs = pkg .SortLclPkgs (packs )
259
+ for _ , p := range packItfs {
260
+ util .StatusMessage (util .VERBOSITY_DEFAULT , "%s\n " , p .FullName ())
261
+ }
262
+
263
+ return
264
+ }
265
+
250
266
for _ , pkgName := range args {
251
267
if pkgName == "all" {
252
268
testAll = true
@@ -470,16 +486,21 @@ func AddBuildCommands(cmd *cobra.Command) {
470
486
})
471
487
472
488
var exclude string
489
+ var list bool
473
490
testCmd := & cobra.Command {
474
491
Use : "test <package-name> [package-names...] | all" ,
475
492
Short : "Executes unit tests for one or more packages" ,
476
493
Run : func (cmd * cobra.Command , args []string ) {
477
- testRunCmd (cmd , args , exclude , executeShell )
494
+ testRunCmd (cmd , args , exclude , executeShell , list )
478
495
},
479
496
}
480
497
testCmd .Flags ().StringVarP (& exclude , "exclude" , "e" , "" , "Comma separated list of packages to exclude" )
481
498
testCmd .Flags ().BoolVar (& executeShell , "executeShell" , false ,
482
499
"Execute build command using /bin/sh (Linux and MacOS only)" )
500
+ testCmd .Flags ().BoolVar (& list ,
501
+ "list" , false ,
502
+ "Show all available unit tests" )
503
+
483
504
cmd .AddCommand (testCmd )
484
505
AddTabCompleteFn (testCmd , func () []string {
485
506
return append (testablePkgList (), "all" , "allexcept" )
0 commit comments