-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
panicx.LocationOfFunc()
and LocationOfCall()
.
- Loading branch information
Showing
6 changed files
with
231 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package panicx_test | ||
|
||
// This file contains definitions used within tests that check for specific line | ||
// numbers. To minimize test disruption edit this file as infrequently as | ||
// possible. | ||
// | ||
// New additions should always be made at the end so that the line numbers of | ||
// existing definitions do not change. The padding below can be removed as | ||
// imports statements added. | ||
|
||
import ( | ||
"github.com/dogmatiq/dogma" | ||
. "github.com/dogmatiq/testkit/engine/panicx" | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
// import padding | ||
) | ||
|
||
func doNothing() {} | ||
func panicWithUnexpectedMessage() { panic(dogma.UnexpectedMessage) } | ||
func locationOfCallLayer1() Location { return LocationOfCall() } | ||
func locationOfCallLayer2() Location { return locationOfCallLayer1() } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package panicx | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/dogmatiq/configkit" | ||
"github.com/dogmatiq/dogma" | ||
) | ||
|
||
// UnexpectedBehavior is a panic value that occurs when a handler exhibits some | ||
// behavior that the engine did not expect. | ||
// | ||
// Often this means it has violated the Dogma specification. | ||
type UnexpectedBehavior struct { | ||
// Handler is the non-compliant handler. | ||
Handler configkit.RichHandler | ||
|
||
// Interface is the name of the interface containing the method with the | ||
// unexpected behavior. | ||
Interface string | ||
|
||
// Method is the name of the method that behaved unexpectedly. | ||
Method string | ||
|
||
// Implementation is the value that implements the nominated interface. | ||
Implementation interface{} | ||
|
||
// Message is the message that was being handled at the time, if any. | ||
Message dogma.Message | ||
|
||
// Description is a human-readable description of the behavior. | ||
Description string | ||
|
||
// Location is the engine's best attempt at pinpointing the location of the | ||
// unexpected behavior. | ||
Location Location | ||
} | ||
|
||
func (x UnexpectedBehavior) String() string { | ||
return fmt.Sprintf( | ||
"the '%s' %s message handler behaved unexpectedly in %T.%s(): %s", | ||
x.Handler.Identity().Name, | ||
x.Handler.HandlerType(), | ||
x.Implementation, | ||
x.Method, | ||
x.Description, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package panicx_test | ||
|
||
import ( | ||
"github.com/dogmatiq/configkit" | ||
"github.com/dogmatiq/dogma" | ||
. "github.com/dogmatiq/dogma/fixtures" | ||
. "github.com/dogmatiq/testkit/engine/panicx" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("type UnexpectedBehavior", func() { | ||
config := configkit.FromProjection( | ||
&ProjectionMessageHandler{ | ||
ConfigureFunc: func(c dogma.ProjectionConfigurer) { | ||
c.Identity("<name>", "<key>") | ||
c.ConsumesEventType(MessageE{}) | ||
}, | ||
}, | ||
) | ||
|
||
Describe("func String()", func() { | ||
It("returns a description of the panic", func() { | ||
x := UnexpectedBehavior{ | ||
Handler: config, | ||
Interface: "<interface>", | ||
Method: "<method>", | ||
Implementation: config.Handler(), | ||
Description: "<description>", | ||
} | ||
|
||
Expect(x.String()).To(Equal( | ||
"the '<name>' projection message handler behaved unexpectedly in *fixtures.ProjectionMessageHandler.<method>(): <description>", | ||
)) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters