Skip to content

Commit 6127125

Browse files
committed
newt: Add --list flag to test command
Now it's possible to show all available unit tests and testable packages
1 parent 1127fdc commit 6127125

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

newt/cli/build_cmds.go

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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,29 @@ 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+
return
272+
}
273+
250274
for _, pkgName := range args {
251275
if pkgName == "all" {
252276
testAll = true
@@ -470,16 +494,21 @@ func AddBuildCommands(cmd *cobra.Command) {
470494
})
471495

472496
var exclude string
497+
var list bool
473498
testCmd := &cobra.Command{
474499
Use: "test <package-name> [package-names...] | all",
475500
Short: "Executes unit tests for one or more packages",
476501
Run: func(cmd *cobra.Command, args []string) {
477-
testRunCmd(cmd, args, exclude, executeShell)
502+
testRunCmd(cmd, args, exclude, executeShell, list)
478503
},
479504
}
480505
testCmd.Flags().StringVarP(&exclude, "exclude", "e", "", "Comma separated list of packages to exclude")
481506
testCmd.Flags().BoolVar(&executeShell, "executeShell", false,
482507
"Execute build command using /bin/sh (Linux and MacOS only)")
508+
testCmd.Flags().BoolVar(&list,
509+
"list", false,
510+
"Show all available unit tests")
511+
483512
cmd.AddCommand(testCmd)
484513
AddTabCompleteFn(testCmd, func() []string {
485514
return append(testablePkgList(), "all", "allexcept")

0 commit comments

Comments
 (0)