From f50609b6b5ea9bf8f4172908a51f90bfbdb33007 Mon Sep 17 00:00:00 2001 From: Brandon Bonds Date: Wed, 10 Jan 2024 17:31:18 -0600 Subject: [PATCH 1/2] Fixed a nil dereference when supplying a custom type for special step arguments --- runner.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/runner.go b/runner.go index d1cfd5a..97bdcd1 100644 --- a/runner.go +++ b/runner.go @@ -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 } } } From 820beb178cc11cf130002c8574121a9750d2cb26 Mon Sep 17 00:00:00 2001 From: Brandon Bonds Date: Tue, 16 Jan 2024 17:01:19 -0600 Subject: [PATCH 2/2] test: simple test using an interface compatible with gocuke.TestingT --- simple_test.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/simple_test.go b/simple_test.go index e504376..0f90a53 100644 --- a/simple_test.go +++ b/simple_test.go @@ -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) + } +}