aboutsummaryrefslogtreecommitdiffstats
path: root/prog/test_util.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-03-22 14:23:35 +0100
committerDmitry Vyukov <dvyukov@google.com>2020-03-24 08:43:00 +0100
commit2ab437bb1e9f9f34d2e080ad11c944464a8bd944 (patch)
tree568bcf0cdf14d2df812018ab48277eaff0f21632 /prog/test_util.go
parentef871b2e4ff7b6a8f84a6a0a0fd3e9c3ed8e67b4 (diff)
prog: improve TestDeserializeHelper
1. Allow to not provide Out if it's the same as In. 2. Always check Out.
Diffstat (limited to 'prog/test_util.go')
-rw-r--r--prog/test_util.go12
1 files changed, 9 insertions, 3 deletions
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)