/usr/share/gocode/src/github.com/onsi/gomega/gexec/exit_matcher_test.go is in golang-gomega-dev 1.0+git20160910.d59fa0a-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | package gexec_test
import (
. "github.com/onsi/gomega/gexec"
"os/exec"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
type NeverExits struct{}
func (e NeverExits) ExitCode() int {
return -1
}
var _ = Describe("ExitMatcher", func() {
var command *exec.Cmd
var session *Session
BeforeEach(func() {
var err error
command = exec.Command(fireflyPath, "0")
session, err = Start(command, nil, nil)
Ω(err).ShouldNot(HaveOccurred())
})
Describe("when passed something that is an Exiter", func() {
It("should act normally", func() {
failures := InterceptGomegaFailures(func() {
Ω(NeverExits{}).Should(Exit())
})
Ω(failures[0]).Should(ContainSubstring("Expected process to exit. It did not."))
})
})
Describe("when passed something that is not an Exiter", func() {
It("should error", func() {
failures := InterceptGomegaFailures(func() {
Ω("aardvark").Should(Exit())
})
Ω(failures[0]).Should(ContainSubstring("Exit must be passed a gexec.Exiter"))
})
})
Context("with no exit code", func() {
It("should say the right things when it fails", func() {
Ω(session).ShouldNot(Exit())
failures := InterceptGomegaFailures(func() {
Ω(session).Should(Exit())
})
Ω(failures[0]).Should(ContainSubstring("Expected process to exit. It did not."))
Eventually(session).Should(Exit())
Ω(session).Should(Exit())
failures = InterceptGomegaFailures(func() {
Ω(session).ShouldNot(Exit())
})
Ω(failures[0]).Should(ContainSubstring("Expected process not to exit. It did."))
})
})
Context("with an exit code", func() {
It("should say the right things when it fails", func() {
Ω(session).ShouldNot(Exit(0))
Ω(session).ShouldNot(Exit(1))
failures := InterceptGomegaFailures(func() {
Ω(session).Should(Exit(0))
})
Ω(failures[0]).Should(ContainSubstring("Expected process to exit. It did not."))
Eventually(session).Should(Exit(0))
Ω(session).Should(Exit(0))
failures = InterceptGomegaFailures(func() {
Ω(session).Should(Exit(1))
})
Ω(failures[0]).Should(ContainSubstring("to match exit code:"))
Ω(session).ShouldNot(Exit(1))
failures = InterceptGomegaFailures(func() {
Ω(session).ShouldNot(Exit(0))
})
Ω(failures[0]).Should(ContainSubstring("not to match exit code:"))
})
})
Describe("bailing out early", func() {
It("should bail out early once the process exits", func() {
t := time.Now()
failures := InterceptGomegaFailures(func() {
Eventually(session).Should(Exit(1))
})
Ω(time.Since(t)).Should(BeNumerically("<=", 500*time.Millisecond))
Ω(failures).Should(HaveLen(1))
})
})
})
|