Fix TestCloneProperties for go 1.21 am: 50fe8e79e5

Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/2824190

Change-Id: If679bf544928acff32a8684bcc58e60108632359
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Colin Cross 2023-11-09 18:57:43 +00:00 committed by Automerger Merge Worker
commit 21118230c9

View file

@ -296,6 +296,21 @@ type EmbeddedStruct struct {
} }
type EmbeddedInterface interface{} 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) { func TestCloneProperties(t *testing.T) {
for _, testCase := range clonePropertiesTestCases { for _, testCase := range clonePropertiesTestCases {
testString := fmt.Sprintf("%s", testCase.in) testString := fmt.Sprintf("%s", testCase.in)
@ -308,7 +323,7 @@ func TestCloneProperties(t *testing.T) {
t.Errorf(" expected: %#v", testCase.out) t.Errorf(" expected: %#v", testCase.out)
t.Errorf(" got: %#v", got) t.Errorf(" got: %#v", got)
} }
if testCase.out == got { if testCase.out == got && !isPointerToEmptyStruct(testCase.out) {
t.Errorf("test case %s", testString) t.Errorf("test case %s", testString)
t.Errorf("items should be cloned, not the original") t.Errorf("items should be cloned, not the original")
t.Errorf(" expected: %s", testCase.out) t.Errorf(" expected: %s", testCase.out)