diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index a18bbf9..165b55e 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -4,7 +4,7 @@ jobs: test: strategy: matrix: - go-version: [1.16.x, 1.17.x, 1.18.x, 1.19.x, 1.20.x] + go-version: [1.18.x, 1.19.x, 1.20.x, 1.21.x, 1.22.x] os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} steps: diff --git a/bind_test.go b/bind_test.go index ac894c8..cd9d639 100644 --- a/bind_test.go +++ b/bind_test.go @@ -223,7 +223,7 @@ func TestInitDependencyOnUnavailableData(t *testing.T) { var shouldWorkInit func(s0) s2 var shouldWorkInvoke func(s3) s5 err := c.Bind(&shouldWorkInvoke, &shouldWorkInit) - assert.Error(t, err) + require.Error(t, err) assert.Panics(t, func() { MustBind(c, &shouldWorkInvoke, &shouldWorkInit) }) diff --git a/cache_test.go b/cache_test.go index 5c5519e..8ea25a6 100644 --- a/cache_test.go +++ b/cache_test.go @@ -291,7 +291,7 @@ func TestCacheSizes(t *testing.T) { rw1, rw2, rw3, rw4, func(s string, d *Debugging) { - assert.True(t, len(s) > 50, "length") + assert.Greater(t, len(s), 50, "length") if count == 0 { prior = s } else { diff --git a/characterize_test.go b/characterize_test.go index 6acc94b..3df10c0 100644 --- a/characterize_test.go +++ b/characterize_test.go @@ -371,6 +371,7 @@ func TestCharacterize(t *testing.T) { originFm := newProvider(test.fn, i, test.name) fm, err := charFunc(originFm, cc) if test.expectedToError { + //nolint:testifylint assert.Error(t, err, "expected err for"+test.name) continue } else { diff --git a/filler_test.go b/filler_test.go index 8ee8f7f..0ce2725 100644 --- a/filler_test.go +++ b/filler_test.go @@ -72,6 +72,6 @@ func TestFiller(t *testing.T) { assert.Equal(t, s3(""), f5.Sub.S3, "f5.s3 not filled") }, ) - assert.NoError(t, err) + assert.NoError(t, err) //nolint:testifylint assert.True(t, called) } diff --git a/go.mod b/go.mod index acd5c40..9564fcb 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,17 @@ module github.com/muir/nject -go 1.16 +go 1.18 require ( - github.com/kr/pretty v0.2.0 // indirect github.com/muir/reflectutils v0.7.0 github.com/stretchr/testify v1.8.2 +) + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/kr/pretty v0.2.0 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/match_test.go b/match_test.go index 92628c6..630c62d 100644 --- a/match_test.go +++ b/match_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) var ( @@ -71,11 +72,11 @@ func TestBestMatch(t *testing.T) { t.Logf("\tm[%s] = %s (%s) %d", tc.Type(), d.name, d.typeCode.Type(), d.layer) } got, _, err := m.bestMatch(getTypeCode(test.Find), "searching for "+test.Name) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, test.Want.String(), got.Type().String(), test.Name) } if test.Want == nil { - assert.Panics(t, f, test.Name) + require.Panics(t, f, test.Name) } else { f() } diff --git a/overrides_error_test.go b/overrides_error_test.go index cd00aa0..7dcd756 100644 --- a/overrides_error_test.go +++ b/overrides_error_test.go @@ -24,17 +24,22 @@ func TestOverridesError(t *testing.T) { var target func(anotherType) error t.Log("test: okay because no error bubbling up") + //nolint:testifylint assert.NoError(t, Sequence("A", danger, finalWithoutError).Bind(&target, nil)) t.Log("test: should fail because the final function returns error that gets clobbered") + //nolint:testifylint assert.Error(t, Sequence("B", danger, finalWithError).Bind(&target, nil)) t.Log("test: should fail because there is a terminal-error injector that gets clobbered") + //nolint:testifylint assert.Error(t, Sequence("C", danger, returnsTerminal, finalWithoutError).Bind(&target, nil)) t.Log("test: okay because marked even though the final function returns error that gets clobbered") + //nolint:testifylint assert.NoError(t, Sequence("B", OverridesError(danger), finalWithError).Bind(&target, nil)) t.Log("test: okay because marked even though there is a terminal-error injector that gets clobbered") + //nolint:testifylint assert.NoError(t, Sequence("C", OverridesError(danger), returnsTerminal, finalWithoutError).Bind(&target, nil)) } diff --git a/regressions_test.go b/regressions_test.go index b5fffb4..3fbb79e 100644 --- a/regressions_test.go +++ b/regressions_test.go @@ -180,7 +180,7 @@ func TestMissingAutoDesiredRegression(t *testing.T) { twoCalled := false var initFunc func() var invoke http.HandlerFunc - assert.NoError(t, Sequence("test", + require.NoError(t, Sequence("test", Cacheable(func(*Debugging) string { oneCalled = true return "" @@ -906,6 +906,7 @@ func TestRegression9(t *testing.T) { }))), Provide("user-chain-3", func(_ i005, _ s054, _ s014, _ s019, _ s012) { called["user-chain-3"]++ }), ).Bind(&invoker, nil) + //nolint:testifylint if !assert.NoError(t, err, "bind error") { t.Log(DetailedError(err)) } diff --git a/reorder_test.go b/reorder_test.go index b6ab284..97362b5 100644 --- a/reorder_test.go +++ b/reorder_test.go @@ -161,7 +161,7 @@ func TestReorderInOut(t *testing.T) { type r string var final string var dd *Debugging - assert.NoError(t, Run(t.Name(), + require.NoError(t, Run(t.Name(), func() string { return "start" }, diff --git a/run_test.go b/run_test.go index bd017c0..7f8f510 100644 --- a/run_test.go +++ b/run_test.go @@ -40,7 +40,7 @@ var testSeq = Cacheable(Sequence("TBF", func TestRunWorks(t *testing.T) { wrapTest(t, func(t *testing.T) { called := false - assert.NoError(t, Run("run1", + require.NoError(t, Run("run1", s3("s3 value"), s0("s0 value"), testSeq, func(s s5) { @@ -54,7 +54,7 @@ func TestRunWorks(t *testing.T) { func TestRunMissingValue(t *testing.T) { wrapTest(t, func(t *testing.T) { called := false - assert.Error(t, Run("run1", + require.Error(t, Run("run1", s0("s0 value"), testSeq, func(s s4) { assert.Equal(t, s4("s4 value"), s) @@ -85,11 +85,10 @@ func testRunReturnsError(t *testing.T, e error) { return e }) if e == nil { - assert.NoError(t, err) + require.NoError(t, err) } else { - if assert.Error(t, err) { - assert.Equal(t, e.Error(), err.Error()) - } + require.Error(t, err) + assert.Equal(t, e.Error(), err.Error()) } assert.True(t, called) }) @@ -124,7 +123,7 @@ func TestNilLiterals(t *testing.T) { wrapTest(t, func(t *testing.T) { var intp *int called := false - assert.NoError(t, Run("test nil", + require.NoError(t, Run("test nil", intp, nil, func(ip *int) error { @@ -141,7 +140,7 @@ func TestUnusedLiteral(t *testing.T) { wrapTest(t, func(t *testing.T) { var intp *int called := false - assert.NoError(t, Run("test unused", + require.NoError(t, Run("test unused", intp, "seven", func(s string) error { @@ -214,23 +213,35 @@ func TestWrappersBindError(t *testing.T) { func TestEmpties(t *testing.T) { wrapTest(t, func(t *testing.T) { + //nolint:testifylint assert.Error(t, Run("no final func")) + //nolint:testifylint assert.Error(t, Run("no final func", nil)) + //nolint:testifylint assert.NoError(t, Run("no final func", func() {})) seq := Sequence("empty") + //nolint:testifylint assert.Error(t, Run("no final func", seq)) + //nolint:testifylint assert.Error(t, Run("no final func", seq, nil)) + //nolint:testifylint assert.NoError(t, Run("no final func", seq, func() {})) seq2 := seq.Append("nothing") + //nolint:testifylint assert.Error(t, Run("no final func", seq2)) + //nolint:testifylint assert.Error(t, Run("no final func", seq2, nil)) + //nolint:testifylint assert.NoError(t, Run("no final func", seq2, func() {})) seq3 := seq.Append("more nothing", Sequence("empty too")) + //nolint:testifylint assert.Error(t, Run("no final func", seq3)) + //nolint:testifylint assert.Error(t, Run("no final func", seq3, nil)) + //nolint:testifylint assert.NoError(t, Run("no final func", seq3, func() {})) }) } @@ -295,24 +306,33 @@ func TestAppend(t *testing.T) { func TestErrorStrings(t *testing.T) { wrapTest(t, func(t *testing.T) { invalid := func(int, func()) {} + //nolint:testifylint assert.NoError(t, Run("one", func() {})) err := Run("one", invalid, func() {}) - assert.Error(t, err) - assert.Contains(t, err.Error(), "one(0) ") + //nolint:testifylint + if assert.Error(t, err) { + assert.Contains(t, err.Error(), "one(0) ") + } err = Run("two", Provide("i-name", invalid), func() {}) - assert.Error(t, err) - assert.NotContains(t, err.Error(), "two(0)") - assert.Contains(t, err.Error(), "i-name ") + //nolint:testifylint + if assert.Error(t, err) { + assert.NotContains(t, err.Error(), "two(0)") + assert.Contains(t, err.Error(), "i-name ") + } err = Run("three", nil, invalid, func() {}) - assert.Error(t, err) - assert.Contains(t, err.Error(), "three(1) ") + //nolint:testifylint + if assert.Error(t, err) { + assert.Contains(t, err.Error(), "three(1) ") + } err = Run("four", nil, nil, Cacheable(invalid), func() {}) - assert.Error(t, err) - assert.Contains(t, err.Error(), "four(2) ") + //nolint:testifylint + if assert.Error(t, err) { + assert.Contains(t, err.Error(), "four(2) ") + } }) } @@ -406,7 +426,7 @@ func TestInjectorsDebugging(t *testing.T) { s3("s3 value"), s0("s0 value"), testSeq, func(s s5, d *Debugging) { - assert.True(t, len(d.Trace) > 10000, d.Trace) + assert.Greater(t, len(d.Trace), 10000, d.Trace) })) }) } diff --git a/utils_test.go b/utils_test.go index 6e91b66..1b703d8 100644 --- a/utils_test.go +++ b/utils_test.go @@ -211,6 +211,7 @@ func TestCurry(t *testing.T) { }, "curry") return } else { + //nolint:testifylint if !assert.NoError(t, err, "curry") { return }