From 2ab437bb1e9f9f34d2e080ad11c944464a8bd944 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sun, 22 Mar 2020 14:23:35 +0100 Subject: prog: improve TestDeserializeHelper 1. Allow to not provide Out if it's the same as In. 2. Always check Out. --- prog/test_util.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'prog/test_util.go') diff --git a/prog/test_util.go b/prog/test_util.go index bb96a64e8..7f391792c 100644 --- a/prog/test_util.go +++ b/prog/test_util.go @@ -20,9 +20,9 @@ func InitTargetTest(t *testing.T, os, arch string) *Target { type DeserializeTest struct { In string - Out string + Out string // if not set, equals to In Err string - StrictErr string + StrictErr string // if not set, equals to Err } func TestDeserializeHelper(t *testing.T, OS, arch string, transform func(*Target, *Prog), tests []DeserializeTest) { @@ -36,6 +36,12 @@ func TestDeserializeHelper(t *testing.T, OS, arch string, transform func(*Target if test.Err != "" && test.Out != "" { t.Fatalf("both Err and Out are set") } + if test.In == test.Out { + t.Fatalf("In and Out are equal, remove Out in such case\n%v", test.In) + } + if test.Out == "" { + test.Out = test.In + } for _, mode := range []DeserializeMode{NonStrict, Strict} { p, err := target.Deserialize([]byte(test.In), mode) wantErr := test.Err @@ -61,7 +67,7 @@ func TestDeserializeHelper(t *testing.T, OS, arch string, transform func(*Target } output := strings.TrimSpace(string(p.Serialize())) want := strings.TrimSpace(test.Out) - if want != "" && want != output { + if want != output { t.Fatalf("wrong serialized data:\n%s\nexpect:\n%s\n", output, want) } p.SerializeForExec(buf) -- cgit mrf-deployment