From 79c404050509100a233091e97125778fed09acce Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Thu, 29 Jun 2017 21:14:18 -0700 Subject: [PATCH] sync up some straggler json_tests --- .../omitempty/ptr_bool/json_test.go | 27 ++++++++++++++----- .../omitempty/ptr_float32/json_test.go | 27 ++++++++++++++----- .../omitempty/ptr_int32/json_test.go | 27 ++++++++++++++----- .../ptr_map_string_string/json_test.go | 27 ++++++++++++++----- .../omitempty/ptr_slice_string/json_test.go | 27 ++++++++++++++----- .../omitempty/ptr_string/string/json_test.go | 27 ++++++++++++++----- .../omitempty/ptr_uint32/json_test.go | 27 ++++++++++++++----- 7 files changed, 140 insertions(+), 49 deletions(-) diff --git a/output_tests/struct_tags/omitempty/ptr_bool/json_test.go b/output_tests/struct_tags/omitempty/ptr_bool/json_test.go index a7b1d0d..8c7d795 100644 --- a/output_tests/struct_tags/omitempty/ptr_bool/json_test.go +++ b/output_tests/struct_tags/omitempty/ptr_bool/json_test.go @@ -3,6 +3,8 @@ package test import ( "bytes" "encoding/json" + "fmt" + "strings" "testing" "github.com/davecgh/go-spew/spew" @@ -18,29 +20,37 @@ func Test_Roundtrip(t *testing.T) { jbStd, err := json.Marshal(before) if err != nil { - t.Errorf("failed to marshal with stdlib: %v", err) + t.Fatalf("failed to marshal with stdlib: %v", err) + } + if len(strings.TrimSpace(string(jbStd))) == 0 { + t.Fatal("stdlib marshal produced empty result and no error") } jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) if err != nil { - t.Errorf("failed to marshal with jsoniter: %v", err) + t.Fatalf("failed to marshal with jsoniter: %v", err) + } + if len(strings.TrimSpace(string(jbIter))) == 0 { + t.Fatal("jsoniter marshal produced empty result and no error") } if string(jbStd) != string(jbIter) { - t.Errorf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", + t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", indent(jbStd, " "), indent(jbIter, " "), dump(before)) } var afterStd T err = json.Unmarshal(jbIter, &afterStd) if err != nil { - t.Errorf("failed to unmarshal with stdlib: %v", err) + t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", + err, indent(jbIter, " ")) } var afterIter T err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) if err != nil { - t.Errorf("failed to unmarshal with jsoniter: %v", err) + t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", + err, indent(jbIter, " ")) } if fingerprint(afterStd) != fingerprint(afterIter) { - t.Errorf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", + t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", dump(afterStd), dump(afterIter), indent(jbIter, " ")) } } @@ -65,7 +75,10 @@ func dump(obj interface{}) string { func indent(src []byte, prefix string) string { var buf bytes.Buffer - json.Indent(&buf, src, prefix, indentStr) + err := json.Indent(&buf, src, prefix, indentStr) + if err != nil { + return fmt.Sprintf("!!! %v", err) + } return buf.String() } diff --git a/output_tests/struct_tags/omitempty/ptr_float32/json_test.go b/output_tests/struct_tags/omitempty/ptr_float32/json_test.go index a7b1d0d..8c7d795 100644 --- a/output_tests/struct_tags/omitempty/ptr_float32/json_test.go +++ b/output_tests/struct_tags/omitempty/ptr_float32/json_test.go @@ -3,6 +3,8 @@ package test import ( "bytes" "encoding/json" + "fmt" + "strings" "testing" "github.com/davecgh/go-spew/spew" @@ -18,29 +20,37 @@ func Test_Roundtrip(t *testing.T) { jbStd, err := json.Marshal(before) if err != nil { - t.Errorf("failed to marshal with stdlib: %v", err) + t.Fatalf("failed to marshal with stdlib: %v", err) + } + if len(strings.TrimSpace(string(jbStd))) == 0 { + t.Fatal("stdlib marshal produced empty result and no error") } jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) if err != nil { - t.Errorf("failed to marshal with jsoniter: %v", err) + t.Fatalf("failed to marshal with jsoniter: %v", err) + } + if len(strings.TrimSpace(string(jbIter))) == 0 { + t.Fatal("jsoniter marshal produced empty result and no error") } if string(jbStd) != string(jbIter) { - t.Errorf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", + t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", indent(jbStd, " "), indent(jbIter, " "), dump(before)) } var afterStd T err = json.Unmarshal(jbIter, &afterStd) if err != nil { - t.Errorf("failed to unmarshal with stdlib: %v", err) + t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", + err, indent(jbIter, " ")) } var afterIter T err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) if err != nil { - t.Errorf("failed to unmarshal with jsoniter: %v", err) + t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", + err, indent(jbIter, " ")) } if fingerprint(afterStd) != fingerprint(afterIter) { - t.Errorf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", + t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", dump(afterStd), dump(afterIter), indent(jbIter, " ")) } } @@ -65,7 +75,10 @@ func dump(obj interface{}) string { func indent(src []byte, prefix string) string { var buf bytes.Buffer - json.Indent(&buf, src, prefix, indentStr) + err := json.Indent(&buf, src, prefix, indentStr) + if err != nil { + return fmt.Sprintf("!!! %v", err) + } return buf.String() } diff --git a/output_tests/struct_tags/omitempty/ptr_int32/json_test.go b/output_tests/struct_tags/omitempty/ptr_int32/json_test.go index a7b1d0d..8c7d795 100644 --- a/output_tests/struct_tags/omitempty/ptr_int32/json_test.go +++ b/output_tests/struct_tags/omitempty/ptr_int32/json_test.go @@ -3,6 +3,8 @@ package test import ( "bytes" "encoding/json" + "fmt" + "strings" "testing" "github.com/davecgh/go-spew/spew" @@ -18,29 +20,37 @@ func Test_Roundtrip(t *testing.T) { jbStd, err := json.Marshal(before) if err != nil { - t.Errorf("failed to marshal with stdlib: %v", err) + t.Fatalf("failed to marshal with stdlib: %v", err) + } + if len(strings.TrimSpace(string(jbStd))) == 0 { + t.Fatal("stdlib marshal produced empty result and no error") } jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) if err != nil { - t.Errorf("failed to marshal with jsoniter: %v", err) + t.Fatalf("failed to marshal with jsoniter: %v", err) + } + if len(strings.TrimSpace(string(jbIter))) == 0 { + t.Fatal("jsoniter marshal produced empty result and no error") } if string(jbStd) != string(jbIter) { - t.Errorf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", + t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", indent(jbStd, " "), indent(jbIter, " "), dump(before)) } var afterStd T err = json.Unmarshal(jbIter, &afterStd) if err != nil { - t.Errorf("failed to unmarshal with stdlib: %v", err) + t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", + err, indent(jbIter, " ")) } var afterIter T err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) if err != nil { - t.Errorf("failed to unmarshal with jsoniter: %v", err) + t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", + err, indent(jbIter, " ")) } if fingerprint(afterStd) != fingerprint(afterIter) { - t.Errorf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", + t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", dump(afterStd), dump(afterIter), indent(jbIter, " ")) } } @@ -65,7 +75,10 @@ func dump(obj interface{}) string { func indent(src []byte, prefix string) string { var buf bytes.Buffer - json.Indent(&buf, src, prefix, indentStr) + err := json.Indent(&buf, src, prefix, indentStr) + if err != nil { + return fmt.Sprintf("!!! %v", err) + } return buf.String() } diff --git a/output_tests/struct_tags/omitempty/ptr_map_string_string/json_test.go b/output_tests/struct_tags/omitempty/ptr_map_string_string/json_test.go index a7b1d0d..8c7d795 100644 --- a/output_tests/struct_tags/omitempty/ptr_map_string_string/json_test.go +++ b/output_tests/struct_tags/omitempty/ptr_map_string_string/json_test.go @@ -3,6 +3,8 @@ package test import ( "bytes" "encoding/json" + "fmt" + "strings" "testing" "github.com/davecgh/go-spew/spew" @@ -18,29 +20,37 @@ func Test_Roundtrip(t *testing.T) { jbStd, err := json.Marshal(before) if err != nil { - t.Errorf("failed to marshal with stdlib: %v", err) + t.Fatalf("failed to marshal with stdlib: %v", err) + } + if len(strings.TrimSpace(string(jbStd))) == 0 { + t.Fatal("stdlib marshal produced empty result and no error") } jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) if err != nil { - t.Errorf("failed to marshal with jsoniter: %v", err) + t.Fatalf("failed to marshal with jsoniter: %v", err) + } + if len(strings.TrimSpace(string(jbIter))) == 0 { + t.Fatal("jsoniter marshal produced empty result and no error") } if string(jbStd) != string(jbIter) { - t.Errorf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", + t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", indent(jbStd, " "), indent(jbIter, " "), dump(before)) } var afterStd T err = json.Unmarshal(jbIter, &afterStd) if err != nil { - t.Errorf("failed to unmarshal with stdlib: %v", err) + t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", + err, indent(jbIter, " ")) } var afterIter T err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) if err != nil { - t.Errorf("failed to unmarshal with jsoniter: %v", err) + t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", + err, indent(jbIter, " ")) } if fingerprint(afterStd) != fingerprint(afterIter) { - t.Errorf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", + t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", dump(afterStd), dump(afterIter), indent(jbIter, " ")) } } @@ -65,7 +75,10 @@ func dump(obj interface{}) string { func indent(src []byte, prefix string) string { var buf bytes.Buffer - json.Indent(&buf, src, prefix, indentStr) + err := json.Indent(&buf, src, prefix, indentStr) + if err != nil { + return fmt.Sprintf("!!! %v", err) + } return buf.String() } diff --git a/output_tests/struct_tags/omitempty/ptr_slice_string/json_test.go b/output_tests/struct_tags/omitempty/ptr_slice_string/json_test.go index a7b1d0d..8c7d795 100644 --- a/output_tests/struct_tags/omitempty/ptr_slice_string/json_test.go +++ b/output_tests/struct_tags/omitempty/ptr_slice_string/json_test.go @@ -3,6 +3,8 @@ package test import ( "bytes" "encoding/json" + "fmt" + "strings" "testing" "github.com/davecgh/go-spew/spew" @@ -18,29 +20,37 @@ func Test_Roundtrip(t *testing.T) { jbStd, err := json.Marshal(before) if err != nil { - t.Errorf("failed to marshal with stdlib: %v", err) + t.Fatalf("failed to marshal with stdlib: %v", err) + } + if len(strings.TrimSpace(string(jbStd))) == 0 { + t.Fatal("stdlib marshal produced empty result and no error") } jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) if err != nil { - t.Errorf("failed to marshal with jsoniter: %v", err) + t.Fatalf("failed to marshal with jsoniter: %v", err) + } + if len(strings.TrimSpace(string(jbIter))) == 0 { + t.Fatal("jsoniter marshal produced empty result and no error") } if string(jbStd) != string(jbIter) { - t.Errorf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", + t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", indent(jbStd, " "), indent(jbIter, " "), dump(before)) } var afterStd T err = json.Unmarshal(jbIter, &afterStd) if err != nil { - t.Errorf("failed to unmarshal with stdlib: %v", err) + t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", + err, indent(jbIter, " ")) } var afterIter T err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) if err != nil { - t.Errorf("failed to unmarshal with jsoniter: %v", err) + t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", + err, indent(jbIter, " ")) } if fingerprint(afterStd) != fingerprint(afterIter) { - t.Errorf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", + t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", dump(afterStd), dump(afterIter), indent(jbIter, " ")) } } @@ -65,7 +75,10 @@ func dump(obj interface{}) string { func indent(src []byte, prefix string) string { var buf bytes.Buffer - json.Indent(&buf, src, prefix, indentStr) + err := json.Indent(&buf, src, prefix, indentStr) + if err != nil { + return fmt.Sprintf("!!! %v", err) + } return buf.String() } diff --git a/output_tests/struct_tags/omitempty/ptr_string/string/json_test.go b/output_tests/struct_tags/omitempty/ptr_string/string/json_test.go index a7b1d0d..8c7d795 100644 --- a/output_tests/struct_tags/omitempty/ptr_string/string/json_test.go +++ b/output_tests/struct_tags/omitempty/ptr_string/string/json_test.go @@ -3,6 +3,8 @@ package test import ( "bytes" "encoding/json" + "fmt" + "strings" "testing" "github.com/davecgh/go-spew/spew" @@ -18,29 +20,37 @@ func Test_Roundtrip(t *testing.T) { jbStd, err := json.Marshal(before) if err != nil { - t.Errorf("failed to marshal with stdlib: %v", err) + t.Fatalf("failed to marshal with stdlib: %v", err) + } + if len(strings.TrimSpace(string(jbStd))) == 0 { + t.Fatal("stdlib marshal produced empty result and no error") } jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) if err != nil { - t.Errorf("failed to marshal with jsoniter: %v", err) + t.Fatalf("failed to marshal with jsoniter: %v", err) + } + if len(strings.TrimSpace(string(jbIter))) == 0 { + t.Fatal("jsoniter marshal produced empty result and no error") } if string(jbStd) != string(jbIter) { - t.Errorf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", + t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", indent(jbStd, " "), indent(jbIter, " "), dump(before)) } var afterStd T err = json.Unmarshal(jbIter, &afterStd) if err != nil { - t.Errorf("failed to unmarshal with stdlib: %v", err) + t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", + err, indent(jbIter, " ")) } var afterIter T err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) if err != nil { - t.Errorf("failed to unmarshal with jsoniter: %v", err) + t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", + err, indent(jbIter, " ")) } if fingerprint(afterStd) != fingerprint(afterIter) { - t.Errorf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", + t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", dump(afterStd), dump(afterIter), indent(jbIter, " ")) } } @@ -65,7 +75,10 @@ func dump(obj interface{}) string { func indent(src []byte, prefix string) string { var buf bytes.Buffer - json.Indent(&buf, src, prefix, indentStr) + err := json.Indent(&buf, src, prefix, indentStr) + if err != nil { + return fmt.Sprintf("!!! %v", err) + } return buf.String() } diff --git a/output_tests/struct_tags/omitempty/ptr_uint32/json_test.go b/output_tests/struct_tags/omitempty/ptr_uint32/json_test.go index a7b1d0d..8c7d795 100644 --- a/output_tests/struct_tags/omitempty/ptr_uint32/json_test.go +++ b/output_tests/struct_tags/omitempty/ptr_uint32/json_test.go @@ -3,6 +3,8 @@ package test import ( "bytes" "encoding/json" + "fmt" + "strings" "testing" "github.com/davecgh/go-spew/spew" @@ -18,29 +20,37 @@ func Test_Roundtrip(t *testing.T) { jbStd, err := json.Marshal(before) if err != nil { - t.Errorf("failed to marshal with stdlib: %v", err) + t.Fatalf("failed to marshal with stdlib: %v", err) + } + if len(strings.TrimSpace(string(jbStd))) == 0 { + t.Fatal("stdlib marshal produced empty result and no error") } jbIter, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(before) if err != nil { - t.Errorf("failed to marshal with jsoniter: %v", err) + t.Fatalf("failed to marshal with jsoniter: %v", err) + } + if len(strings.TrimSpace(string(jbIter))) == 0 { + t.Fatal("jsoniter marshal produced empty result and no error") } if string(jbStd) != string(jbIter) { - t.Errorf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", + t.Fatalf("marshal expected:\n %s\ngot:\n %s\nobj:\n %s", indent(jbStd, " "), indent(jbIter, " "), dump(before)) } var afterStd T err = json.Unmarshal(jbIter, &afterStd) if err != nil { - t.Errorf("failed to unmarshal with stdlib: %v", err) + t.Fatalf("failed to unmarshal with stdlib: %v\nvia:\n %s", + err, indent(jbIter, " ")) } var afterIter T err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(jbIter, &afterIter) if err != nil { - t.Errorf("failed to unmarshal with jsoniter: %v", err) + t.Fatalf("failed to unmarshal with jsoniter: %v\nvia:\n %s", + err, indent(jbIter, " ")) } if fingerprint(afterStd) != fingerprint(afterIter) { - t.Errorf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", + t.Fatalf("unmarshal expected:\n %s\ngot:\n %s\nvia:\n %s", dump(afterStd), dump(afterIter), indent(jbIter, " ")) } } @@ -65,7 +75,10 @@ func dump(obj interface{}) string { func indent(src []byte, prefix string) string { var buf bytes.Buffer - json.Indent(&buf, src, prefix, indentStr) + err := json.Indent(&buf, src, prefix, indentStr) + if err != nil { + return fmt.Sprintf("!!! %v", err) + } return buf.String() }