diff --git a/java/androidmk_test.go b/java/androidmk_test.go index 0b1961b4d..5eaa77b32 100644 --- a/java/androidmk_test.go +++ b/java/androidmk_test.go @@ -135,7 +135,8 @@ func TestHostdexSpecificRequired(t *testing.T) { } func TestJavaSdkLibrary_RequireXmlPermissionFile(t *testing.T) { - result := javaFixtureFactory.Extend( + result := android.GroupFixturePreparers( + prepareForJavaTest, PrepareForTestWithJavaSdkLibraryFiles, FixtureWithLastReleaseApis("foo-shared_library", "foo-no_shared_library"), ).RunTestWithBp(t, ` diff --git a/java/app_test.go b/java/app_test.go index 609ddf1a8..252353364 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -29,14 +29,14 @@ import ( "android/soong/genrule" ) -// testApp runs tests using the javaFixtureFactory +// testApp runs tests using the prepareForJavaTest // // See testJava for an explanation as to how to stop using this deprecated method. // // deprecated func testApp(t *testing.T, bp string) *android.TestContext { t.Helper() - result := javaFixtureFactory.RunTestWithBp(t, bp) + result := prepareForJavaTest.RunTestWithBp(t, bp) return result.TestContext } @@ -55,7 +55,8 @@ func TestApp(t *testing.T) { for _, moduleType := range []string{"android_app", "android_library"} { t.Run(moduleType, func(t *testing.T) { - result := javaFixtureFactory.Extend( + result := android.GroupFixturePreparers( + prepareForJavaTest, android.FixtureModifyMockFS(func(fs android.MockFS) { for _, file := range resourceFiles { fs[file] = nil @@ -364,8 +365,8 @@ func TestUpdatableApps(t *testing.T) { if test.expectedError != "" { errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(test.expectedError) } - javaFixtureFactory. - Extend(FixtureWithPrebuiltApis(map[string][]string{ + android.GroupFixturePreparers( + prepareForJavaTest, FixtureWithPrebuiltApis(map[string][]string{ "29": {"foo"}, })). ExtendWithErrorHandler(errorHandler).RunTestWithBp(t, test.bp) @@ -1063,7 +1064,8 @@ func TestAppSdkVersion(t *testing.T) { %s }`, moduleType, test.sdkVersion, platformApiProp) - result := javaFixtureFactory.Extend( + result := android.GroupFixturePreparers( + prepareForJavaTest, android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { variables.Platform_sdk_version = &test.platformSdkInt variables.Platform_sdk_codename = &test.platformSdkCodename @@ -1131,7 +1133,8 @@ func TestVendorAppSdkVersion(t *testing.T) { vendor: true, }`, moduleType, sdkKind, test.sdkVersion) - result := javaFixtureFactory.Extend( + result := android.GroupFixturePreparers( + prepareForJavaTest, android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { variables.Platform_sdk_version = &test.platformSdkInt variables.Platform_sdk_codename = &test.platformSdkCodename @@ -2331,7 +2334,8 @@ func TestUsesLibraries(t *testing.T) { } ` - result := javaFixtureFactory.Extend( + result := android.GroupFixturePreparers( + prepareForJavaTest, PrepareForTestWithJavaSdkLibraryFiles, FixtureWithLastReleaseApis("runtime-library", "foo", "quuz", "qux", "bar", "fred"), android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { @@ -2681,7 +2685,8 @@ func TestUncompressDex(t *testing.T) { test := func(t *testing.T, bp string, want bool, unbundled bool) { t.Helper() - result := javaFixtureFactory.Extend( + result := android.GroupFixturePreparers( + prepareForJavaTest, PrepareForTestWithPrebuiltsOfCurrentApi, android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { if unbundled { diff --git a/java/dexpreopt_bootjars_test.go b/java/dexpreopt_bootjars_test.go index 9db53fc0d..d78651d90 100644 --- a/java/dexpreopt_bootjars_test.go +++ b/java/dexpreopt_bootjars_test.go @@ -43,12 +43,12 @@ func testDexpreoptBoot(t *testing.T, ruleFile string, expectedInputs, expectedOu } ` - result := javaFixtureFactory. - Extend( - PrepareForTestWithJavaSdkLibraryFiles, - FixtureWithLastReleaseApis("foo"), - dexpreopt.FixtureSetBootJars("platform:foo", "platform:bar", "platform:baz"), - ).RunTestWithBp(t, bp) + result := android.GroupFixturePreparers( + prepareForJavaTest, + PrepareForTestWithJavaSdkLibraryFiles, + FixtureWithLastReleaseApis("foo"), + dexpreopt.FixtureSetBootJars("platform:foo", "platform:bar", "platform:baz"), + ).RunTestWithBp(t, bp) dexpreoptBootJars := result.SingletonForTests("dex_bootjars") rule := dexpreoptBootJars.Output(ruleFile) diff --git a/java/hiddenapi_singleton_test.go b/java/hiddenapi_singleton_test.go index 12a85d59e..d6c6a2ddc 100644 --- a/java/hiddenapi_singleton_test.go +++ b/java/hiddenapi_singleton_test.go @@ -35,7 +35,8 @@ func fixtureSetPrebuiltHiddenApiDirProductVariable(prebuiltHiddenApiDir *string) }) } -var hiddenApiFixtureFactory = javaFixtureFactory.Extend(PrepareForTestWithHiddenApiBuildComponents) +var hiddenApiFixtureFactory = android.GroupFixturePreparers( + prepareForJavaTest, PrepareForTestWithHiddenApiBuildComponents) func TestHiddenAPISingleton(t *testing.T) { result := hiddenApiFixtureFactory.Extend( diff --git a/java/java_test.go b/java/java_test.go index a907c8263..b6f639f98 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -33,14 +33,6 @@ import ( "android/soong/python" ) -// Legacy factory to use to create fixtures for tests in this package. -// -// deprecated: See prepareForJavaTest -var javaFixtureFactory = android.NewFixtureFactory( - nil, - prepareForJavaTest, -) - // Legacy preparer used for running tests within the java package. // // This includes everything that was needed to run any test in the java package prior to the @@ -75,8 +67,8 @@ func TestMain(m *testing.M) { // deprecated func testJavaError(t *testing.T, pattern string, bp string) (*android.TestContext, android.Config) { t.Helper() - result := javaFixtureFactory. - Extend(dexpreopt.PrepareForTestWithDexpreopt). + result := android.GroupFixturePreparers( + prepareForJavaTest, dexpreopt.PrepareForTestWithDexpreopt). ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)). RunTestWithBp(t, bp) return result.TestContext, result.Config @@ -93,37 +85,38 @@ func testJavaErrorWithConfig(t *testing.T, pattern string, config android.Config // the fixture's config will be ignored when RunTestWithConfig replaces it. pathCtx := android.PathContextForTesting(config) dexpreopt.SetTestGlobalConfig(config, dexpreopt.GlobalConfigForTests(pathCtx)) - result := javaFixtureFactory. + result := prepareForJavaTest. ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)). RunTestWithConfig(t, config) return result.TestContext, result.Config } -// testJavaWithFS runs tests using the javaFixtureFactory +// testJavaWithFS runs tests using the prepareForJavaTest // // See testJava for an explanation as to how to stop using this deprecated method. // // deprecated func testJavaWithFS(t *testing.T, bp string, fs android.MockFS) (*android.TestContext, android.Config) { t.Helper() - result := javaFixtureFactory.Extend(fs.AddToFixture()).RunTestWithBp(t, bp) + result := android.GroupFixturePreparers( + prepareForJavaTest, fs.AddToFixture()).RunTestWithBp(t, bp) return result.TestContext, result.Config } -// testJava runs tests using the javaFixtureFactory +// testJava runs tests using the prepareForJavaTest // -// Do not add any new usages of this, instead use the javaFixtureFactory directly as it makes it +// Do not add any new usages of this, instead use the prepareForJavaTest directly as it makes it // much easier to customize the test behavior. // // If it is necessary to customize the behavior of an existing test that uses this then please first -// convert the test to using javaFixtureFactory first and then in a following change add the +// convert the test to using prepareForJavaTest first and then in a following change add the // appropriate fixture preparers. Keeping the conversion change separate makes it easy to verify // that it did not change the test behavior unexpectedly. // // deprecated func testJava(t *testing.T, bp string) (*android.TestContext, android.Config) { t.Helper() - result := javaFixtureFactory.RunTestWithBp(t, bp) + result := prepareForJavaTest.RunTestWithBp(t, bp) return result.TestContext, result.Config } @@ -638,7 +631,7 @@ prebuilt_stubs_sources { } func TestJavaSdkLibraryImport(t *testing.T) { - result := javaFixtureFactory.RunTestWithBp(t, ` + result := prepareForJavaTest.RunTestWithBp(t, ` java_library { name: "foo", srcs: ["a.java"], @@ -692,7 +685,8 @@ func TestJavaSdkLibraryImport(t *testing.T) { } func TestJavaSdkLibraryImport_WithSource(t *testing.T) { - result := javaFixtureFactory.Extend( + result := android.GroupFixturePreparers( + prepareForJavaTest, PrepareForTestWithJavaSdkLibraryFiles, FixtureWithLastReleaseApis("sdklib"), ).RunTestWithBp(t, ` @@ -734,7 +728,8 @@ func TestJavaSdkLibraryImport_WithSource(t *testing.T) { } func TestJavaSdkLibraryImport_Preferred(t *testing.T) { - result := javaFixtureFactory.Extend( + result := android.GroupFixturePreparers( + prepareForJavaTest, PrepareForTestWithJavaSdkLibraryFiles, FixtureWithLastReleaseApis("sdklib"), ).RunTestWithBp(t, ` @@ -841,7 +836,7 @@ func TestJavaSdkLibraryEnforce(t *testing.T) { if expectedErrorPattern != "" { errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(expectedErrorPattern) } - javaFixtureFactory.ExtendWithErrorHandler(errorHandler).RunTest(t, createPreparer(info)) + prepareForJavaTest.ExtendWithErrorHandler(errorHandler).RunTest(t, createPreparer(info)) }) } @@ -1319,8 +1314,8 @@ func TestGeneratedSources(t *testing.T) { } func TestTurbine(t *testing.T) { - result := javaFixtureFactory. - Extend(FixtureWithPrebuiltApis(map[string][]string{"14": {"foo"}})). + result := android.GroupFixturePreparers( + prepareForJavaTest, FixtureWithPrebuiltApis(map[string][]string{"14": {"foo"}})). RunTestWithBp(t, ` java_library { name: "foo", @@ -1731,7 +1726,8 @@ func TestJavaImport(t *testing.T) { } func TestJavaSdkLibrary(t *testing.T) { - result := javaFixtureFactory.Extend( + result := android.GroupFixturePreparers( + prepareForJavaTest, PrepareForTestWithJavaSdkLibraryFiles, FixtureWithPrebuiltApis(map[string][]string{ "28": {"foo"}, @@ -1856,7 +1852,8 @@ func TestJavaSdkLibrary(t *testing.T) { } func TestJavaSdkLibrary_StubOrImplOnlyLibs(t *testing.T) { - result := javaFixtureFactory.Extend( + result := android.GroupFixturePreparers( + prepareForJavaTest, PrepareForTestWithJavaSdkLibraryFiles, FixtureWithLastReleaseApis("sdklib"), ).RunTestWithBp(t, ` @@ -1892,7 +1889,8 @@ func TestJavaSdkLibrary_StubOrImplOnlyLibs(t *testing.T) { } func TestJavaSdkLibrary_DoNotAccessImplWhenItIsNotBuilt(t *testing.T) { - result := javaFixtureFactory.Extend( + result := android.GroupFixturePreparers( + prepareForJavaTest, PrepareForTestWithJavaSdkLibraryFiles, FixtureWithLastReleaseApis("foo"), ).RunTestWithBp(t, ` @@ -1920,7 +1918,8 @@ func TestJavaSdkLibrary_DoNotAccessImplWhenItIsNotBuilt(t *testing.T) { } func TestJavaSdkLibrary_UseSourcesFromAnotherSdkLibrary(t *testing.T) { - javaFixtureFactory.Extend( + android.GroupFixturePreparers( + prepareForJavaTest, PrepareForTestWithJavaSdkLibraryFiles, FixtureWithLastReleaseApis("foo"), ).RunTestWithBp(t, ` @@ -1941,11 +1940,11 @@ func TestJavaSdkLibrary_UseSourcesFromAnotherSdkLibrary(t *testing.T) { } func TestJavaSdkLibrary_AccessOutputFiles_MissingScope(t *testing.T) { - javaFixtureFactory. - Extend( - PrepareForTestWithJavaSdkLibraryFiles, - FixtureWithLastReleaseApis("foo"), - ). + android.GroupFixturePreparers( + prepareForJavaTest, + PrepareForTestWithJavaSdkLibraryFiles, + FixtureWithLastReleaseApis("foo"), + ). ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`"foo" does not provide api scope system`)). RunTestWithBp(t, ` java_sdk_library { @@ -1965,7 +1964,8 @@ func TestJavaSdkLibrary_AccessOutputFiles_MissingScope(t *testing.T) { } func TestJavaSdkLibrary_Deps(t *testing.T) { - result := javaFixtureFactory.Extend( + result := android.GroupFixturePreparers( + prepareForJavaTest, PrepareForTestWithJavaSdkLibraryFiles, FixtureWithLastReleaseApis("sdklib"), ).RunTestWithBp(t, ` @@ -1990,7 +1990,7 @@ func TestJavaSdkLibrary_Deps(t *testing.T) { } func TestJavaSdkLibraryImport_AccessOutputFiles(t *testing.T) { - javaFixtureFactory.RunTestWithBp(t, ` + prepareForJavaTest.RunTestWithBp(t, ` java_sdk_library_import { name: "foo", public: { @@ -2023,7 +2023,7 @@ func TestJavaSdkLibraryImport_AccessOutputFiles_Invalid(t *testing.T) { ` t.Run("stubs.source", func(t *testing.T) { - javaFixtureFactory. + prepareForJavaTest. ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`stubs.source not available for api scope public`)). RunTestWithBp(t, bp+` java_library { @@ -2038,7 +2038,7 @@ func TestJavaSdkLibraryImport_AccessOutputFiles_Invalid(t *testing.T) { }) t.Run("api.txt", func(t *testing.T) { - javaFixtureFactory. + prepareForJavaTest. ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`api.txt not available for api scope public`)). RunTestWithBp(t, bp+` java_library { @@ -2052,7 +2052,7 @@ func TestJavaSdkLibraryImport_AccessOutputFiles_Invalid(t *testing.T) { }) t.Run("removed-api.txt", func(t *testing.T) { - javaFixtureFactory. + prepareForJavaTest. ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`removed-api.txt not available for api scope public`)). RunTestWithBp(t, bp+` java_library { @@ -2067,7 +2067,7 @@ func TestJavaSdkLibraryImport_AccessOutputFiles_Invalid(t *testing.T) { } func TestJavaSdkLibrary_InvalidScopes(t *testing.T) { - javaFixtureFactory. + prepareForJavaTest. ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module "foo": enabled api scope "system" depends on disabled scope "public"`)). RunTestWithBp(t, ` java_sdk_library { @@ -2087,7 +2087,8 @@ func TestJavaSdkLibrary_InvalidScopes(t *testing.T) { } func TestJavaSdkLibrary_SdkVersion_ForScope(t *testing.T) { - javaFixtureFactory.Extend( + android.GroupFixturePreparers( + prepareForJavaTest, PrepareForTestWithJavaSdkLibraryFiles, FixtureWithLastReleaseApis("foo"), ).RunTestWithBp(t, ` @@ -2104,7 +2105,8 @@ func TestJavaSdkLibrary_SdkVersion_ForScope(t *testing.T) { } func TestJavaSdkLibrary_ModuleLib(t *testing.T) { - javaFixtureFactory.Extend( + android.GroupFixturePreparers( + prepareForJavaTest, PrepareForTestWithJavaSdkLibraryFiles, FixtureWithLastReleaseApis("foo"), ).RunTestWithBp(t, ` @@ -2123,7 +2125,8 @@ func TestJavaSdkLibrary_ModuleLib(t *testing.T) { } func TestJavaSdkLibrary_SystemServer(t *testing.T) { - javaFixtureFactory.Extend( + android.GroupFixturePreparers( + prepareForJavaTest, PrepareForTestWithJavaSdkLibraryFiles, FixtureWithLastReleaseApis("foo"), ).RunTestWithBp(t, ` @@ -2142,7 +2145,7 @@ func TestJavaSdkLibrary_SystemServer(t *testing.T) { } func TestJavaSdkLibrary_MissingScope(t *testing.T) { - javaFixtureFactory. + prepareForJavaTest. ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`requires api scope module-lib from foo but it only has \[\] available`)). RunTestWithBp(t, ` java_sdk_library { @@ -2163,7 +2166,8 @@ func TestJavaSdkLibrary_MissingScope(t *testing.T) { } func TestJavaSdkLibrary_FallbackScope(t *testing.T) { - javaFixtureFactory.Extend( + android.GroupFixturePreparers( + prepareForJavaTest, PrepareForTestWithJavaSdkLibraryFiles, FixtureWithLastReleaseApis("foo"), ).RunTestWithBp(t, ` @@ -2186,7 +2190,8 @@ func TestJavaSdkLibrary_FallbackScope(t *testing.T) { } func TestJavaSdkLibrary_DefaultToStubs(t *testing.T) { - result := javaFixtureFactory.Extend( + result := android.GroupFixturePreparers( + prepareForJavaTest, PrepareForTestWithJavaSdkLibraryFiles, FixtureWithLastReleaseApis("foo"), ).RunTestWithBp(t, ` diff --git a/java/sdk_test.go b/java/sdk_test.go index ff0a2039b..028c4fe9a 100644 --- a/java/sdk_test.go +++ b/java/sdk_test.go @@ -349,7 +349,8 @@ func TestClasspath(t *testing.T) { android.AssertPathsRelativeToTopEquals(t, "implicits", deps, javac.Implicits) } - fixtureFactory := javaFixtureFactory.Extend( + fixtureFactory := android.GroupFixturePreparers( + prepareForJavaTest, FixtureWithPrebuiltApis(map[string][]string{ "29": {}, "30": {}, diff --git a/java/system_modules_test.go b/java/system_modules_test.go index 3d9f398ce..7d8935a4d 100644 --- a/java/system_modules_test.go +++ b/java/system_modules_test.go @@ -50,7 +50,7 @@ var addSourceSystemModules = android.FixtureAddTextFile("source/Android.bp", ` `) func TestJavaSystemModules(t *testing.T) { - result := javaFixtureFactory.RunTest(t, addSourceSystemModules) + result := prepareForJavaTest.RunTest(t, addSourceSystemModules) // check the existence of the source module sourceSystemModules := result.ModuleForTests("system-modules", "android_common") @@ -77,7 +77,7 @@ var addPrebuiltSystemModules = android.FixtureAddTextFile("prebuilts/Android.bp" `) func TestJavaSystemModulesImport(t *testing.T) { - result := javaFixtureFactory.RunTest(t, addPrebuiltSystemModules) + result := prepareForJavaTest.RunTest(t, addPrebuiltSystemModules) // check the existence of the renamed prebuilt module prebuiltSystemModules := result.ModuleForTests("system-modules", "android_common") @@ -89,7 +89,7 @@ func TestJavaSystemModulesImport(t *testing.T) { } func TestJavaSystemModulesMixSourceAndPrebuilt(t *testing.T) { - result := javaFixtureFactory.RunTest(t, + result := prepareForJavaTest.RunTest(t, addSourceSystemModules, addPrebuiltSystemModules, )