Skip to content

Conversation

@fredbi
Copy link
Member

@fredbi fredbi commented Jan 12, 2026

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.colorize
  • or by environment variable TESTIFY_COLORIZE=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.colorize -testify.theme=light
  • or by environment variable TESTIFY_THEME=light

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

  • I have signed all my commits with my name and email (see DCO. This does not require a PGP-signed commit
  • I have rebased and squashed my work, so only one commit remains
  • I have added tests to cover my changes.
  • I have properly enriched go doc comments in code.
  • I have properly documented any breaking change.

Copy link

Copilot AI left a 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
Copy link

Copilot AI Jan 12, 2026

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.

Suggested change
k := t.Kind() // Proposal for enhancement: check if t is not nil
k := t.Kind()

Copilot uses AI. Check for mistakes.
Copy link
Member Author

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.

@fredbi fredbi force-pushed the feat/colorized-output branch from 88534f2 to e5c1f93 Compare January 12, 2026 19:28
@codecov
Copy link

codecov bot commented Jan 12, 2026

Codecov Report

❌ Patch coverage is 60.09852% with 162 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.63%. Comparing base (374235c) to head (bdf9d89).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
internal/assertions/enable/colors/themes.go 0.00% 36 Missing ⚠️
internal/difflib/matcher.go 80.83% 21 Missing and 11 partials ⚠️
internal/assertions/enable/colors/options.go 0.00% 25 Missing ⚠️
internal/assertions/enable/colors/enable_colors.go 0.00% 23 Missing ⚠️
assert/enable/colors/enable_colors.go 0.00% 12 Missing ⚠️
internal/assertions/enable/colors/colors.go 33.33% 11 Missing and 1 partial ⚠️
internal/difflib/difflib.go 80.48% 0 Missing and 8 partials ⚠️
internal/difflib/options.go 81.81% 4 Missing and 2 partials ⚠️
internal/assertions/diff.go 87.17% 4 Missing and 1 partial ⚠️
internal/assertions/equal.go 75.00% 2 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

@fredbi fredbi force-pushed the feat/colorized-output branch from e5c1f93 to 844ab46 Compare January 12, 2026 19:39
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>
@fredbi fredbi force-pushed the feat/colorized-output branch from 844ab46 to bdf9d89 Compare January 12, 2026 21:08
@fredbi fredbi merged commit d432be4 into go-openapi:master Jan 12, 2026
21 checks passed
@fredbi fredbi deleted the feat/colorized-output branch January 12, 2026 21:14
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.

1 participant