Codebase list golang-gomega / 8e3aa2e
gexec.Exit() takes a gexec.Exiter Signed-off-by: Eric Malm <emalm@pivotallabs.com> Ted Young authored 9 years ago Eric Malm committed 9 years ago
2 changed file(s) with 25 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
3636 actualExitCode int
3737 }
3838
39 type Exiter interface {
40 ExitCode() int
41 }
42
3943 func (m *exitMatcher) Match(actual interface{}) (success bool, err error) {
40 session, ok := actual.(*Session)
44 exiter, ok := actual.(Exiter)
4145 if !ok {
42 return false, fmt.Errorf("Exit must be passed a gexit session. Got:\n%s", format.Object(actual, 1))
46 return false, fmt.Errorf("Exit must be passed a gexec.Exiter (Missing method ExitCode() int) Got:\n%s", format.Object(actual, 1))
4347 }
4448
45 m.actualExitCode = session.ExitCode()
49 m.actualExitCode = exiter.ExitCode()
4650
4751 if m.actualExitCode == -1 {
4852 return false, nil
77 . "github.com/onsi/ginkgo"
88 . "github.com/onsi/gomega"
99 )
10
11 type NeverExits struct{}
12
13 func (e NeverExits) ExitCode() int {
14 return -1
15 }
1016
1117 var _ = Describe("ExitMatcher", func() {
1218 var command *exec.Cmd
1925 Ω(err).ShouldNot(HaveOccurred())
2026 })
2127
22 Describe("when passed something that is not a session", func() {
28 Describe("when passed something that is an Exiter", func() {
29 It("should act normally", func() {
30 failures := interceptFailures(func() {
31 Ω(NeverExits{}).Should(Exit())
32 })
33
34 Ω(failures[0]).Should(ContainSubstring("Expected process to exit. It did not."))
35 })
36 })
37
38 Describe("when passed something that is not an Exiter", func() {
2339 It("should error", func() {
2440 failures := interceptFailures(func() {
2541 Ω("aardvark").Should(Exit())
2642 })
2743
28 Ω(failures[0]).Should(ContainSubstring("Exit must be passed a gexit session"))
44 Ω(failures[0]).Should(ContainSubstring("Exit must be passed a gexec.Exiter"))
2945 })
3046 })
3147