Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added support for types assignable to special step argument types #28

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,13 @@ func (r *Runner) registerSuite(suiteType interface{}) *Runner {
continue
}

if getter, ok := r.supportedSpecialArgs[field.Type]; ok {
r.suiteInjectors = append(r.suiteInjectors, &suiteInjector{getValue: getter, field: field})
if field.Type == rapidTType {
r.suiteUsesRapid = true
for specialArgType, getter := range r.supportedSpecialArgs {
if field.Type.AssignableTo(specialArgType) {
r.suiteInjectors = append(r.suiteInjectors, &suiteInjector{getValue: getter, field: field})
if field.Type == rapidTType {
r.suiteUsesRapid = true
}
break
}
}
}
Expand Down
48 changes: 48 additions & 0 deletions simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,51 @@ func (s simpleSuiteNP) IHaveLeft(a int64) {
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)
}
}
Loading