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

breaking change: a matrix is required when using RunMatrix #26

Merged
merged 1 commit into from
Jun 26, 2023
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
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)
},
)
}