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

assert: print underlying objects when comparing pointers values #1118

Open
sjiekak opened this issue Oct 1, 2021 · 9 comments · May be fixed by #1287
Open

assert: print underlying objects when comparing pointers values #1118

sjiekak opened this issue Oct 1, 2021 · 9 comments · May be fixed by #1287
Labels
enhancement pkg-assert Change related to package testify/assert

Comments

@sjiekak
Copy link

sjiekak commented Oct 1, 2021

Example

package main

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

func TestPointerToValue(t *testing.T) {
	var a int = 1
	var b int = 2
	require.EqualValues(t, &a, &b, "The two numbers should be the same.")

}

The output is

=== RUN   TestPointerToValue
    prog.go:13: 
        	Error Trace:	prog.go:13
        	Error:      	Not equal: 
        	            	expected: (*int)(0xc0000189b8)
        	            	actual  : (*int)(0xc0000189c0)
        	Test:       	TestPointerToValue
        	Messages:   	The two numbers should be the same.
--- FAIL: TestPointerToValue (0.00s)

It would be incredible to have the actual values being compared printed as well. For instance
expected: (*int)(0xc0000189b8) could be expected: (*int)(0xc0000189b8) 1.

Currently, I am abusing this helper

func equalValuesPrettyPrint(t testing.TB, expected, actual interface{}) bool {
	return assert.EqualValues(t, expected, actual, "exp=%v, got=%v", reflect.Indirect(reflect.ValueOf(expected)), reflect.Indirect(reflect.ValueOf(actual)))
} 
@sjiekak sjiekak changed the title Print underlying objects when comparing pointers Print underlying objects when comparing pointers values Oct 1, 2021
@rajkumarGosavi
Copy link

Can I take this issue?

@slavaavr
Copy link

hi, any updates on this?

@jyturley
Copy link

Hi I can take this one on, if @rajkumarGosavi isn't working on this. @slavaavr
I assume we just want to show the values of the basic datatypes like int and bool and the like? And not structs? Or do we want everything?

@slavaavr
Copy link

@jyturley he there. Initially, I thought about printing pointer values for any type in the right way (without memory addresses). But then I checked library implementation and found out that they use fmt.Sptintf("%#v"), so it will be too hard to implement this feature from the scratch

@mchlp
Copy link
Contributor

mchlp commented Oct 21, 2022

Will be taking this since this issue has been idle for a while.

@mchlp mchlp linked a pull request Oct 21, 2022 that will close this issue
@tomasweigenast
Copy link

Any update?

@dolmen dolmen added pkg-assert Change related to package testify/assert enhancement labels Jul 12, 2023
@dolmen dolmen changed the title Print underlying objects when comparing pointers values assert: print underlying objects when comparing pointers values Jul 12, 2023
@NikitaPersefoni
Copy link

This is still relevant, would be thrilled to have this feature implemented. Is anybody able to pick it up?
@rajkumarGosavi @mchlp @slavaavr

@mchlp
Copy link
Contributor

mchlp commented Dec 13, 2023

The original PR that closes this issue seems to still be open and waiting for approve + merge: #1287

The changes are now out-of-date and need to be rebased on top of the most up to date changes on master. WIll take a look and see if I can the builds working again with those changes on top of master.

@mchlp
Copy link
Contributor

mchlp commented Dec 13, 2023

The PR is now rebased on top of master and checks are passing on my fork, but are failing on the PR. Additional discussion on the PR: #1287 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement pkg-assert Change related to package testify/assert
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants