google/truth

Better message if assertThat(string).matches(equalString) fails

cpovirk opened this issue · 1 comments

As noted in https://stackoverflow.com/q/64616887/28465, it's easy for users to write matches when they mean isEqualTo. (Perhaps we should have picked a name like "matchesRegex"; oops [edit: probably "matchesPattern," a colleague points out].) If someone writes matches("$5") and the input string is "$5," our failure message could say "Hey, that doesn't match the regex, but did you mean isEqualTo?"

(If users make this mistake with doesNotMatch, there's usually not much we can do to detect it, since the test just passes silently....)

@cpovirk I added a PR #789 for this Issue hope thats ok. If you think a different message would be better lmk. 👍