@@ -23,6 +23,7 @@ import (
2323 "fmt"
2424 "os"
2525 "path/filepath"
26+ "sort"
2627 "strings"
2728
2829 "github.com/spf13/cobra"
@@ -235,8 +236,8 @@ func pkgnames(pkgs []*pkg.LocalPackage) string {
235236 return s
236237}
237238
238- func testRunCmd (cmd * cobra.Command , args []string , exclude string , executeShell bool ) {
239- if len (args ) < 1 {
239+ func testRunCmd (cmd * cobra.Command , args []string , exclude string , executeShell bool , list bool ) {
240+ if (( len (args ) < 1 ) && ! list ) || (( len ( args ) > 0 ) && list ) {
240241 NewtUsage (cmd , nil )
241242 }
242243
@@ -247,6 +248,30 @@ func testRunCmd(cmd *cobra.Command, args []string, exclude string, executeShell
247248 // Verify and resolve each specified package.
248249 testAll := false
249250 packs := []* pkg.LocalPackage {}
251+
252+ if list {
253+ packItfs := proj .PackagesOfType (pkg .PACKAGE_TYPE_UNITTEST )
254+ testableNames := testablePkgList ()
255+ packs = make ([]* pkg.LocalPackage , len (packItfs ))
256+ for i , p := range packItfs {
257+ packs [i ] = p .(* pkg.LocalPackage )
258+ }
259+
260+ names := testableNames
261+ for _ , p := range packs {
262+ names = append (names , p .FullName ())
263+ }
264+
265+ sort .Strings (names )
266+
267+ for _ , name := range names {
268+ util .StatusMessage (util .VERBOSITY_DEFAULT , "%s\n " , name )
269+
270+ }
271+
272+ return
273+ }
274+
250275 for _ , pkgName := range args {
251276 if pkgName == "all" {
252277 testAll = true
@@ -470,16 +495,21 @@ func AddBuildCommands(cmd *cobra.Command) {
470495 })
471496
472497 var exclude string
498+ var list bool
473499 testCmd := & cobra.Command {
474500 Use : "test <package-name> [package-names...] | all" ,
475501 Short : "Executes unit tests for one or more packages" ,
476502 Run : func (cmd * cobra.Command , args []string ) {
477- testRunCmd (cmd , args , exclude , executeShell )
503+ testRunCmd (cmd , args , exclude , executeShell , list )
478504 },
479505 }
480506 testCmd .Flags ().StringVarP (& exclude , "exclude" , "e" , "" , "Comma separated list of packages to exclude" )
481507 testCmd .Flags ().BoolVar (& executeShell , "executeShell" , false ,
482508 "Execute build command using /bin/sh (Linux and MacOS only)" )
509+ testCmd .Flags ().BoolVar (& list ,
510+ "list" , false ,
511+ "Show all available unit tests" )
512+
483513 cmd .AddCommand (testCmd )
484514 AddTabCompleteFn (testCmd , func () []string {
485515 return append (testablePkgList (), "all" , "allexcept" )
0 commit comments