Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flow C funcStatus from setup C to Test C #127

Open
wants to merge 3 commits into
base: v1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions check.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ type C struct {
method *methodType
kind funcKind
testName string
_status funcStatus
_status *funcStatus
logb *logger
logw io.Writer
done chan *C
Expand All @@ -95,11 +95,11 @@ type C struct {
}

func (c *C) status() funcStatus {
return funcStatus(atomic.LoadUint32((*uint32)(&c._status)))
return funcStatus(atomic.LoadUint32((*uint32)(c._status)))
}

func (c *C) setStatus(s funcStatus) {
atomic.StoreUint32((*uint32)(&c._status), uint32(s))
atomic.StoreUint32((*uint32)(c._status), uint32(s))
}

func (c *C) stopNow() {
Expand Down Expand Up @@ -477,7 +477,9 @@ func (tracker *resultTracker) _loopRoutine() {
}
}
case failedSt:
tracker.result.Failed++
if c.kind != succeededSt {
tracker.result.Failed++
}
case panickedSt:
if c.kind == fixtureKd {
tracker.result.FixturePanicked++
Expand Down Expand Up @@ -661,6 +663,7 @@ func (runner *suiteRunner) forkCall(method *methodType, kind funcKind, testName
timer: timer{benchTime: runner.benchTime},
startTime: time.Now(),
benchMem: runner.benchMem,
_status: new(funcStatus),
}
runner.tracker.expectCall(c)
go (func() {
Expand Down Expand Up @@ -760,7 +763,11 @@ func (runner *suiteRunner) forkTest(method *methodType) *C {
defer c.StopTimer()
benchN := 1
for {
runner.runFixtureWithPanic(runner.setUpTest, testName, c.logb, &skipped)
cSetup := runner.runFixtureWithPanic(runner.setUpTest, testName, c.logb, &skipped)
if cSetup != nil {
// Assign the _status of the setup method to the Test method so that _status value changes flow through
c._status = cSetup._status
}
mt := c.method.Type()
if mt.NumIn() != 1 || mt.In(0) != reflect.TypeOf(c) {
// Rather than a plain panic, provide a more helpful message when
Expand Down
39 changes: 39 additions & 0 deletions fixture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,45 @@ func (s *FixtureS) TestFixtureLogging(c *C) {
"1\n2\n3\n4\n5\n")
}

// -----------------------------------------------------------------------
// Verify that test failure status within SetUpTest() persists within the test itself.

type FixtureStatusHelper struct {
cSetup *C
cTest *C
failTest bool
}

func (s *FixtureStatusHelper) SetUpTest(c *C) {
s.cSetup = c
}

func (s *FixtureStatusHelper) Test(c *C) {
// Setting Fail status here should be reflected in the C captured in SetupTest
if s.failTest {
s.cSetup.Fail()
}
s.cTest = c
}

func (s *FixtureS) TestFixtureStatusFlowsFromSetupTestToTest(c *C) {
var scenarios []FixtureStatusHelper = []FixtureStatusHelper{
{failTest: true},
{failTest: false},
}

output := String{}
for _, t := range scenarios {
result := Run(&t, &RunConf{Output: &output})
c.Assert(t.cSetup.Failed(), Equals, t.cTest.Failed())
expectedFailed := 0
if t.failTest {
expectedFailed = 1
}
c.Assert(result.Failed, Equals, expectedFailed)
}
}

// -----------------------------------------------------------------------
// Skip() within fixture methods.

Expand Down