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: improve godoc and failure messages #229

Merged
merged 6 commits into from Apr 16, 2022

Conversation

dnephin
Copy link
Member

@dnephin dnephin commented Apr 15, 2022

Primarily this improve the godoc for the assert package in two ways:

  1. includes more examples of the failure messages, to give users a better idea of what they can expect from the assertions
  2. document that most assert functions use t.FailNow and therefore should only be called from the main test goroutine. Check should be used from all other goroutines.

Also makes some minor improvements to failures messages:

  1. slightly better message for assert.Assert when the argument is a ast.Ident boolean, or a binary expression (==, >, etc).
  2. remove the error type from assert.ErrorIs when the type is a stdlib type (*errors.errorString, or *fmt.wrapError, which come from errors.New, or fmt.Errorf). These types are not going to be relevant, so omitting them helps keep the failure message clear.

I'm going to try and preview the html rendered godoc before tagging a new release, to make sure it renders the way I expect.

Also adds a deprecation notice to env.Patch since t.SetEnv takes care of that now.

Note: this PR breaks compatiblity with Go1.12 by removing the go1.13 build tag that was guarding calls to errors.Is. gotest.tools/v3@v3.1.0 will be the last version that will work with Go 1.12.

Go 1.12 (the last version before errors.Is was added) has not been
supported in a while.

Move ErrorIs assertion and comparison into the main files.
Add examples to godoc that show the failure message.

Improve the failure message for assert.Assert when the argument is an
ast.Ident, or a binary expression.
Removes the stdlib error types from the failure message
(*errors.errorString, and fmt.wrapError). These types are not relevant because
they come from using fmt.Errorf or errors.New. The type of the error is only
relevant when the error is a user defined type.
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

1 participant