testify icon indicating copy to clipboard operation
testify copied to clipboard

Fix custom messages in comparison-assertions

Open benjaminjkraft opened this issue 3 years ago • 4 comments

Summary

This PR fixes custom messages in comparison-assertions.

Changes

The assesrtions now pass varargs rather than a single slice arg.

Motivation

The comparison-assertions were passing msgAndArgs as a slice rather than varargs, which meant that the entire message-and-arguments got printed as a single slice. Now it gets printf-ed correctly. See test cases for examples.

Edit: Fixes the rest of #1034 (the other part was fixed by #1026).

benjaminjkraft avatar Nov 05 '20 02:11 benjaminjkraft

Hi @boyan-soubachov -- thanks for the look! The test I added should cover the regression, I think -- if you run it without the other changes it fails with e.g.

    assertion_compare_test.go:266: 
                Error Trace:
                Error:          "\n\tError Trace:\t\n\tError:      \t\"1\" is not greater than \"2\"\n\tMessages:   \t[%v wasn't greater 1]\n" does not contain "1 wasn't greater"
                Test:           TestComparisonCustomMessages

Let me know if there was something different you wanted, I'm happy to add it!

(FYI I've also fixed the merge conflict which is from #1026.)

benjaminjkraft avatar Jan 22 '21 02:01 benjaminjkraft

can we merge this? :) thanks

codyohl avatar Apr 09 '21 02:04 codyohl

@boyan-soubachov PTAL

AlekSi avatar May 19 '21 19:05 AlekSi

Looks like the issue was fixed in https://github.com/stretchr/testify/pull/1150/, so this PR can be closed.

lambdanis avatar Apr 21 '22 21:04 lambdanis

@benjaminjkraft Thanks for the patch. Unfortunately it hasn't been noticed earlier.

@lambdanis Thanks for the duplicate report.

dolmen avatar Mar 06 '24 01:03 dolmen