From 50fe8e79e50ba0eb0bba2ed82208a5e331408e4f Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 8 Nov 2023 21:59:29 -0800 Subject: [PATCH] Fix TestCloneProperties for go 1.21 Go 1.21 does a better job using the same empty allocation for empty structs, allow cloned properties to point to the original when it is an empty struct. Bug: 309895579 Test: TestCloneProperties Change-Id: I064f2316a8a8017a109968671ac305dbbe3246af --- proptools/clone_test.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/proptools/clone_test.go b/proptools/clone_test.go index 137882a..08f8455 100644 --- a/proptools/clone_test.go +++ b/proptools/clone_test.go @@ -296,6 +296,21 @@ type EmbeddedStruct struct { } type EmbeddedInterface interface{} +func isPointerToEmptyStruct(v any) bool { + t := reflect.TypeOf(v) + if t.Kind() != reflect.Ptr { + return false + } + t = t.Elem() + if t.Kind() != reflect.Struct { + return false + } + if t.NumField() > 0 { + return false + } + return true +} + func TestCloneProperties(t *testing.T) { for _, testCase := range clonePropertiesTestCases { testString := fmt.Sprintf("%s", testCase.in) @@ -308,7 +323,7 @@ func TestCloneProperties(t *testing.T) { t.Errorf(" expected: %#v", testCase.out) t.Errorf(" got: %#v", got) } - if testCase.out == got { + if testCase.out == got && !isPointerToEmptyStruct(testCase.out) { t.Errorf("test case %s", testString) t.Errorf("items should be cloned, not the original") t.Errorf(" expected: %s", testCase.out)