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

#946 Colorize 'Expected' and 'Actual' in Assert Package + Minor Fixes: #1112, #1086 & #1231 #1232

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vaguecoder
Copy link

@vaguecoder vaguecoder commented Jul 17, 2022

Summary

Colorizes error, expected, actual, test name and message of the assert failure cases for better visualization.

Changes

  1. Colorizing changes in assert package as per Colorize "expected" and "actual" #946
  2. Minor fix of format specifiers as per Fix interpolation using %s instead of %#v for interfaces #1112 due to conflict with colorizing changes.
  3. Minor fix of format specifiers as per Use %v when formatting objects in assert.Len #1086 due to conflict with colorizing changes.
  4. Minor fix of order of arguments for func InEpsilon call as per Misplaced "expected" and "actual" Arguments Inside InEpsilonSlice #1231. This was an observation and I opened this issue earlier today.

Motivation

Colorizing the output for failure cases makes it easier to visualize. This was first suggested on card #946.

Related Issues

Closes #946
Closes #1231

Additional Notes for Reviewers & Maintainers

  1. Please find play link with defined failure cases for 62 functions that can be ran in local with the code associated with this PR, for review.
  2. difflib is unmaintained since few years now. The required code with changes are not added in assert, in diff.go. Check if there's a better solution.

@LandonTClipp
Copy link
Contributor

This has the problem of inserting color coding into the output even if stdout is not a terminal, or some kind of printer capable of understanding color sequences. Most CI/CD pipelines run outside of a terminal, so this would make the output difficult to read.

@thedaneeffect
Copy link

thedaneeffect commented May 12, 2023

This has the problem of inserting color coding into the output even if stdout is not a terminal, or some kind of printer capable of understanding color sequences. Most CI/CD pipelines run outside of a terminal, so this would make the output difficult to read.

Perhaps a similar approach to log.SetFlags could be done to take this into account.

package main

import (
    "testing"
    
    "github.com/stretchr/testify/require"
)

func init() {
    require.SetFlags(require.Fcolorize)
}

func TestMyFunc(t *testing.T) {
    require.Equal(t, "Foo", "Bar")
}

@dolmen dolmen added enhancement pkg-assert Change related to package testify/assert enhancement: colored output About adding colored output labels Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement: colored output About adding colored output enhancement pkg-assert Change related to package testify/assert
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Colorize "expected" and "actual" Misplaced "expected" and "actual" Arguments Inside InEpsilonSlice
4 participants