Repository: incubator-mynewt-newt
Updated Branches:
  refs/heads/develop 17b334f82 -> 6339049ee


Support excluding tests

This will allow as to run "all but these tests". For example:

newt test all --exclude net/oic


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/bff00632
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/bff00632
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/bff00632

Branch: refs/heads/develop
Commit: bff00632606082b74e9a97d1aae63ef312e02e93
Parents: 17b334f
Author: spoonofpower <[email protected]>
Authored: Thu Jan 19 16:02:09 2017 -0800
Committer: spoonofpower <[email protected]>
Committed: Thu Jan 19 16:02:09 2017 -0800

----------------------------------------------------------------------
 newt/cli/build_cmds.go | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/bff00632/newt/cli/build_cmds.go
----------------------------------------------------------------------
diff --git a/newt/cli/build_cmds.go b/newt/cli/build_cmds.go
index 153997a..43cf47e 100644
--- a/newt/cli/build_cmds.go
+++ b/newt/cli/build_cmds.go
@@ -23,6 +23,7 @@ import (
        "fmt"
        "os"
        "path/filepath"
+       "strings"
 
        "github.com/spf13/cobra"
        "mynewt.apache.org/newt/newt/builder"
@@ -211,7 +212,7 @@ func pkgnames(pkgs []*pkg.LocalPackage) string {
        return s
 }
 
-func testRunCmd(cmd *cobra.Command, args []string) {
+func testRunCmd(cmd *cobra.Command, args []string, exclude string) {
        if len(args) < 1 {
                NewtUsage(cmd, nil)
        }
@@ -250,6 +251,22 @@ func testRunCmd(cmd *cobra.Command, args []string) {
                packs = pkg.SortLclPkgs(packs)
        }
 
+       if len(exclude) > 0 {
+               // filter out excluded tests
+               orig := packs
+               packs = packs[:0]
+               excls := strings.Split(exclude, ",")
+       packLoop:
+               for _, pack := range orig {
+                       for _, excl := range excls {
+                               if pack.Name() == excl || 
strings.HasPrefix(pack.Name(), excl+"/") {
+                                       continue packLoop
+                               }
+                       }
+                       packs = append(packs, pack)
+               }
+       }
+
        if len(packs) == 0 {
                NewtUsage(nil, util.NewNewtError("No testable packages found"))
        }
@@ -386,14 +403,18 @@ func AddBuildCommands(cmd *cobra.Command) {
                return append(append(targetList(), unittestList()...), "all")
        })
 
+       var exclude string
        testCmd := &cobra.Command{
                Use:   "test <package-name> [package-names...] | all",
                Short: "Executes unit tests for one or more packages",
-               Run:   testRunCmd,
+               Run: func(cmd *cobra.Command, args []string) {
+                       testRunCmd(cmd, args, exclude)
+               },
        }
+       testCmd.Flags().StringVarP(&exclude, "exclude", "e", "", "Comma 
separated list of packages to exclude")
        cmd.AddCommand(testCmd)
        AddTabCompleteFn(testCmd, func() []string {
-               return append(testablePkgList(), "all")
+               return append(testablePkgList(), "all", "allexcept")
        })
 
        loadHelpText := "Load app image to target for <target-name>."

Reply via email to