From f96052c82adb50db120b1acdb4b54eac20df4e1f Mon Sep 17 00:00:00 2001 From: ariley Date: Mon, 4 May 2020 19:47:19 +0100 Subject: [PATCH] Remove 1.8 and 1.9 tests. Updated failfast test --- .travis.yml | 3 --- suite/suite_test.go | 24 ++++++++++++++++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6edb755fb..f6601d08d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,6 @@ sudo: false matrix: include: - - go: "1.8.x" - - go: "1.9.x" - go: "1.10.x" - go: "1.11.x" env: GO111MODULE=off @@ -28,4 +26,3 @@ script: - ./.travis.gofmt.sh - ./.travis.govet.sh - go test -v -race ./... - - go test -v -race -failfast -run TestSuiteWithFailfast diff --git a/suite/suite_test.go b/suite/suite_test.go index 3ecbd56be..7b9e13e7c 100644 --- a/suite/suite_test.go +++ b/suite/suite_test.go @@ -1,11 +1,13 @@ package suite import ( + "bytes" "errors" "flag" "io/ioutil" "math/rand" "os" + "os/exec" "strings" "testing" "time" @@ -525,14 +527,15 @@ func (s *FailfastSuite) call(method string) { s.callOrder = append(s.callOrder, method) } -func TestSuiteWithFailfast(t *testing.T) { - // This test suite is run twice by travis. Once normally and once with the -failfast flag +func TestFailfastSuite(t *testing.T) { + // This test suite is run twice. Once normally and once with the -failfast flag by TestFailfastSuiteFailFastOn + // If you need to debug it run this test directly with the failfast flag set on/off as you need failFast := flag.Lookup("test.failfast").Value.(flag.Getter).Get().(bool) s := new(FailfastSuite) ok := testing.RunTests( allTestsFilter, []testing.InternalTest{{ - Name: "TestSuiteWithFailfast", + Name: "TestFailfastSuite", F: func(t *testing.T) { Run(t, s) }, @@ -540,13 +543,26 @@ func TestSuiteWithFailfast(t *testing.T) { ) assert.Equal(t, false, ok) if failFast { - // Test A Fails and because we are running with failfast Test B never runs and we proceed staright to TearDownSuite + // Test A Fails and because we are running with failfast Test B never runs and we proceed straight to TearDownSuite assert.Equal(t, "SetupSuite;SetupTest;Test A Fails;TearDownTest;TearDownSuite", strings.Join(s.callOrder, ";")) } else { // Test A Fails and because we are running without failfast we continue and run Test B and then proceed to TearDownSuite assert.Equal(t, "SetupSuite;SetupTest;Test A Fails;TearDownTest;SetupTest;Test B Passes;TearDownTest;TearDownSuite", strings.Join(s.callOrder, ";")) } } +func TestFailfastSuiteFailFastOn(t *testing.T) { + // To test this with failfast on (and isolated from other intended test failures in our test suite) we launch it in its own process + cmd := exec.Command("go", "test", "-v", "-race", "-run", "TestFailfastSuite", "-failfast") + var out bytes.Buffer + cmd.Stdout = &out + t.Log("Running go test -v -race -run TestFailfastSuite -failfast") + err := cmd.Run() + t.Log(out.String()) + if err != nil { + t.Log(err) + t.Fail() + } +} func (s *FailfastSuite) SetupSuite() { s.call("SetupSuite") }