From 024bc9db6c0a45333263ff506fa9d8f60000ecb8 Mon Sep 17 00:00:00 2001 From: Ruben de Vries Date: Tue, 11 May 2021 11:42:57 +0200 Subject: [PATCH] add flag to report progress --- courtney.go | 16 +++++++++------- shared/shared.go | 26 ++++++++++++++------------ tester/tester.go | 4 +++- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/courtney.go b/courtney.go index f9e3c8d..56a98df 100644 --- a/courtney.go +++ b/courtney.go @@ -21,6 +21,7 @@ func main() { enforceFlag := flag.Bool("e", false, "Enforce 100% code coverage") verboseFlag := flag.Bool("v", false, "Verbose output") + reportFlag := flag.Bool("r", false, "Print each package being tested") shortFlag := flag.Bool("short", false, "Pass the short flag to the go test command") timeoutFlag := flag.String("timeout", "", "Pass the timeout flag to the go test command") outputFlag := flag.String("o", "", "Override coverage file location") @@ -51,13 +52,14 @@ func main() { } setup := &shared.Setup{ - Env: env, - Paths: patsy.NewCache(env), - Enforce: *enforceFlag, - Verbose: *verboseFlag, - Short: *shortFlag, - Timeout: *timeoutFlag, - Output: *outputFlag, + Env: env, + Paths: patsy.NewCache(env), + Enforce: *enforceFlag, + Verbose: *verboseFlag, + ReportTestRun: *reportFlag, + Short: *shortFlag, + Timeout: *timeoutFlag, + Output: *outputFlag, Options: shared.Options{ ExcludeErrNoReturnParam: *excludeErrNoReturnParamFlag, }, diff --git a/shared/shared.go b/shared/shared.go index c8b1da1..d81e3d5 100644 --- a/shared/shared.go +++ b/shared/shared.go @@ -10,18 +10,20 @@ import ( // Setup holds globals, environment and command line flags for the courtney // command type Setup struct { - Env vos.Env - Paths *patsy.Cache - Enforce bool - Verbose bool - Short bool - Timeout string - Load string - Output string - Options Options - ExcludePkgs []string - TestArgs []string - Packages []PackageSpec + Env vos.Env + Paths *patsy.Cache + Enforce bool + Verbose bool + ReportTestRun bool + TestVerbose bool + Short bool + Timeout string + Load string + Output string + Options Options + ExcludePkgs []string + TestArgs []string + Packages []PackageSpec } type Options struct { diff --git a/tester/tester.go b/tester/tester.go index b661738..affeaef 100644 --- a/tester/tester.go +++ b/tester/tester.go @@ -252,11 +252,13 @@ func (t *Tester) processDir(dir string) error { args = append(args, t.setup.TestArgs...) } if t.setup.Verbose { - fmt.Fprintf( + _, _ = fmt.Fprintf( t.setup.Env.Stdout(), "Running test: %s\n", strings.Join(append([]string{"go"}, args...), " "), ) + } else if t.setup.ReportTestRun { + _, _ = fmt.Fprintf(t.setup.Env.Stdout(), "Running test: %s\n", dir) } exe := exec.Command("go", args...)