@@ -235,8 +235,8 @@ func pkgnames(pkgs []*pkg.LocalPackage) string {
235235 return s
236236}
237237
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 ) {
240240 NewtUsage (cmd , nil )
241241 }
242242
@@ -247,6 +247,22 @@ func testRunCmd(cmd *cobra.Command, args []string, exclude string, executeShell
247247 // Verify and resolve each specified package.
248248 testAll := false
249249 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+
250266 for _ , pkgName := range args {
251267 if pkgName == "all" {
252268 testAll = true
@@ -470,16 +486,21 @@ func AddBuildCommands(cmd *cobra.Command) {
470486 })
471487
472488 var exclude string
489+ var list bool
473490 testCmd := & cobra.Command {
474491 Use : "test <package-name> [package-names...] | all" ,
475492 Short : "Executes unit tests for one or more packages" ,
476493 Run : func (cmd * cobra.Command , args []string ) {
477- testRunCmd (cmd , args , exclude , executeShell )
494+ testRunCmd (cmd , args , exclude , executeShell , list )
478495 },
479496 }
480497 testCmd .Flags ().StringVarP (& exclude , "exclude" , "e" , "" , "Comma separated list of packages to exclude" )
481498 testCmd .Flags ().BoolVar (& executeShell , "executeShell" , false ,
482499 "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+
483504 cmd .AddCommand (testCmd )
484505 AddTabCompleteFn (testCmd , func () []string {
485506 return append (testablePkgList (), "all" , "allexcept" )
0 commit comments