Skip to content

Commit

Permalink
fixed comments from dolmen
Browse files Browse the repository at this point in the history
  • Loading branch information
stamm committed Jul 11, 2023
1 parent 5a26333 commit 6b6a037
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 7 additions & 3 deletions suite/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion suite/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, " "))
Expand Down

0 comments on commit 6b6a037

Please sign in to comment.