Skip to content

Commit

Permalink
change run conract api to use singular form instead of plural - final…
Browse files Browse the repository at this point in the history
…ize it
  • Loading branch information
adamluzsi committed Feb 8, 2021
1 parent cf836f4 commit c5975ba
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Contract interface {
Benchmark(*testing.B)
}

func RunContracts(tb interface{}, contracts ...Contract) {
func RunContract(tb interface{}, contracts ...Contract) {
for _, c := range contracts {
switch tb := tb.(type) {
case *testing.T:
Expand All @@ -32,11 +32,11 @@ func RunContracts(tb interface{}, contracts ...Contract) {
c.Benchmark(tb)

case *T:
RunContracts(tb.TB, c)
RunContract(tb.TB, c)

case *Spec:
c := c // copy to avoid reference overrides from "for"
tb.Test(fullyQualifiedName(c), func(t *T) { RunContracts(t, c) })
tb.Test(fullyQualifiedName(c), func(t *T) { RunContract(t, c) })

default:
panic(fmt.Errorf(`unknown test runner type: %T`, tb))
Expand Down
10 changes: 5 additions & 5 deletions Contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ import (
func TestRunContracts(t *testing.T) {
t.Run(`when TB is *testing.T`, func(t *testing.T) {
sT := &RunContractExampleContract{}
testcase.RunContracts(&testing.T{}, sT)
testcase.RunContract(&testing.T{}, sT)
require.True(t, sT.TestWasCalled)
require.False(t, sT.BenchmarkWasCalled)
})

t.Run(`when TB is *testing.B`, func(t *testing.T) {
sB := &RunContractExampleContract{}
testcase.RunContracts(&testing.B{}, sB)
testcase.RunContract(&testing.B{}, sB)
require.False(t, sB.TestWasCalled)
require.True(t, sB.BenchmarkWasCalled)
})

t.Run(`when TB is *testcase.T with *testing.T under the hood`, func(t *testing.T) {
sT := &RunContractExampleContract{}
testcase.RunContracts(&testcase.T{TB: &testing.T{}}, sT)
testcase.RunContract(&testcase.T{TB: &testing.T{}}, sT)
require.True(t, sT.TestWasCalled)
require.False(t, sT.BenchmarkWasCalled)
})

t.Run(`when TB is *testcase.T with *testing.B under the hood`, func(t *testing.T) {
sT := &RunContractExampleContract{}
testcase.RunContracts(&testcase.T{TB: &testing.B{}}, sT)
testcase.RunContract(&testcase.T{TB: &testing.B{}}, sT)
require.False(t, sT.TestWasCalled)
require.True(t, sT.BenchmarkWasCalled)
})
Expand All @@ -39,7 +39,7 @@ func TestRunContracts(t *testing.T) {
s := testcase.NewSpec(t)
a := &RunContractExampleContract{}
b := &RunContractExampleContract{}
testcase.RunContracts(s, a, b)
testcase.RunContract(s, a, b)
s.Finish()
require.True(t, a.TestWasCalled)
require.False(t, a.BenchmarkWasCalled)
Expand Down

0 comments on commit c5975ba

Please sign in to comment.