-
Notifications
You must be signed in to change notification settings - Fork 2
feat: added optional support for colorized output #33
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds optional colorized output support to testify assertions with minimal dependencies. The feature is opt-in via a blank import and can be controlled through CLI flags or environment variables.
Changes:
- Refactored difflib package to support customizable output printers through an Options system
- Added colorization support for assertion failures (expected/actual values and diff output)
- Implemented theme support (dark/light) for different terminal backgrounds
Reviewed changes
Copilot reviewed 29 out of 30 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/difflib/options.go | New Options system for customizable diff output printers |
| internal/difflib/options_test.go | Tests for colorized diff output |
| internal/difflib/matcher.go | Extracted SequenceMatcher types and logic from difflib.go |
| internal/difflib/difflib.go | Refactored to use the new Options system |
| internal/difflib/difflib_test.go | Improved test organization |
| internal/difflib/difflib_benchmarks_test.go | Separated benchmarks into dedicated file |
| internal/assertions/diff.go | Moved diff logic with integrated color support |
| internal/assertions/equal.go | Updated to colorize expected/actual values |
| internal/assertions/helpers.go | Removed code moved to diff.go |
| internal/assertions/enable/colors/*.go | Internal colorization API and implementations |
| enable/colors/*.go | Public colorization module with CLI/env integration |
| assert/enable/colors/enable_colors.go | Public indirection API for colorization |
| docs/doc-site/examples/EXAMPLES.md | Added colorization documentation and examples |
| README.md | Updated to mention colorized output feature |
| go.work | Added enable/colors module to workspace |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| func typeAndKind(v any) (reflect.Type, reflect.Kind) { | ||
| t := reflect.TypeOf(v) | ||
| k := t.Kind() // Proposal for enhancement: check if t is not nil |
Copilot
AI
Jan 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment suggests checking if t is not nil, but this check is actually unnecessary in Go. reflect.TypeOf() will never return nil - if v is nil, reflect.TypeOf(v) returns a non-nil reflect.Type that represents the nil type. The Kind() method can safely be called on this value. This comment should be removed as it suggests an enhancement that isn't needed and might confuse readers.
| k := t.Kind() // Proposal for enhancement: check if t is not nil | |
| k := t.Kind() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reflect doc: TypeOf returns the reflection Type that represents the dynamic type of i. If i is a nil interface value, TypeOf returns nil.
88534f2 to
e5c1f93
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #33 +/- ##
==========================================
- Coverage 88.76% 87.63% -1.13%
==========================================
Files 63 71 +8
Lines 8436 8598 +162
==========================================
+ Hits 7488 7535 +47
- Misses 782 892 +110
- Partials 166 171 +5 ☔ View full report in Codecov by Sentry. |
e5c1f93 to
844ab46
Compare
This PR adds support for colorized output, with minimal extra dependencies. - Actual / Expected in equal colorized - Diff output is colorized It is enabled with the specific extra blank import: _ "github.com/go-openapi/testify/enable/colors/v2" When enabled, colorized output is: * enabled by go test flag -testify.colorized * or by environment variable TESTIFY_COLORIZED=true By default, colors are chose to be rendered on a dark terminal. You may use darker colors on a bright terminal with: * go test flag -testify.colorized -testify.theme=light * or by environment variable TESTIFY_THEME=light This work is inspired and adapts the following PRs: * github.com/stretchr#1467 * github.com/stretchr#1480 * github.com/stretchr#1232 * github.com/stretchr#994 Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
844ab46 to
bdf9d89
Compare
This PR adds support for colorized output, with minimal extra dependencies.
It is enabled with the specific extra blank import:
_ "github.com/go-openapi/testify/enable/colors/v2"
When enabled, colorized output is:
By default, colors are chose to be rendered on a dark terminal.
You may use darker colors on a bright terminal with:
This work is inspired and adapts the following PRs:
Change type
Please select: 🆕 New feature or enhancement|🔧 Bug fix'|📃 Documentation update
Short description
Fixes
Full description
Checklist