@@ -22,6 +22,7 @@ package cli
2222import (
2323 "fmt"
2424 "os"
25+ "os/exec"
2526 "path/filepath"
2627 "strings"
2728
@@ -235,11 +236,19 @@ func pkgnames(pkgs []*pkg.LocalPackage) string {
235236 return s
236237}
237238
238- func testRunCmd (cmd * cobra.Command , args []string , exclude string , executeShell bool ) {
239+ func testRunCmd (cmd * cobra.Command , args []string , exclude string , executeShell bool , valgrind bool ) {
239240 if len (args ) < 1 {
240241 NewtUsage (cmd , nil )
241242 }
242243
244+ if valgrind == true {
245+ _ , err := exec .LookPath ("valgrind" )
246+ if err != nil {
247+ NewtUsage (nil , util .FmtNewtError ("Valgrind is not installed." +
248+ "Please install it before running tests with --valgrind flag." ))
249+ }
250+ }
251+
243252 util .ExecuteShell = executeShell
244253
245254 proj := TryGetProject ()
@@ -320,7 +329,7 @@ func testRunCmd(cmd *cobra.Command, args []string, exclude string, executeShell
320329 util .StatusMessage (util .VERBOSITY_DEFAULT , "Testing package %s\n " ,
321330 pack .FullName ())
322331
323- err = b .SelfTestExecute ()
332+ err = b .SelfTestExecute (valgrind )
324333 if err == nil {
325334 passedPkgs = append (passedPkgs , pack )
326335 } else {
@@ -435,6 +444,7 @@ func sizeRunCmd(cmd *cobra.Command, args []string, ram bool, flash bool, section
435444func AddBuildCommands (cmd * cobra.Command ) {
436445 var printShellCmds bool
437446 var executeShell bool
447+ var valgrind bool
438448
439449 buildCmd := & cobra.Command {
440450 Use : "build <target-name> [target-names...]" ,
@@ -474,12 +484,14 @@ func AddBuildCommands(cmd *cobra.Command) {
474484 Use : "test <package-name> [package-names...] | all" ,
475485 Short : "Executes unit tests for one or more packages" ,
476486 Run : func (cmd * cobra.Command , args []string ) {
477- testRunCmd (cmd , args , exclude , executeShell )
487+ testRunCmd (cmd , args , exclude , executeShell , valgrind )
478488 },
479489 }
480490 testCmd .Flags ().StringVarP (& exclude , "exclude" , "e" , "" , "Comma separated list of packages to exclude" )
481491 testCmd .Flags ().BoolVar (& executeShell , "executeShell" , false ,
482492 "Execute build command using /bin/sh (Linux and MacOS only)" )
493+ testCmd .Flags ().BoolVar (& valgrind , "valgrind" , false ,
494+ "Run test executables under Valgrind" )
483495 cmd .AddCommand (testCmd )
484496 AddTabCompleteFn (testCmd , func () []string {
485497 return append (testablePkgList (), "all" , "allexcept" )
0 commit comments