/usr/share/gocode/src/github.com/smartystreets/goconvey/convey/story_conventions_test.go is in golang-github-smartystreets-goconvey-dev 1.5.0-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 convey
import (
"fmt"
"strings"
"testing"
"github.com/smartystreets/goconvey/execution"
)
func TestMissingTopLevelGoTestReferenceCausesPanic(t *testing.T) {
output := map[string]bool{}
defer expectEqual(t, false, output["good"])
defer requireGoTestReference(t)
Convey("Hi", func() {
output["bad"] = true // this shouldn't happen
})
}
func requireGoTestReference(t *testing.T) {
err := recover()
if err == nil {
t.Error("We should have recovered a panic here (because of a missing *testing.T reference)!")
} else {
expectEqual(t, execution.MissingGoTest, err)
}
}
func TestMissingTopLevelGoTestReferenceAfterGoodExample(t *testing.T) {
output := map[string]bool{}
defer func() {
expectEqual(t, true, output["good"])
expectEqual(t, false, output["bad"])
}()
defer requireGoTestReference(t)
Convey("Good example", t, func() {
output["good"] = true
})
Convey("Bad example", func() {
output["bad"] = true // shouldn't happen
})
}
func TestExtraReferencePanics(t *testing.T) {
output := map[string]bool{}
defer func() {
err := recover()
if err == nil {
t.Error("We should have recovered a panic here (because of an extra *testing.T reference)!")
} else if !strings.HasPrefix(fmt.Sprintf("%v", err), execution.ExtraGoTest) {
t.Error("Should have panicked with the 'extra go test' error!")
}
if output["bad"] {
t.Error("We should NOT have run the bad example!")
}
}()
Convey("Good example", t, func() {
Convey("Bad example - passing in *testing.T a second time!", t, func() {
output["bad"] = true // shouldn't happen
})
})
}
func TestParseRegistrationMissingRequiredElements(t *testing.T) {
defer func() {
if r := recover(); r != nil {
if r != "You must provide a name (string), then a *testing.T (if in outermost scope), and then an action (func())." {
t.Errorf("Incorrect panic message.")
}
}
}()
Convey()
t.Errorf("goTest should have panicked in Convey(...) and then recovered in the defer func().")
}
func TestParseRegistration_MissingNameString(t *testing.T) {
defer func() {
if r := recover(); r != nil {
if r != parseError {
t.Errorf("Incorrect panic message.")
}
}
}()
action := func() {}
Convey(action)
t.Errorf("goTest should have panicked in Convey(...) and then recovered in the defer func().")
}
func TestParseRegistration_MissingActionFunc(t *testing.T) {
defer func() {
if r := recover(); r != nil {
if r != parseError {
t.Errorf("Incorrect panic message: '%s'", r)
}
}
}()
Convey("Hi there", 12345)
t.Errorf("goTest should have panicked in Convey(...) and then recovered in the defer func().")
}
|