go-check / check

Rich testing for the Go language
Other
696 stars 182 forks source link

Test status does not flow from TestSetup to its running Test #128

Open christothes opened 3 years ago

christothes commented 3 years ago

Given a test suite with a TestSetup method, if c.Fail() is called on the *C instance captured from the TestSetup method or one of its descendants after TestSetup completes but before the Test method completes, the test is not marked failed.

Consider the following test:

package main

import (
    chk "gopkg.in/check.v1"
    "testing"
)

type scratchTest struct {
    c *chk.C
}

// Hookup to the testing framework
func Test(t *testing.T) { chk.TestingT(t) }

var _ = chk.Suite(&scratchTest{})

func (s *scratchTest) TestCheckDoesNotFlow(c *chk.C) {
    s.doFail()
    c.Log("This test should be failing")
}

func (s *scratchTest) SetUpTest(c *chk.C) {
    // capture the check test context
    s.c = c
}

func (s *scratchTest) doFail() {
    s.c.Fail()
}

Actual output:

OK: 1 passed
PASS
ok      _/C_/src/goscratch      0.126s

Expected output:

----------------------------------------------------------------------
FAIL: checkrepro_test.go:20: scratchTest.TestCheckDoesNotFlow

This test should be failing
OOPS: 0 passed, 1 FAILED
--- FAIL: Test (0.00s)
FAIL
exit status 1
FAIL    chrissscratch.com/scratch       0.105s
barrettj12 commented 3 months ago

Duplicate of #22 and #41