-
Notifications
You must be signed in to change notification settings - Fork 9
/
simple_test.go
107 lines (87 loc) · 2.09 KB
/
simple_test.go
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
package gocuke_test
import (
"testing"
"github.com/regen-network/gocuke"
)
func TestSimple(t *testing.T) {
gocuke.NewRunner(t, &simpleSuite{}).Path("examples/simple/simple.feature").Run()
}
type simpleSuite struct {
gocuke.TestingT
cukes int64
}
func (s *simpleSuite) IHaveCukes(a int64) {
s.cukes = a
}
func (s *simpleSuite) IEat(a int64) {
s.cukes -= a
}
func (s *simpleSuite) IHaveLeft(a int64) {
if a != s.cukes {
s.Fatalf("expected %d cukes, have %d", a, s.cukes)
}
}
// test if a struct that doesn't use a pointer and a global var
func TestSimpleNonPointer(t *testing.T) {
gocuke.
NewRunner(t, simpleSuiteNP{}).
Path("examples/simple/simple.feature").
NonParallel().
Run()
}
var globalCukes int64
type simpleSuiteNP struct {
gocuke.TestingT
}
func (s simpleSuiteNP) IHaveCukes(a int64) {
globalCukes = a
}
func (s simpleSuiteNP) IEat(a int64) {
globalCukes -= a
}
func (s simpleSuiteNP) IHaveLeft(a int64) {
if a != globalCukes {
s.Fatalf("expected %d cukes, have %d", a, globalCukes)
}
}
// test a struct using a different interface compatible with gocuke.TestingT
func TestSimpleCompat(t *testing.T) {
gocuke.NewRunner(t, &simpleSuiteCompat{}).Path("examples/simple/simple.feature").Run()
}
type TestingTCompat interface {
Cleanup(func())
Error(args ...interface{})
Errorf(format string, args ...interface{})
Fail()
FailNow()
Failed() bool
Fatal(args ...interface{})
Fatalf(format string, args ...interface{})
Log(args ...interface{})
Logf(format string, args ...interface{})
Skip(args ...interface{})
SkipNow()
Skipf(format string, args ...interface{})
Helper()
// Not included in gocuke.TestingT
Name() string
}
type simpleSuiteCompat struct {
TestingTCompat
cukes int64
}
func (s *simpleSuiteCompat) IHaveCukes(a int64) {
// These calls to s.LogF fail if s.TestingTCompat is nil
s.Logf("I have %d cukes", a)
s.cukes = a
}
func (s *simpleSuiteCompat) IEat(a int64) {
s.Logf("I eat %d", a)
s.cukes -= a
}
func (s *simpleSuiteCompat) IHaveLeft(a int64) {
s.Logf("I have %d left?", a)
if a != s.cukes {
s.Fatalf("expected %d cukes, have %d", a, s.cukes)
}
}