From 84a3273131c28c3f199dc7f29d1bfae6c79f2b94 Mon Sep 17 00:00:00 2001 From: Damian Gryski Date: Thu, 30 Mar 2023 23:07:20 -0700 Subject: [PATCH] main: fix tests with default TestConfig.Count=0 doesn't skip all tests --- compileopts/config.go | 2 +- main.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/compileopts/config.go b/compileopts/config.go index 86f35fa9..117f5c20 100644 --- a/compileopts/config.go +++ b/compileopts/config.go @@ -545,7 +545,7 @@ type TestConfig struct { Verbose bool Short bool RunRegexp string - Count int + Count *int BenchRegexp string BenchTime string BenchMem bool diff --git a/main.go b/main.go index 435708bb..a242ff43 100644 --- a/main.go +++ b/main.go @@ -245,8 +245,8 @@ func Test(pkgName string, stdout, stderr io.Writer, options *compileopts.Options if testConfig.BenchMem { flags = append(flags, "-test.benchmem") } - if testConfig.Count != 1 { - flags = append(flags, "-test.count="+strconv.Itoa(testConfig.Count)) + if testConfig.Count != nil && *testConfig.Count != 1 { + flags = append(flags, "-test.count="+strconv.Itoa(*testConfig.Count)) } var buf bytes.Buffer @@ -1420,7 +1420,7 @@ func main() { flag.BoolVar(&testConfig.Verbose, "v", false, "verbose: print additional output") flag.BoolVar(&testConfig.Short, "short", false, "short: run smaller test suite to save time") flag.StringVar(&testConfig.RunRegexp, "run", "", "run: regexp of tests to run") - flag.IntVar(&testConfig.Count, "count", 1, "count: number of times to run tests/benchmarks `count` times") + testConfig.Count = flag.Int("count", 1, "count: number of times to run tests/benchmarks `count` times") flag.StringVar(&testConfig.BenchRegexp, "bench", "", "run: regexp of benchmarks to run") flag.StringVar(&testConfig.BenchTime, "benchtime", "", "run each benchmark for duration `d`") flag.BoolVar(&testConfig.BenchMem, "benchmem", false, "show memory stats for benchmarks")