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

Add FailureMessage.Err method and AssertionError type #141

Merged
merged 12 commits into from
Sep 10, 2024

Conversation

lycis
Copy link
Contributor

@lycis lycis commented Sep 6, 2024

Why

Sometimes you want to get an error from an assertion rather than directly fail a test run. Also test suites like Godog rely on returning an error instead of directly failing tests (e.g. because they encapsulate direct access to the test instance).

What

The FailureMessage type received a function AsError() that returns an instance of error or nil with the according failure message.

Checklist

  • CHANGELOG.md is updated.
  • README.md is updated.
  • The code changes follow Effective Go.
  • The code changes follow CodeReviewComments.
  • The code changes are covered by tests.

failmsg.go Outdated Show resolved Hide resolved
failmsg.go Outdated Show resolved Hide resolved
@lycis
Copy link
Contributor Author

lycis commented Sep 9, 2024

I like the suggest changes. I implemented them by:

  • Introducing the error-compatible type AssertionError
  • Refactoring AsError() to Err() to be more idiomatic.

CHANGELOG.md Outdated Show resolved Hide resolved
Copy link

codecov bot commented Sep 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (7b197d1) to head (c02f19d).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #141   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           15        16    +1     
  Lines          438       444    +6     
=========================================
+ Hits           438       444    +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pellared
Copy link
Member

pellared commented Sep 9, 2024

Thanks for your contribution. I plan to make a release today.

@pellared pellared changed the title Option to return an error from assertions instead of failing directly Add FailureMessage.Err method and AssertionError type Sep 10, 2024
@pellared pellared merged commit 83844e9 into fluentassert:main Sep 10, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants