assert: improve godoc and failure messages#229
Merged
dnephin merged 6 commits intogotestyourself:mainfrom Apr 16, 2022
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Primarily this improve the godoc for the assert package in two ways:
t.FailNowand therefore should only be called from the main test goroutine.Checkshould be used from all other goroutines.Also makes some minor improvements to failures messages:
assert.Assertwhen the argument is aast.Identboolean, or a binary expression (==,>, etc).assert.ErrorIswhen the type is a stdlib type (*errors.errorString, or*fmt.wrapError, which come fromerrors.New, orfmt.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.Patchsincet.SetEnvtakes 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.0will be the last version that will work with Go 1.12.