From 9301cd2ad53bbceeeb09a156728e2ca9c5d55da4 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Fri, 16 Feb 2018 16:44:03 -0800 Subject: [PATCH] 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. --- hcl/hclsyntax/parser_test.go | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/hcl/hclsyntax/parser_test.go b/hcl/hclsyntax/parser_test.go index 6d4698f..4bb21e8 100644 --- a/hcl/hclsyntax/parser_test.go +++ b/hcl/hclsyntax/parser_test.go @@ -1,12 +1,10 @@ package hclsyntax import ( - "reflect" "testing" - "github.com/davecgh/go-spew/spew" + "github.com/go-test/deep" "github.com/hashicorp/hcl2/hcl" - "github.com/kylelemons/godebug/pretty" "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 { t.Run(test.input, func(t *testing.T) { file, diags := ParseConfig([]byte(test.input), "", hcl.Pos{Byte: 0, Line: 1, Column: 1}) @@ -1463,12 +1455,9 @@ block "valid" {} got := file.Body - if !reflect.DeepEqual(got, test.want) { - diff := prettyConfig.Compare(test.want, got) - if diff != "" { - 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)) + if diff := deep.Equal(got, test.want); diff != nil { + for _, problem := range diff { + t.Errorf(problem) } } })