Skip to content

Commit

Permalink
allow generic Suite input for RunSuite
Browse files Browse the repository at this point in the history
  • Loading branch information
adamluzsi committed Jun 23, 2024
1 parent dfc5b7c commit 915a951
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,7 @@ func TestRunSuite_spectAsSuite(t *testing.T) {
suite2.Test("tst2", func(t *testcase.T) { name2 = t.Name() })

dtb := &doubles.TB{}
testcase.RunSuite(dtb, suite1, suite2.AsSuite())
testcase.RunSuite[testcase.Suite](dtb, suite1, suite2.AsSuite())

assert.True(t, strings.HasSuffix(name1, "tst1"))
assert.True(t, strings.HasSuffix(name2, "tst2"))
Expand Down
4 changes: 2 additions & 2 deletions Suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type OpenSuite interface {
// RunSuite is a helper function that makes execution one or many Suite easy.
// By using RunSuite, you don't have to distinguish between testing or benchmark execution mod.
// It supports *testing.T, *testing.B, *testcase.T, *testcase.Spec and CustomTB test runners.
func RunSuite[TBS anyTBOrSpec](tb TBS, contracts ...Suite) {
func RunSuite[S Suite, TBS anyTBOrSpec](tb TBS, contracts ...S) {
if tb, ok := any(tb).(helper); ok {
tb.Helper()
}
Expand All @@ -46,7 +46,7 @@ func RunSuite[TBS anyTBOrSpec](tb TBS, contracts ...Suite) {
}
}

func RunOpenSuite[TBS anyTBOrSpec](tb TBS, contracts ...OpenSuite) {
func RunOpenSuite[OS OpenSuite, TBS anyTBOrSpec](tb TBS, contracts ...OS) {
if tb, ok := any(tb).(helper); ok {
tb.Helper()
}
Expand Down
19 changes: 19 additions & 0 deletions Suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,22 @@ func TestSpec_AsSuite_merge(t *testing.T) {

// TODO: cover further
}

type SampleContractType interface {
testcase.Suite
testcase.OpenSuite
}

func SampleContracts() []SampleContractType {
return []SampleContractType{}
}

func ExampleRunSuite() {
s := testcase.NewSpec(nil)
testcase.RunSuite(s, SampleContracts()...)
}

func ExampleRunOpenSuite() {
s := testcase.NewSpec(nil)
testcase.RunOpenSuite(s, SampleContracts()...)
}

0 comments on commit 915a951

Please sign in to comment.