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 Error() assertions on the final error value of multi-return value functions #480

Merged
merged 1 commit into from Nov 5, 2021

Conversation

thediveo
Copy link
Collaborator

@thediveo thediveo commented Nov 3, 2021

This PR follows up on #392, implementing a new Error method on Assertions.

  • adds Error method to Assertion, returning a new Assertion configured for error-related assertions (see below for details).
  • refactors Assertion to store both the actual value as well as all extras in a single slice for uniform handling.
  • refactors extra values vetting into generic slice of actual values vetting with optionally skipping a particular element, either the first element for normal assertions and the last element for error assertions.
  • an Error-returned Assertion is configured to vet differently from non-error-related assertions in order to correctly handle the Go error idiom, where either (A) all return values must be zero values in case of a trailing non-nil error, or (B) there are no constraints on the return values when the trailing error value is nil.
  • changes vet-related error messages to refer to "Unexpected non-nil/non-zero argument ..." instead of "Unexpected non-nil/non-zero extra argument".
  • adapts existing tests to the new vet-related error messages.
  • adds new test table covering Error.

@thediveo thediveo changed the title add Error() assertions on the final error value of multi-return values add Error() assertions on the final error value of multi-return value functions Nov 3, 2021
@onsi onsi merged commit 2f96943 into onsi:master Nov 5, 2021
@onsi
Copy link
Owner

onsi commented Nov 5, 2021

Looks great, thanks!

@thediveo thediveo deleted the thediveo-error-assertions branch November 5, 2021 15:08
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.

None yet

2 participants