From 36474d322bcbc463b94c546315b5db00591d0236 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Fri, 12 Mar 2021 12:19:43 +0000 Subject: [PATCH] Stop sdk package depending on testing.T being embedded in TestResult This change is in preparation for removing testing.T from TestResult. Bug: 181070625 Test: m nothing Change-Id: I67535aff0d894e6e3d8456b75540f340af853355 --- sdk/boot_image_sdk_test.go | 5 ++-- sdk/bp_test.go | 54 ++++++++++++++++---------------------- sdk/cc_sdk_test.go | 53 ++++++++++++++++++------------------- sdk/exports_test.go | 2 +- sdk/java_sdk_test.go | 40 ++++++++++++++-------------- sdk/sdk_test.go | 21 ++++++--------- sdk/testing.go | 44 +++++++++++++++++-------------- 7 files changed, 103 insertions(+), 116 deletions(-) diff --git a/sdk/boot_image_sdk_test.go b/sdk/boot_image_sdk_test.go index 915253d19..9805a6a90 100644 --- a/sdk/boot_image_sdk_test.go +++ b/sdk/boot_image_sdk_test.go @@ -29,7 +29,7 @@ func TestSnapshotWithBootImage(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -58,6 +58,5 @@ sdk_snapshot { boot_images: ["mysdk_mybootimage@current"], } `), - checkAllCopyRules(""), - ) + checkAllCopyRules("")) } diff --git a/sdk/bp_test.go b/sdk/bp_test.go index a7164a5e9..2bd8a4307 100644 --- a/sdk/bp_test.go +++ b/sdk/bp_test.go @@ -54,26 +54,25 @@ func propertyStructFixture() interface{} { return str } -func checkPropertySetFixture(h android.TestHelper, val interface{}, hasTags bool) { +func checkPropertySetFixture(t *testing.T, val interface{}, hasTags bool) { set := val.(*bpPropertySet) - h.AssertDeepEquals("wrong x value", "taxi", set.getValue("x")) - h.AssertDeepEquals("wrong y value", 1729, set.getValue("y")) + android.AssertDeepEquals(t, "wrong x value", "taxi", set.getValue("x")) + android.AssertDeepEquals(t, "wrong y value", 1729, set.getValue("y")) subset := set.getValue("sub").(*bpPropertySet) - h.AssertDeepEquals("wrong sub.x value", "taxi", subset.getValue("x")) - h.AssertDeepEquals("wrong sub.y value", 1729, subset.getValue("y")) + android.AssertDeepEquals(t, "wrong sub.x value", "taxi", subset.getValue("x")) + android.AssertDeepEquals(t, "wrong sub.y value", 1729, subset.getValue("y")) if hasTags { - h.AssertDeepEquals("wrong y tag", "tag_y", set.getTag("y")) - h.AssertDeepEquals("wrong sub.x tag", "tag_x", subset.getTag("x")) + android.AssertDeepEquals(t, "wrong y tag", "tag_y", set.getTag("y")) + android.AssertDeepEquals(t, "wrong sub.x tag", "tag_x", subset.getTag("x")) } else { - h.AssertDeepEquals("wrong y tag", nil, set.getTag("y")) - h.AssertDeepEquals("wrong sub.x tag", nil, subset.getTag("x")) + android.AssertDeepEquals(t, "wrong y tag", nil, set.getTag("y")) + android.AssertDeepEquals(t, "wrong sub.x tag", nil, subset.getTag("x")) } } func TestAddPropertySimple(t *testing.T) { - h := android.TestHelper{t} set := newPropertySet() for name, val := range map[string]interface{}{ "x": "taxi", @@ -83,16 +82,15 @@ func TestAddPropertySimple(t *testing.T) { "arr": []string{"a", "b", "c"}, } { set.AddProperty(name, val) - h.AssertDeepEquals("wrong value", val, set.getValue(name)) + android.AssertDeepEquals(t, "wrong value", val, set.getValue(name)) } - h.AssertPanic("adding x again should panic", + android.AssertPanic(t, "adding x again should panic", func() { set.AddProperty("x", "taxi") }) - h.AssertPanic("adding arr again should panic", + android.AssertPanic(t, "adding arr again should panic", func() { set.AddProperty("arr", []string{"d"}) }) } func TestAddPropertySubset(t *testing.T) { - h := android.TestHelper{t} getFixtureMap := map[string]func() interface{}{ "property set": propertySetFixture, "property struct": propertyStructFixture, @@ -103,8 +101,8 @@ func TestAddPropertySubset(t *testing.T) { t.Run(name, func(t *testing.T) { set := propertySetFixture().(*bpPropertySet) set.AddProperty("new", getFixture()) - checkPropertySetFixture(h, set, true) - checkPropertySetFixture(h, set.getValue("new"), name == "property set") + checkPropertySetFixture(t, set, true) + checkPropertySetFixture(t, set.getValue("new"), name == "property set") }) } }) @@ -118,40 +116,38 @@ func TestAddPropertySubset(t *testing.T) { subset.AddPropertySet("sub") set.AddProperty("sub", getFixture()) merged := set.getValue("sub").(*bpPropertySet) - h.AssertDeepEquals("wrong flag value", false, merged.getValue("flag")) - checkPropertySetFixture(h, merged, name == "property set") + android.AssertDeepEquals(t, "wrong flag value", false, merged.getValue("flag")) + checkPropertySetFixture(t, merged, name == "property set") }) } }) t.Run("add conflicting subset", func(t *testing.T) { set := propertySetFixture().(*bpPropertySet) - h.AssertPanic("adding x again should panic", + android.AssertPanic(t, "adding x again should panic", func() { set.AddProperty("x", propertySetFixture()) }) }) t.Run("add non-pointer struct", func(t *testing.T) { set := propertySetFixture().(*bpPropertySet) str := propertyStructFixture().(*propertyStruct) - h.AssertPanic("adding a non-pointer struct should panic", + android.AssertPanic(t, "adding a non-pointer struct should panic", func() { set.AddProperty("new", *str) }) }) } func TestAddPropertySetNew(t *testing.T) { - h := android.TestHelper{t} set := newPropertySet() subset := set.AddPropertySet("sub") subset.AddProperty("new", "d^^b") - h.AssertDeepEquals("wrong sub.new value", "d^^b", set.getValue("sub").(*bpPropertySet).getValue("new")) + android.AssertDeepEquals(t, "wrong sub.new value", "d^^b", set.getValue("sub").(*bpPropertySet).getValue("new")) } func TestAddPropertySetExisting(t *testing.T) { - h := android.TestHelper{t} set := propertySetFixture().(*bpPropertySet) subset := set.AddPropertySet("sub") subset.AddProperty("new", "d^^b") - h.AssertDeepEquals("wrong sub.new value", "d^^b", set.getValue("sub").(*bpPropertySet).getValue("new")) + android.AssertDeepEquals(t, "wrong sub.new value", "d^^b", set.getValue("sub").(*bpPropertySet).getValue("new")) } type removeFredTransformation struct { @@ -180,9 +176,6 @@ func (t removeFredTransformation) transformPropertySetAfterContents(name string, } func TestTransformRemoveProperty(t *testing.T) { - - helper := android.TestHelper{t} - set := newPropertySet() set.AddProperty("name", "name") set.AddProperty("fred", "12") @@ -191,13 +184,10 @@ func TestTransformRemoveProperty(t *testing.T) { contents := &generatedContents{} outputPropertySet(contents, set) - helper.AssertTrimmedStringEquals("removing property failed", "name: \"name\",\n", contents.content.String()) + android.AssertTrimmedStringEquals(t, "removing property failed", "name: \"name\",\n", contents.content.String()) } func TestTransformRemovePropertySet(t *testing.T) { - - helper := android.TestHelper{t} - set := newPropertySet() set.AddProperty("name", "name") set.AddPropertySet("fred") @@ -206,5 +196,5 @@ func TestTransformRemovePropertySet(t *testing.T) { contents := &generatedContents{} outputPropertySet(contents, set) - helper.AssertTrimmedStringEquals("removing property set failed", "name: \"name\",\n", contents.content.String()) + android.AssertTrimmedStringEquals(t, "removing property set failed", "name: \"name\",\n", contents.content.String()) } diff --git a/sdk/cc_sdk_test.go b/sdk/cc_sdk_test.go index 28c9e9e28..a2539c9a0 100644 --- a/sdk/cc_sdk_test.go +++ b/sdk/cc_sdk_test.go @@ -101,7 +101,7 @@ func TestSdkCompileMultilibOverride(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -353,7 +353,7 @@ func TestSnapshotWithObject(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -440,7 +440,7 @@ func TestSnapshotWithCcDuplicateHeaders(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkAllCopyRules(` myinclude/Test.h -> include/myinclude/Test.h .intermediates/mynativelib1/android_arm64_armv8-a_shared/mynativelib1.so -> arm64/lib/mynativelib1.so @@ -486,7 +486,7 @@ func TestSnapshotWithCcExportGeneratedHeaders(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -556,7 +556,7 @@ func TestSnapshotWithCcSharedLibraryCommonProperties(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -615,7 +615,7 @@ func TestSnapshotWithCcBinary(t *testing.T) { } `) - CheckSnapshot(result, "mymodule_exports", "", + CheckSnapshot(t, result, "mymodule_exports", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -700,7 +700,7 @@ func TestMultipleHostOsTypesSnapshotWithCcBinary(t *testing.T) { } `) - CheckSnapshot(result, "myexports", "", + CheckSnapshot(t, result, "myexports", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -859,7 +859,7 @@ func TestSnapshotWithSingleHostOsType(t *testing.T) { } `) - CheckSnapshot(result, "myexports", "", + CheckSnapshot(t, result, "myexports", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -997,7 +997,7 @@ func TestSnapshotWithCcStaticNocrtBinary(t *testing.T) { } `) - CheckSnapshot(result, "mymodule_exports", "", + CheckSnapshot(t, result, "mymodule_exports", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1105,7 +1105,7 @@ func TestSnapshotWithCcSharedLibrary(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1206,7 +1206,7 @@ func TestSnapshotWithCcSharedLibrarySharedLibs(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1303,7 +1303,7 @@ func TestHostSnapshotWithCcSharedLibrary(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1430,7 +1430,7 @@ func TestMultipleHostOsTypesSnapshotWithCcSharedLibrary(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1558,7 +1558,7 @@ func TestSnapshotWithCcStaticLibrary(t *testing.T) { } `) - CheckSnapshot(result, "myexports", "", + CheckSnapshot(t, result, "myexports", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1621,7 +1621,7 @@ func TestHostSnapshotWithCcStaticLibrary(t *testing.T) { } `) - CheckSnapshot(result, "myexports", "", + CheckSnapshot(t, result, "myexports", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1735,7 +1735,7 @@ func TestSnapshotWithCcLibrary(t *testing.T) { } `) - CheckSnapshot(result, "myexports", "", + CheckSnapshot(t, result, "myexports", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1849,7 +1849,7 @@ func TestHostSnapshotWithMultiLib64(t *testing.T) { } `) - CheckSnapshot(result, "myexports", "", + CheckSnapshot(t, result, "myexports", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1946,7 +1946,7 @@ func TestSnapshotWithCcHeadersLibrary(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1984,7 +1984,7 @@ func TestHostSnapshotWithCcHeadersLibrary(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -2086,7 +2086,7 @@ func TestDeviceAndHostSnapshotWithCcHeadersLibrary(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -2118,7 +2118,6 @@ cc_prebuilt_library_headers { }, } `), - // Verifi checkVersionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -2199,7 +2198,7 @@ func TestSystemSharedLibPropagation(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -2272,7 +2271,7 @@ cc_prebuilt_library_shared { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -2383,7 +2382,7 @@ func TestStubsLibrary(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -2436,7 +2435,7 @@ func TestDeviceAndHostSnapshotWithStubsLibrary(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -2549,7 +2548,7 @@ func TestUniqueHostSoname(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -2664,7 +2663,7 @@ func TestNoSanitizerMembers(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkUnversionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. diff --git a/sdk/exports_test.go b/sdk/exports_test.go index 54a40d272..fd7741c7b 100644 --- a/sdk/exports_test.go +++ b/sdk/exports_test.go @@ -42,7 +42,7 @@ func TestModuleExportsSnapshot(t *testing.T) { "package/Android.bp": []byte(packageBp), }) - CheckSnapshot(result, "myexports", "package", + CheckSnapshot(t, result, "myexports", "package", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go index 40f276919..f4e9380dd 100644 --- a/sdk/java_sdk_test.go +++ b/sdk/java_sdk_test.go @@ -128,7 +128,7 @@ func TestSdkDependsOnSourceEvenWhenPrebuiltPreferred(t *testing.T) { // Make sure that the mysdk module depends on "sdkmember" and not "prebuilt_sdkmember". java.CheckModuleDependencies(t, result.TestContext, "mysdk", "android_common", []string{"sdkmember"}) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkAndroidBpContents(`// This is auto-generated. DO NOT EDIT. java_import { @@ -256,7 +256,7 @@ func TestSnapshotWithJavaHeaderLibrary(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -313,7 +313,7 @@ func TestHostSnapshotWithJavaHeaderLibrary(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -370,7 +370,7 @@ func TestDeviceAndHostSnapshotWithJavaHeaderLibrary(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -441,7 +441,7 @@ func TestSnapshotWithJavaImplLibrary(t *testing.T) { } `) - CheckSnapshot(result, "myexports", "", + CheckSnapshot(t, result, "myexports", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -497,7 +497,7 @@ func TestSnapshotWithJavaBootLibrary(t *testing.T) { } `) - CheckSnapshot(result, "myexports", "", + CheckSnapshot(t, result, "myexports", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -552,7 +552,7 @@ func TestHostSnapshotWithJavaImplLibrary(t *testing.T) { } `) - CheckSnapshot(result, "myexports", "", + CheckSnapshot(t, result, "myexports", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -608,7 +608,7 @@ func TestSnapshotWithJavaTest(t *testing.T) { } `) - CheckSnapshot(result, "myexports", "", + CheckSnapshot(t, result, "myexports", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -663,7 +663,7 @@ func TestHostSnapshotWithJavaTest(t *testing.T) { } `) - CheckSnapshot(result, "myexports", "", + CheckSnapshot(t, result, "myexports", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -732,7 +732,7 @@ func TestSnapshotWithJavaSystemModules(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -828,7 +828,7 @@ func TestHostSnapshotWithJavaSystemModules(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -919,7 +919,7 @@ func TestDeviceAndHostSnapshotWithOsSpecificMembers(t *testing.T) { } `) - CheckSnapshot(result, "myexports", "", + CheckSnapshot(t, result, "myexports", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1033,7 +1033,7 @@ func TestSnapshotWithJavaSdkLibrary(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1134,7 +1134,7 @@ func TestSnapshotWithJavaSdkLibrary_SdkVersion_None(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1203,7 +1203,7 @@ func TestSnapshotWithJavaSdkLibrary_SdkVersion_ForScope(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1275,7 +1275,7 @@ func TestSnapshotWithJavaSdkLibrary_ApiScopes(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1368,7 +1368,7 @@ func TestSnapshotWithJavaSdkLibrary_ModuleLib(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1476,7 +1476,7 @@ func TestSnapshotWithJavaSdkLibrary_SystemServer(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1564,7 +1564,7 @@ func TestSnapshotWithJavaSdkLibrary_NamingScheme(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -1640,7 +1640,7 @@ func TestSnapshotWithJavaSdkLibrary_DoctagFiles(t *testing.T) { } `) - CheckSnapshot(result, "mysdk", "", + CheckSnapshot(t, result, "mysdk", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go index 65a9001e6..05d8bdb92 100644 --- a/sdk/sdk_test.go +++ b/sdk/sdk_test.go @@ -169,7 +169,7 @@ func TestSnapshotVisibility(t *testing.T) { "package/Android.bp": []byte(packageBp), }) - CheckSnapshot(result, "mysdk", "package", + CheckSnapshot(t, result, "mysdk", "package", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -317,9 +317,8 @@ func TestSdkInstall(t *testing.T) { ` result := testSdkWithFs(t, sdk, nil) - CheckSnapshot(result, "mysdk", "", - checkAllOtherCopyRules(`.intermediates/mysdk/common_os/mysdk-current.zip -> mysdk-current.zip`), - ) + CheckSnapshot(t, result, "mysdk", "", + checkAllOtherCopyRules(`.intermediates/mysdk/common_os/mysdk-current.zip -> mysdk-current.zip`)) } type EmbeddedPropertiesStruct struct { @@ -387,12 +386,10 @@ func TestCommonValueOptimization(t *testing.T) { extractor := newCommonValueExtractor(common) - h := android.TestHelper{t} - err := extractor.extractCommonProperties(common, structs) - h.AssertDeepEquals("unexpected error", nil, err) + android.AssertDeepEquals(t, "unexpected error", nil, err) - h.AssertDeepEquals("common properties not correct", + android.AssertDeepEquals(t, "common properties not correct", &testPropertiesStruct{ name: "common", private: "", @@ -410,7 +407,7 @@ func TestCommonValueOptimization(t *testing.T) { }, common) - h.AssertDeepEquals("updated properties[0] not correct", + android.AssertDeepEquals(t, "updated properties[0] not correct", &testPropertiesStruct{ name: "struct-0", private: "common", @@ -428,7 +425,7 @@ func TestCommonValueOptimization(t *testing.T) { }, structs[0]) - h.AssertDeepEquals("updated properties[1] not correct", + android.AssertDeepEquals(t, "updated properties[1] not correct", &testPropertiesStruct{ name: "struct-1", private: "common", @@ -462,10 +459,8 @@ func TestCommonValueOptimization_InvalidArchSpecificVariants(t *testing.T) { extractor := newCommonValueExtractor(common) - h := android.TestHelper{t} - err := extractor.extractCommonProperties(common, structs) - h.AssertErrorMessageEquals("unexpected error", `field "S_Common" is not tagged as "arch_variant" but has arch specific properties: + android.AssertErrorMessageEquals(t, "unexpected error", `field "S_Common" is not tagged as "arch_variant" but has arch specific properties: "struct-0" has value "should-be-but-is-not-common0" "struct-1" has value "should-be-but-is-not-common1"`, err) } diff --git a/sdk/testing.go b/sdk/testing.go index 41280fc5c..a5519f8f0 100644 --- a/sdk/testing.go +++ b/sdk/testing.go @@ -108,8 +108,9 @@ func pathsToStrings(paths android.Paths) []string { // // e.g. find the src/dest pairs from each cp command, the various zip files // generated, etc. -func getSdkSnapshotBuildInfo(result *android.TestResult, sdk *sdk) *snapshotBuildInfo { +func getSdkSnapshotBuildInfo(t *testing.T, result *android.TestResult, sdk *sdk) *snapshotBuildInfo { info := &snapshotBuildInfo{ + t: t, r: result, androidBpContents: sdk.GetAndroidBpContentsForTests(), androidUnversionedBpContents: sdk.GetUnversionedAndroidBpContentsForTests(), @@ -153,7 +154,7 @@ func getSdkSnapshotBuildInfo(result *android.TestResult, sdk *sdk) *snapshotBuil info.intermediateZip = info.outputZip mergeInput := android.NormalizePathForTesting(bp.Input) if info.intermediateZip != mergeInput { - result.Errorf("Expected intermediate zip %s to be an input to merge zips but found %s instead", + t.Errorf("Expected intermediate zip %s to be an input to merge zips but found %s instead", info.intermediateZip, mergeInput) } @@ -177,15 +178,15 @@ func getSdkSnapshotBuildInfo(result *android.TestResult, sdk *sdk) *snapshotBuil // Takes a list of functions which check different facets of the snapshot build rules. // Allows each test to customize what is checked without duplicating lots of code // or proliferating check methods of different flavors. -func CheckSnapshot(result *android.TestResult, name string, dir string, checkers ...snapshotBuildInfoChecker) { - result.Helper() +func CheckSnapshot(t *testing.T, result *android.TestResult, name string, dir string, checkers ...snapshotBuildInfoChecker) { + t.Helper() // The sdk CommonOS variant is always responsible for generating the snapshot. variant := android.CommonOS.Name sdk := result.Module(name, variant).(*sdk) - snapshotBuildInfo := getSdkSnapshotBuildInfo(result, sdk) + snapshotBuildInfo := getSdkSnapshotBuildInfo(t, result, sdk) // Check state of the snapshot build. for _, checker := range checkers { @@ -197,7 +198,7 @@ func CheckSnapshot(result *android.TestResult, name string, dir string, checkers if dir != "" { dir = filepath.Clean(dir) + "/" } - result.AssertStringEquals("Snapshot zip file in wrong place", + android.AssertStringEquals(t, "Snapshot zip file in wrong place", fmt.Sprintf(".intermediates/%s%s/%s/%s-current.zip", dir, name, variant, name), actual) // Populate a mock filesystem with the files that would have been copied by @@ -208,7 +209,7 @@ func CheckSnapshot(result *android.TestResult, name string, dir string, checkers } // Process the generated bp file to make sure it is valid. - testSdkWithFs(result.T, snapshotBuildInfo.androidBpContents, fs) + testSdkWithFs(t, snapshotBuildInfo.androidBpContents, fs) } type snapshotBuildInfoChecker func(info *snapshotBuildInfo) @@ -218,8 +219,8 @@ type snapshotBuildInfoChecker func(info *snapshotBuildInfo) // Both the expected and actual string are both trimmed before comparing. func checkAndroidBpContents(expected string) snapshotBuildInfoChecker { return func(info *snapshotBuildInfo) { - info.r.Helper() - info.r.AssertTrimmedStringEquals("Android.bp contents do not match", expected, info.androidBpContents) + info.t.Helper() + android.AssertTrimmedStringEquals(info.t, "Android.bp contents do not match", expected, info.androidBpContents) } } @@ -230,8 +231,8 @@ func checkAndroidBpContents(expected string) snapshotBuildInfoChecker { // Both the expected and actual string are both trimmed before comparing. func checkUnversionedAndroidBpContents(expected string) snapshotBuildInfoChecker { return func(info *snapshotBuildInfo) { - info.r.Helper() - info.r.AssertTrimmedStringEquals("unversioned Android.bp contents do not match", expected, info.androidUnversionedBpContents) + info.t.Helper() + android.AssertTrimmedStringEquals(info.t, "unversioned Android.bp contents do not match", expected, info.androidUnversionedBpContents) } } @@ -245,8 +246,8 @@ func checkUnversionedAndroidBpContents(expected string) snapshotBuildInfoChecker // Both the expected and actual string are both trimmed before comparing. func checkVersionedAndroidBpContents(expected string) snapshotBuildInfoChecker { return func(info *snapshotBuildInfo) { - info.r.Helper() - info.r.AssertTrimmedStringEquals("versioned Android.bp contents do not match", expected, info.androidVersionedBpContents) + info.t.Helper() + android.AssertTrimmedStringEquals(info.t, "versioned Android.bp contents do not match", expected, info.androidVersionedBpContents) } } @@ -257,27 +258,27 @@ func checkVersionedAndroidBpContents(expected string) snapshotBuildInfoChecker { // before comparing. func checkAllCopyRules(expected string) snapshotBuildInfoChecker { return func(info *snapshotBuildInfo) { - info.r.Helper() - info.r.AssertTrimmedStringEquals("Incorrect copy rules", expected, info.copyRules) + info.t.Helper() + android.AssertTrimmedStringEquals(info.t, "Incorrect copy rules", expected, info.copyRules) } } func checkAllOtherCopyRules(expected string) snapshotBuildInfoChecker { return func(info *snapshotBuildInfo) { - info.r.Helper() - info.r.AssertTrimmedStringEquals("Incorrect copy rules", expected, info.otherCopyRules) + info.t.Helper() + android.AssertTrimmedStringEquals(info.t, "Incorrect copy rules", expected, info.otherCopyRules) } } // Check that the specified paths match the list of zips to merge with the intermediate zip. func checkMergeZips(expected ...string) snapshotBuildInfoChecker { return func(info *snapshotBuildInfo) { - info.r.Helper() + info.t.Helper() if info.intermediateZip == "" { - info.r.Errorf("No intermediate zip file was created") + info.t.Errorf("No intermediate zip file was created") } - info.r.AssertDeepEquals("mismatching merge zip files", expected, info.mergeZips) + android.AssertDeepEquals(info.t, "mismatching merge zip files", expected, info.mergeZips) } } @@ -287,6 +288,9 @@ func checkMergeZips(expected ...string) snapshotBuildInfoChecker { // All source/input paths are relative either the build directory. All dest/output paths are // relative to the snapshot root directory. type snapshotBuildInfo struct { + t *testing.T + + // The result from RunTest() r *android.TestResult // The contents of the generated Android.bp file