From 6b6a037613662704c6a7322376f698084cf1f525 Mon Sep 17 00:00:00 2001 From: Rustam Zagirov Date: Tue, 11 Jul 2023 12:03:15 +0300 Subject: [PATCH] fixed comments from dolmen --- suite/suite.go | 10 +++++++--- suite/suite_test.go | 4 +++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/suite/suite.go b/suite/suite.go index 7b3290113..0d44a6b8a 100644 --- a/suite/suite.go +++ b/suite/suite.go @@ -19,7 +19,7 @@ import ( var allTestsFilter = func(_, _ string) (bool, error) { return true, nil } var matchMethod = flag.String("testify.m", "", "regular expression to select tests of the testify suite to run") -var shuffle = flag.String("testify.shuffle", "off", "randomize the execution order of tests") +var shuffle = flag.String("testify.shuffle", "off", "randomize the execution order of tests in testify suites, like -test.shuffle") // Suite is a basic testing suite with methods for storing and // retrieving the current *testing.T context. @@ -202,6 +202,9 @@ func Run(t *testing.T, suite TestingSuite) { } tests = append(tests, test) } + + // implementation is similar to the implementation of -test.shuffle in package testing + // https://cs.opensource.google/go/go/+/refs/tags/go1.20.5:src/testing/testing.go;l=1876-1893 if *shuffle != "off" { var n int64 var err error @@ -210,14 +213,15 @@ func Run(t *testing.T, suite TestingSuite) { } else { n, err = strconv.ParseInt(*shuffle, 10, 64) if err != nil { - fmt.Fprintln(os.Stderr, `testing: -shuffle should be "off", "on", or a valid integer:`, err) + t.Fatal(`testing: -testify.shuffle should be "off", "on", or a valid integer:`, err) return } } - fmt.Println("-testify.shuffle", n) + t.Log("-testify.shuffle", n) rng := rand.New(rand.NewSource(n)) rng.Shuffle(len(tests), func(i, j int) { tests[i], tests[j] = tests[j], tests[i] }) } + if suiteSetupDone { defer func() { if tearDownAllSuite, ok := suite.(TearDownAllSuite); ok { diff --git a/suite/suite_test.go b/suite/suite_test.go index 10d66831a..5e6fb65ce 100644 --- a/suite/suite_test.go +++ b/suite/suite_test.go @@ -631,9 +631,11 @@ func TestSuiteShuffleOrder(t *testing.T) { Run(t, new(ShuffleOrderSuite)) } +// TestShuffleOrderSuiteShuffleOn relies on the algorithm used by package math/rand. +// If that algorithm changes the seed value may have to be adapted. func TestShuffleOrderSuiteShuffleOn(t *testing.T) { // To test this with testify.shuffle on we launch it in its own process - cmd := exec.Command("go", "test", "-v", "-race", "-run", "TestSuiteShuffleOrder", "-testify.shuffle", "2") + cmd := exec.Command("go", "test", "-v", "-run", "TestSuiteShuffleOrder", "-testify.shuffle", "2") var out bytes.Buffer cmd.Stdout = &out t.Logf("Running %s", strings.Join(cmd.Args, " "))