-
Notifications
You must be signed in to change notification settings - Fork 1.7k
tests: improve captureTestingT helper #1741
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
base: master
Are you sure you want to change the base?
Conversation
Why not just log the error using |
I had no idea %q was escaping the \n or \t character |
I can change, but then if becomes a matter of style but I feel like this is more readable
than:
EDIT: I decided to live with it, it only happens when dealing with quote, and when an error message is updated. |
This helper is used to capture the testing.TB interface, and compare the log output with the expected output. This is useful for testing and refactoring purposes. This commit improves the helper by displaying: - the captured and expected outputs on a newline. - the special characters in the captured output, such as newlines and tabs. Both help with readability. Here is an example of the output before and after the change: Before: assertions_test.go:3422: Logged Error: Should be in error chain expected: *assert.customError in chain: "EOF" (*errors.errorString) assertions_test.go:3422: Should log Error: Should be in error chain: expected: *assert.customError in chain: "EOF" (*errors.errorString) After: assertions_test.go:3394: Recorded Error: "Should be in error chain:\nexpected: *assert.customError\nin chain: \"EOF\" (*errors.errorString)\n" assertions_test.go:3394: Expected Error: "Should be in error chain\nexpected: *assert.customError\nin chain: \"EOF\" (*errors.errorString)" The new format helps to identify the differences: - the missing colon after "Should be in error chain" - the extra newline in the captured output Note: I spent 10 minutes on this change, because I lost 10 minutes in finding the differences between the captured and expected output on a refactoring I was doing.
done |
I feel like I could use back tick with CanQuote as you did in a previous PR What do you think? |
Summary
A simple change to provide more explicit errors message when testing the code while refactoring asserters
Changes
This helper is used to capture the testing.TB interface, and compare
the log output with the expected output.
This is useful for testing and refactoring purposes.
This commit improves the helper by displaying:
Both help with readability.
Here is an example of the output before and after the change:
Before:
After:
My initial implementation:
The final implementation after applying @dolmen suggestion:
The new format helps to identify the differences:
Motivation
I spent 10 minutes on this change, because I lost 10 minutes in
finding the differences between the captured and expected output on a
refactoring I was doing.
Related issues
Replaces: #1735 opened with the wrong fork