Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assert: Add a self-describing Matcher #1507

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

pdhammond42
Copy link

Summary

Add a Matcher interface and associated assert.Matches function

Changes

Add interface, assertion functoin and an exmaple matcher implementation.

Motivation

This allows users to extend the assertions in possibly highly domain specific ways, without having to modify the assert package, and provide a suitably descriptive failure message to help pinpoint the problem.

Related issues

Pete Hammond added 3 commits November 10, 2023 16:01
This allows the assert pacakge to be externaly extended, without
losing the clear description in the case of a test failure.
@dolmen dolmen added enhancement wontfix pkg-assert Change related to package testify/assert pkg-require Change related to package testify/require labels Nov 19, 2023
Copy link
Collaborator

@dolmen dolmen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run the code generator. Check the Actions result.

@dolmen
Copy link
Collaborator

dolmen commented Nov 19, 2023

  • This extends the API surface
  • This can be built on top of Testify, in a separate package

At this point I don't want to extend the API surface.
So, closing.

@pdhammond42
Copy link
Author

Hi @dolmen , I don't see how this can be built on top of Testify. The point is to allow new tests to be built on top of Testify, using Testify's description of the failure. Of course I could do something similar using

stringStartingFoo:=matches.StringStarting("foo")
assert.True(t, stringStartingFoo.Test(x), stringStartingFoo.Describe(x))

but then I could also do

if c := matches.StringStarting("foo"); !c.Test(x) {
  t.Error(c.Describe(x)
}

But it's your code base, your decision. Thanks for looking

@dolmen
Copy link
Collaborator

dolmen commented Nov 22, 2023

"build on top of Testify" means "create your own module that uses the testify/assert API".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement pkg-assert Change related to package testify/assert pkg-require Change related to package testify/require wontfix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants