Merge lp://qastaging/~rogpeppe/gocheck/missing-method-panic into lp://qastaging/gocheck
Status: | Work in progress |
---|---|
Proposed branch: | lp://qastaging/~rogpeppe/gocheck/missing-method-panic |
Merge into: | lp://qastaging/gocheck |
Diff against target: |
919 lines (+434/-173) 5 files modified
fixture_test.go (+167/-73) gocheck.go (+226/-59) gocheck_test.go (+3/-6) run.go (+1/-2) run_test.go (+37/-33) |
To merge this branch: | bzr merge lp://qastaging/~rogpeppe/gocheck/missing-method-panic |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Gustavo Niemeyer | Pending | ||
Review via email:
|
Description of the change
gocheck: diagnose missing methods
Because of the way that gocheck works, there's no
diagnostic if methods are accidentally omitted through
a type-related issue. This proposal changes gocheck
so that such methods are treated as if they had panicked.
It diagnosed three such examples in the current juju trunk.
Two examples that are now diagnosed:
1) Methods which are missing because they're defined
as pointer methods but the value passed to Suite is
a value type.
type mySuite struct{}
func (s *mySuite) Test1(c *C) {}
var _ = Suite(mySuite{})
This gives the message:
-------
PANIC: foo_test.go:9: mySuite.Test1
... Panic: pointer method mySuite.Test1 defined on value type
2) Fixture methods which are missing because
two fixture suites have been embedded.
type helperSuite1 struct{}
func (helperSuite1) SetUpTest(c *C) {}
type helperSuite2 struct{}
func (helperSuite2) SetUpTest(c *C) {}
type mySuite struct {
helperSuite1
helperSuite2
}
func (s mySuite) Test1(c *C) {}
var _ = Suite(mySuite{})
This gives the message:
-------
PANIC: foo_test.go:9: helperSuite1.
... Panic: clashing definitions of mySuite.SetUpTest: mySuite.
-------
PANIC: foo_test.go:18: mySuite.Test1
... Panic: Fixture has panicked (see related PANIC)
The testing for this feature is not yet complete, but I don't
want to spend any more time on it if it's not considered a
good way forward.
The change does also involve one change to the current
semantics - if a method has been defined with an
incorrect type signature, it will be treated as if it
panics in the same way as above, as it seems consistent
with the above behaviour (and it simplifies the code).
It would be easy to reinstate the old behaviour if desired
(the relevant tests are skipped pending a decision).
Unmerged revisions
- 82. By Roger Peppe
-
fix a couple of bugs from the merge
- 81. By Roger Peppe
-
diagnose missing methods
Reviewers: mp+121193_ code.launchpad. net,
Message:
Please take a look.
Description:
gocheck: diagnose missing methods
Because of the way that gocheck works, there's no
diagnostic if methods are accidentally omitted through
a type-related issue. This proposal changes gocheck
so that such methods are treated as if they had panicked.
It diagnosed three such examples in the current juju trunk.
Two examples that are now diagnosed:
1) Methods which are missing because they're defined
as pointer methods but the value passed to Suite is
a value type.
type mySuite struct{}
func (s *mySuite) Test1(c *C) {}
var _ = Suite(mySuite{})
This gives the message: ------- ------- ------- ------- ------- ------- ------- ------- -------
-------
PANIC: foo_test.go:9: mySuite.Test1
... Panic: pointer method mySuite.Test1 defined on value type
2) Fixture methods which are missing because
two fixture suites have been embedded.
type helperSuite1 struct{}
func (helperSuite1) SetUpTest(c *C) {}
type helperSuite2 struct{}
func (helperSuite2) SetUpTest(c *C) {}
type mySuite struct {
helperSuite1
helperSuite2
}
func (s mySuite) Test1(c *C) {}
var _ = Suite(mySuite{})
This gives the message:
------- ------- ------- ------- ------- ------- ------- ------- ------- ------- SetUpTest
PANIC: foo_test.go:9: helperSuite1.
... Panic: clashing definitions of mySuite.SetUpTest: helperSuite1. SetUpTest, mySuite. helperSuite2. SetUpTest
mySuite.
------- ------- ------- ------- ------- ------- ------- ------- ------- -------
PANIC: foo_test.go:18: mySuite.Test1
... Panic: Fixture has panicked (see related PANIC)
The testing for this feature is not yet complete, but I don't
want to spend any more time on it if it's not considered a
good way forward.
The change does also involve one change to the current
semantics - if a method has been defined with an
incorrect type signature, it will be treated as if it
panics in the same way as above, as it seems consistent
with the above behaviour (and it simplifies the code).
It would be easy to reinstate the old behaviour if desired
(the relevant tests are skipped pending a decision).
https:/ /code.launchpad .net/~rogpeppe/ gocheck/ missing- method- panic/+ merge/121193
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/6485060/
Affected files:
A [revision details]
M fixture_test.go
M gocheck.go
M gocheck_test.go
M run.go
M run_test.go