Skip to content

newt: Add --list flag to test command #593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions newt/cli/build_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"os"
"path/filepath"
"sort"
"strings"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -235,8 +236,8 @@ func pkgnames(pkgs []*pkg.LocalPackage) string {
return s
}

func testRunCmd(cmd *cobra.Command, args []string, exclude string, executeShell bool) {
if len(args) < 1 {
func testRunCmd(cmd *cobra.Command, args []string, exclude string, executeShell bool, list bool) {
if ((len(args) < 1) && !list) || ((len(args) > 0) && list) {
NewtUsage(cmd, nil)
}

Expand All @@ -247,6 +248,30 @@ func testRunCmd(cmd *cobra.Command, args []string, exclude string, executeShell
// Verify and resolve each specified package.
testAll := false
packs := []*pkg.LocalPackage{}

if list {
packItfs := proj.PackagesOfType(pkg.PACKAGE_TYPE_UNITTEST)
testableNames := testablePkgList()
packs = make([]*pkg.LocalPackage, len(packItfs))
for i, p := range packItfs {
packs[i] = p.(*pkg.LocalPackage)
}

names := testableNames
for _, p := range packs {
names = append(names, p.FullName())
}

sort.Strings(names)

for _, name := range names {
util.StatusMessage(util.VERBOSITY_DEFAULT, "%s\n", name)

}

return
}

for _, pkgName := range args {
if pkgName == "all" {
testAll = true
Expand Down Expand Up @@ -470,16 +495,21 @@ func AddBuildCommands(cmd *cobra.Command) {
})

var exclude string
var list bool
testCmd := &cobra.Command{
Use: "test <package-name> [package-names...] | all",
Short: "Executes unit tests for one or more packages",
Run: func(cmd *cobra.Command, args []string) {
testRunCmd(cmd, args, exclude, executeShell)
testRunCmd(cmd, args, exclude, executeShell, list)
},
}
testCmd.Flags().StringVarP(&exclude, "exclude", "e", "", "Comma separated list of packages to exclude")
testCmd.Flags().BoolVar(&executeShell, "executeShell", false,
"Execute build command using /bin/sh (Linux and MacOS only)")
testCmd.Flags().BoolVar(&list,
"list", false,
"Show all available unit tests")

cmd.AddCommand(testCmd)
AddTabCompleteFn(testCmd, func() []string {
return append(testablePkgList(), "all", "allexcept")
Expand Down
Loading