hclsyntax: use go-test/deep for comparing parse test results

We were previously using an ugly combination of "pretty" and "spew" to
do this, which never really quite worked because of limitations in each
of those.

deep.Equal doesn't produce quite as much detailed information as the
others, but it has the advantage of showing exactly where a difference
exists rather than forcing us to hunt through a noisy diff to find it.
This commit is contained in:
Martin Atkins 2018-02-16 16:44:03 -08:00
parent 5ca9713bf0
commit 9301cd2ad5

View File

@ -1,12 +1,10 @@
package hclsyntax package hclsyntax
import ( import (
"reflect"
"testing" "testing"
"github.com/davecgh/go-spew/spew" "github.com/go-test/deep"
"github.com/hashicorp/hcl2/hcl" "github.com/hashicorp/hcl2/hcl"
"github.com/kylelemons/godebug/pretty"
"github.com/zclconf/go-cty/cty" "github.com/zclconf/go-cty/cty"
) )
@ -1445,12 +1443,6 @@ block "valid" {}
}, },
} }
prettyConfig := &pretty.Config{
Diffable: true,
IncludeUnexported: true,
PrintStringers: true,
}
for _, test := range tests { for _, test := range tests {
t.Run(test.input, func(t *testing.T) { t.Run(test.input, func(t *testing.T) {
file, diags := ParseConfig([]byte(test.input), "", hcl.Pos{Byte: 0, Line: 1, Column: 1}) file, diags := ParseConfig([]byte(test.input), "", hcl.Pos{Byte: 0, Line: 1, Column: 1})
@ -1463,12 +1455,9 @@ block "valid" {}
got := file.Body got := file.Body
if !reflect.DeepEqual(got, test.want) { if diff := deep.Equal(got, test.want); diff != nil {
diff := prettyConfig.Compare(test.want, got) for _, problem := range diff {
if diff != "" { t.Errorf(problem)
t.Errorf("wrong result\ninput: %s\ndiff: %s", test.input, diff)
} else {
t.Errorf("wrong result\ninput: %s\ngot: %s\nwant: %s", test.input, spew.Sdump(got), spew.Sdump(test.want))
} }
} }
}) })