Skip to content

Commit

Permalink
satisfy testifylint
Browse files Browse the repository at this point in the history
  • Loading branch information
muir committed Jul 20, 2024
1 parent 05854fe commit d3af39e
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 25 deletions.
2 changes: 1 addition & 1 deletion bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
2 changes: 1 addition & 1 deletion cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions characterize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion filler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
5 changes: 3 additions & 2 deletions match_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

var (
Expand Down Expand Up @@ -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()
}
Expand Down
5 changes: 5 additions & 0 deletions overrides_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
3 changes: 2 additions & 1 deletion regressions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down Expand Up @@ -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))
}
Expand Down
2 changes: 1 addition & 1 deletion reorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
56 changes: 38 additions & 18 deletions run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down Expand Up @@ -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)
})
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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() {}))
})
}
Expand Down Expand Up @@ -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) ")
}
})
}

Expand Down Expand Up @@ -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)
}))
})
}
Expand Down
1 change: 1 addition & 0 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ func TestCurry(t *testing.T) {
}, "curry")
return
} else {
//nolint:testifylint
if !assert.NoError(t, err, "curry") {
return
}
Expand Down

0 comments on commit d3af39e

Please sign in to comment.