testifylint icon indicating copy to clipboard operation
testifylint copied to clipboard

feature: Use `Contains` instead of `strings.Contains`

Open nickajacks1 opened this issue 1 year ago • 3 comments

Using assert.True on strings.Contains does not print out useful information about the arguments in the case of a failure. assert.Contains, on the other hand, will report both values on failure.

❌
     assert.True(t, strings.Contains(s, "abc123"))
     assert.True(t, strings.Contains(string(b), "abc123"))

✅
     assert.Contains(t, s, "abc123")
     assert.Contains(t, string(b), "abc123")

assert.Contains doesn't seem to work well with byte slices, so users would need to convert the bytes to strings. Consequently, I'm not too sure about including bytes.Contains in the same lint rule.

nickajacks1 avatar Jan 21 '24 21:01 nickajacks1

Hi, @nickajacks1!

Thank you for proposal.

assert.Contains doesn't seem to work well with byte slices

offtop: maybe to open issue/PR in testify?

Antonboom avatar Jan 23 '24 20:01 Antonboom

Good idea, I'll look into that and report back here.

nickajacks1 avatar Jan 23 '24 20:01 nickajacks1

Full-featured implementation is blocked by https://github.com/stretchr/testify/pull/1526

Antonboom avatar Feb 08 '24 11:02 Antonboom