Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Add a panic() if AddCleanup is unsafe. #92
Conversation
jameinel
changed the title from
Add a panic() if AddCleanup usage by adding panic() for un…
to
Add a panic() if AddCleanup is unsafe.
Mar 17, 2016
|
LGTM |
|
LGTM. Nice catch! On Thu, Mar 17, 2016 at 4:23 PM, Andrew Wilkins notifications@github.com
|
jameinel
added some commits
Mar 17, 2016
axw
reviewed
Mar 17, 2016
| + s.suiteStack = append(s.suiteStack, cleanup) | ||
| + return | ||
| + } | ||
| + if s != s.testSuite { |
axw
Mar 17, 2016
Member
I think this one can go. s.testSuite is always nil, or equal to s.suiteStuite. If anything else were true, then either this or the s != s.suiteSuite test would panic.
jameinel
Mar 17, 2016
Owner
Confirmed. I removed it and the test suite still passed which should catch this sort of thing.
axw
reviewed
Mar 17, 2016
| + s.fakeHomeSuite.TearDownSuite(c) | ||
| + s.IsolationSuite.TearDownSuite(c) | ||
| +} | ||
| + | ||
| func (s *fakeHomeSuite) TestHomeCreated(c *gc.C) { | ||
| // A fake home is created and set. | ||
| s.fakeHomeSuite.SetUpTest(c) |
jameinel
Mar 17, 2016
Owner
We only create the fakeHomeSuite one time in SetUpSuite() thus we should call fakeHomeSuite.SetUpSuite() there, and then tear it down during TearDownSuite(), IMO.
The tests themselves are just calling SetUpTest() and TearDownTest()
|
LGTM |
jameinel commentedMar 17, 2016
If you call AddCleanup from a Test that uses a non-pointer receiver, then the cleanup
will actually never be called, because the original suite is no longer around.
Also, make AddCleanup automatically act like AddSuiteCleanup if it is called while we aren't inside a Test context. That way thinks like PatchValue actually work like we think they do, rather than having them just not work at all.