Skip to content

Commit

Permalink
breaking change: a matrix is required when using RunMatrix
Browse files Browse the repository at this point in the history
  • Loading branch information
muir committed Jun 26, 2023
1 parent c929bb1 commit f6a29ee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
9 changes: 8 additions & 1 deletion matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import (
//
// A warning about t.Parallel(): inner tests wait until outer tests finish.
// See https://go.dev/play/p/ZDaw054HeIN
//
// Matrix values must be direct arguments to RunMatrix -- they will not be extracted
// from nject.Sequences. RunParallelMatrix will fail if there is no matrix provided.
func RunParallelMatrix(t *testing.T, chain ...any) {
t.Parallel()
runMatrixTest(t, true, chain)
Expand All @@ -30,6 +33,9 @@ func RunParallelMatrix(t *testing.T, chain ...any) {
//
// A matrix is a specific type: map[string]nject.Provider. Add those to the
// chain to trigger matrix testing.
//
// Matrix values must be direct arguments to RunMatrix -- they will not be extracted
// from nject.Sequences. RunMatrix will fail if there is no matrix provided.
func RunMatrix(t *testing.T, chain ...any) {
runMatrixTest(t, false, chain)
}
Expand All @@ -50,7 +56,8 @@ func runMatrixTest(t *testing.T, parallel bool, chain []any) {

matrix, before, after := breakChain(t, chain)
if matrix == nil {
RunTest(t, combineSlices(testingT(t), chain)...)
t.Log("No matrix found in matrix testing, perhaps the specifier is in a Sequence? (not allowed)")
t.Fail()
return
}

Expand Down
11 changes: 11 additions & 0 deletions test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,14 @@ func TestExtra(t *testing.T) {
)
assert.Equal(t, 7, c)
}

func TestEmptyMatrix(t *testing.T) {
t.Skip("this test is expected to fail")
t.Parallel()
ntest.RunMatrix(t,
func() int { return 7 },
func(t *testing.T, i int) {
assert.Equal(t, 7, i)
},
)
}

0 comments on commit f6a29ee

Please sign in to comment.