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

diff output with multiple differences is unhelpful #64

Closed
rogpeppe opened this issue Jan 3, 2018 · 1 comment
Closed

diff output with multiple differences is unhelpful #64

rogpeppe opened this issue Jan 3, 2018 · 1 comment

Comments

@rogpeppe
Copy link
Contributor

rogpeppe commented Jan 3, 2018

I ran across this recently when using cmp to test differences in unmarshal results.
One unmarshaler was unmarshaling numbers as floats, the other as ints, but the
Diff result didn't make it at all clear what the difference was.

Example code:

package main

import (
	"fmt"

	"github.com/google/go-cmp/cmp"
)

func main() {
	x := []interface{}{map[string]interface{}{"avg": 0.278, "hr": 65, "name": "Mark McGwire"}, map[string]interface{}{"avg": 0.288, "hr": 63, "name": "Sammy Sosa"}}
	y := []interface{}{map[string]interface{}{"avg": 0.278, "hr": 65.0, "name": "Mark McGwire"}, map[string]interface{}{"avg": 0.288, "hr": 63.0, "name": "Sammy Sosa"}}

	diff := cmp.Diff(x, y)
	fmt.Printf("diff: %s\n", diff)
}

This prints:

diff: root:
	-: []interface {}{map[string]interface {}{"avg": 0.278, "hr": 65, "name": "Mark McGwire"}, map[string]interface {}{"avg": 0.288, "hr": 63, "name": "Sammy Sosa"}}
	+: []interface {}{map[string]interface {}{"avg": 0.278, "hr": 65, "name": "Mark McGwire"}, map[string]interface {}{"avg": 0.288, "hr": 63, "name": "Sammy Sosa"}}

Note that both lines are identical.

@dsnet
Copy link
Collaborator

dsnet commented Jan 3, 2018

The tip version of cmp does avoid shoving this all on one line, but still suffers from not printing the type:

root[0]["hr"]:
	-: 65
	+: 65
root[1]["hr"]:
	-: 63
	+: 63

dsnet added a commit that referenced this issue Jan 3, 2018
When the formatted strings are identical, the reporter tries to fallback
on more exact formatting. This fallback should include the types for
primitive types since the difference can simply be between
an int and an uint.

Fixes #64
@dsnet dsnet closed this as completed in #65 Jan 3, 2018
dsnet added a commit that referenced this issue Jan 3, 2018
When the formatted strings are identical, the reporter tries to fallback
on more exact formatting. This fallback should include the types for
primitive types since the difference can simply be between
an int and an uint.

Fixes #64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants