assert: print underlying objects when comparing pointers values
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)))
}
Can I take this issue?
hi, any updates on this?
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?
@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
Will be taking this since this issue has been idle for a while.
Any update?
This is still relevant, would be thrilled to have this feature implemented. Is anybody able to pick it up? @rajkumarGosavi @mchlp @slavaavr
The original PR that closes this issue seems to still be open and waiting for approve + merge: https://github.com/stretchr/testify/pull/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.
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: https://github.com/stretchr/testify/pull/1287#issuecomment-1854687817