diff --git a/java/androidmk_test.go b/java/androidmk_test.go index 107837d06..fbf2baa97 100644 --- a/java/androidmk_test.go +++ b/java/androidmk_test.go @@ -15,18 +15,20 @@ package java import ( - "android/soong/android" "bytes" "io" "io/ioutil" "strings" "testing" + + "android/soong/android" ) type testAndroidMk struct { *testing.T body []byte } + type testAndroidMkModule struct { *testing.T props map[string]string @@ -115,30 +117,26 @@ func getAndroidMk(t *testing.T, ctx *android.TestContext, config android.Config, } func TestRequired(t *testing.T) { - config := testConfig(nil) - ctx := testContext(config, ` + ctx, config := testJava(t, ` java_library { name: "foo", srcs: ["a.java"], required: ["libfoo"], } - `, nil) - run(t, ctx, config) + `) mk := getAndroidMk(t, ctx, config, "foo") mk.moduleFor("foo").hasRequired("libfoo") } func TestHostdex(t *testing.T) { - config := testConfig(nil) - ctx := testContext(config, ` + ctx, config := testJava(t, ` java_library { name: "foo", srcs: ["a.java"], hostdex: true, } - `, nil) - run(t, ctx, config) + `) mk := getAndroidMk(t, ctx, config, "foo") mk.moduleFor("foo") @@ -146,16 +144,14 @@ func TestHostdex(t *testing.T) { } func TestHostdexRequired(t *testing.T) { - config := testConfig(nil) - ctx := testContext(config, ` + ctx, config := testJava(t, ` java_library { name: "foo", srcs: ["a.java"], hostdex: true, required: ["libfoo"], } - `, nil) - run(t, ctx, config) + `) mk := getAndroidMk(t, ctx, config, "foo") mk.moduleFor("foo").hasRequired("libfoo") @@ -163,8 +159,7 @@ func TestHostdexRequired(t *testing.T) { } func TestHostdexSpecificRequired(t *testing.T) { - config := testConfig(nil) - ctx := testContext(config, ` + ctx, config := testJava(t, ` java_library { name: "foo", srcs: ["a.java"], @@ -175,8 +170,7 @@ func TestHostdexSpecificRequired(t *testing.T) { }, }, } - `, nil) - run(t, ctx, config) + `) mk := getAndroidMk(t, ctx, config, "foo") mk.moduleFor("foo").hasNoRequired("libfoo") diff --git a/java/app_test.go b/java/app_test.go index f08969d2e..32de019f1 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -43,7 +43,7 @@ var ( } ) -func testAppContext(config android.Config, bp string, fs map[string][]byte) *android.TestContext { +func testAppContext(bp string, fs map[string][]byte) *android.TestContext { appFS := map[string][]byte{} for k, v := range fs { appFS[k] = v @@ -53,13 +53,13 @@ func testAppContext(config android.Config, bp string, fs map[string][]byte) *and appFS[file] = nil } - return testContext(config, bp, appFS) + return testContext(bp, appFS) } func testApp(t *testing.T, bp string) *android.TestContext { config := testConfig(nil) - ctx := testAppContext(config, bp, nil) + ctx := testAppContext(bp, nil) run(t, ctx, config) @@ -176,7 +176,7 @@ func TestResourceDirs(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.name, func(t *testing.T) { config := testConfig(nil) - ctx := testContext(config, fmt.Sprintf(bp, testCase.prop), fs) + ctx := testContext(fmt.Sprintf(bp, testCase.prop), fs) run(t, ctx, config) module := ctx.ModuleForTests("foo", "android_common") @@ -388,7 +388,7 @@ func TestAndroidResources(t *testing.T) { config.TestProductVariables.EnforceRROExcludedOverlays = testCase.enforceRROExcludedOverlays } - ctx := testAppContext(config, bp, fs) + ctx := testAppContext(bp, fs) run(t, ctx, config) resourceListToFiles := func(module android.TestingModule, list []string) (files []string) { @@ -515,7 +515,7 @@ func TestAppSdkVersion(t *testing.T) { config.TestProductVariables.Platform_sdk_codename = &test.platformSdkCodename config.TestProductVariables.Platform_sdk_final = &test.platformSdkFinal - ctx := testAppContext(config, bp, nil) + ctx := testAppContext(bp, nil) run(t, ctx, config) @@ -547,7 +547,7 @@ func TestAppSdkVersion(t *testing.T) { } func TestJNIABI(t *testing.T) { - ctx := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+` + ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+` cc_library { name: "libjni", system_shared_libs: [], @@ -620,7 +620,7 @@ func TestJNIABI(t *testing.T) { } func TestJNIPackaging(t *testing.T) { - ctx := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+` + ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+` cc_library { name: "libjni", system_shared_libs: [], @@ -774,7 +774,7 @@ func TestCertificates(t *testing.T) { if test.certificateOverride != "" { config.TestProductVariables.CertificateOverrides = []string{test.certificateOverride} } - ctx := testAppContext(config, test.bp, nil) + ctx := testAppContext(test.bp, nil) run(t, ctx, config) foo := ctx.ModuleForTests("foo", "android_common") @@ -832,7 +832,7 @@ func TestPackageNameOverride(t *testing.T) { if test.packageNameOverride != "" { config.TestProductVariables.PackageNameOverrides = []string{test.packageNameOverride} } - ctx := testAppContext(config, test.bp, nil) + ctx := testAppContext(test.bp, nil) run(t, ctx, config) foo := ctx.ModuleForTests("foo", "android_common") @@ -865,7 +865,7 @@ func TestInstrumentationTargetOverridden(t *testing.T) { ` config := testConfig(nil) config.TestProductVariables.ManifestPackageNameOverrides = []string{"foo:org.dandroid.bp"} - ctx := testAppContext(config, bp, nil) + ctx := testAppContext(bp, nil) run(t, ctx, config) @@ -879,7 +879,7 @@ func TestInstrumentationTargetOverridden(t *testing.T) { } func TestOverrideAndroidApp(t *testing.T) { - ctx := testJava(t, ` + ctx, _ := testJava(t, ` android_app { name: "foo", srcs: ["a.java"], @@ -980,7 +980,7 @@ func TestOverrideAndroidApp(t *testing.T) { } func TestOverrideAndroidAppDependency(t *testing.T) { - ctx := testJava(t, ` + ctx, _ := testJava(t, ` android_app { name: "foo", srcs: ["a.java"], @@ -1021,7 +1021,7 @@ func TestOverrideAndroidAppDependency(t *testing.T) { } func TestAndroidAppImport(t *testing.T) { - ctx := testJava(t, ` + ctx, _ := testJava(t, ` android_app_import { name: "foo", apk: "prebuilts/apk/app.apk", @@ -1050,7 +1050,7 @@ func TestAndroidAppImport(t *testing.T) { } func TestAndroidAppImport_NoDexPreopt(t *testing.T) { - ctx := testJava(t, ` + ctx, _ := testJava(t, ` android_app_import { name: "foo", apk: "prebuilts/apk/app.apk", @@ -1071,7 +1071,7 @@ func TestAndroidAppImport_NoDexPreopt(t *testing.T) { } func TestAndroidAppImport_Presigned(t *testing.T) { - ctx := testJava(t, ` + ctx, _ := testJava(t, ` android_app_import { name: "foo", apk: "prebuilts/apk/app.apk", @@ -1166,7 +1166,7 @@ func TestAndroidAppImport_DpiVariants(t *testing.T) { config := testConfig(nil) config.TestProductVariables.AAPTPreferredConfig = test.aaptPreferredConfig config.TestProductVariables.AAPTPrebuiltDPI = test.aaptPrebuiltDPI - ctx := testAppContext(config, bp, nil) + ctx := testAppContext(bp, nil) run(t, ctx, config) @@ -1183,7 +1183,7 @@ func TestAndroidAppImport_DpiVariants(t *testing.T) { } func TestStl(t *testing.T) { - ctx := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+` + ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+` cc_library { name: "libjni", } @@ -1286,7 +1286,7 @@ func TestUsesLibraries(t *testing.T) { config := testConfig(nil) config.TestProductVariables.MissingUsesLibraries = []string{"baz"} - ctx := testAppContext(config, bp, nil) + ctx := testAppContext(bp, nil) run(t, ctx, config) @@ -1398,7 +1398,7 @@ func TestCodelessApp(t *testing.T) { } func TestEmbedNotice(t *testing.T) { - ctx := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+` + ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+` android_app { name: "foo", srcs: ["a.java"], @@ -1549,7 +1549,7 @@ func TestUncompressDex(t *testing.T) { config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) } - ctx := testAppContext(config, bp, nil) + ctx := testAppContext(bp, nil) run(t, ctx, config) diff --git a/java/device_host_converter_test.go b/java/device_host_converter_test.go index 9b9d0d899..44aae9b36 100644 --- a/java/device_host_converter_test.go +++ b/java/device_host_converter_test.go @@ -50,9 +50,7 @@ func TestDeviceForHost(t *testing.T) { } ` - config := testConfig(nil) - ctx := testContext(config, bp, nil) - run(t, ctx, config) + ctx, config := testJava(t, bp) deviceModule := ctx.ModuleForTests("device_module", "android_common") deviceTurbineCombined := deviceModule.Output("turbine-combined/device_module.jar") @@ -133,9 +131,7 @@ func TestHostForDevice(t *testing.T) { } ` - config := testConfig(nil) - ctx := testContext(config, bp, nil) - run(t, ctx, config) + ctx, config := testJava(t, bp) hostModule := ctx.ModuleForTests("host_module", config.BuildOsCommonVariant) hostJavac := hostModule.Output("javac/host_module.jar") diff --git a/java/dexpreopt_bootjars_test.go b/java/dexpreopt_bootjars_test.go index f91ff6925..4c38399d3 100644 --- a/java/dexpreopt_bootjars_test.go +++ b/java/dexpreopt_bootjars_test.go @@ -51,7 +51,7 @@ func TestDexpreoptBootJars(t *testing.T) { dexpreoptConfig.RuntimeApexJars = []string{"foo", "bar", "baz"} setDexpreoptTestGlobalConfig(config, dexpreoptConfig) - ctx := testContext(config, bp, nil) + ctx := testContext(bp, nil) ctx.RegisterSingletonType("dex_bootjars", android.SingletonFactoryAdaptor(dexpreoptBootJarsFactory)) diff --git a/java/dexpreopt_test.go b/java/dexpreopt_test.go index 7d0109fda..22b7bb9d5 100644 --- a/java/dexpreopt_test.go +++ b/java/dexpreopt_test.go @@ -142,7 +142,7 @@ func TestDexpreoptEnabled(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - ctx := testJava(t, test.bp) + ctx, _ := testJava(t, test.bp) dexpreopt := ctx.ModuleForTests("foo", "android_common").MaybeDescription("dexpreopt") enabled := dexpreopt.Rule != nil diff --git a/java/java_test.go b/java/java_test.go index 677174d39..5942afe00 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -57,8 +57,7 @@ func testConfig(env map[string]string) android.Config { return TestConfig(buildDir, env) } -func testContext(config android.Config, bp string, - fs map[string][]byte) *android.TestContext { +func testContext(bp string, fs map[string][]byte) *android.TestContext { ctx := android.NewTestArchContext() ctx.RegisterModuleType("android_app", android.ModuleFactoryAdaptor(AndroidAppFactory)) @@ -222,13 +221,13 @@ func run(t *testing.T, ctx *android.TestContext, config android.Config) { android.FailIfErrored(t, errs) } -func testJava(t *testing.T, bp string) *android.TestContext { +func testJava(t *testing.T, bp string) (*android.TestContext, android.Config) { t.Helper() config := testConfig(nil) - ctx := testContext(config, bp, nil) + ctx := testContext(bp, nil) run(t, ctx, config) - return ctx + return ctx, config } func moduleToPath(name string) string { @@ -243,7 +242,7 @@ func moduleToPath(name string) string { } func TestSimple(t *testing.T) { - ctx := testJava(t, ` + ctx, _ := testJava(t, ` java_library { name: "foo", srcs: ["a.java"], @@ -287,7 +286,7 @@ func TestSimple(t *testing.T) { } func TestSdkVersion(t *testing.T) { - ctx := testJava(t, ` + ctx, _ := testJava(t, ` java_library { name: "foo", srcs: ["a.java"], @@ -313,7 +312,7 @@ func TestSdkVersion(t *testing.T) { } func TestArchSpecific(t *testing.T) { - ctx := testJava(t, ` + ctx, _ := testJava(t, ` java_library { name: "foo", srcs: ["a.java"], @@ -332,7 +331,7 @@ func TestArchSpecific(t *testing.T) { } func TestBinary(t *testing.T) { - ctx := testJava(t, ` + ctx, _ := testJava(t, ` java_library_host { name: "foo", srcs: ["a.java"], @@ -361,7 +360,7 @@ func TestBinary(t *testing.T) { } func TestPrebuilts(t *testing.T) { - ctx := testJava(t, ` + ctx, _ := testJava(t, ` java_library { name: "foo", srcs: ["a.java"], @@ -412,7 +411,7 @@ func TestPrebuilts(t *testing.T) { } func TestDefaults(t *testing.T) { - ctx := testJava(t, ` + ctx, _ := testJava(t, ` java_defaults { name: "defaults", srcs: ["a.java"], @@ -558,7 +557,7 @@ func TestResources(t *testing.T) { for _, test := range table { t.Run(test.name, func(t *testing.T) { - ctx := testJava(t, ` + ctx, _ := testJava(t, ` java_library { name: "foo", srcs: [ @@ -587,7 +586,7 @@ func TestResources(t *testing.T) { } func TestIncludeSrcs(t *testing.T) { - ctx := testJava(t, ` + ctx, _ := testJava(t, ` java_library { name: "foo", srcs: [ @@ -650,7 +649,7 @@ func TestIncludeSrcs(t *testing.T) { } func TestGeneratedSources(t *testing.T) { - ctx := testJava(t, ` + ctx, _ := testJava(t, ` java_library { name: "foo", srcs: [ @@ -683,7 +682,7 @@ func TestGeneratedSources(t *testing.T) { } func TestTurbine(t *testing.T) { - ctx := testJava(t, ` + ctx, _ := testJava(t, ` java_library { name: "foo", srcs: ["a.java"], @@ -732,7 +731,7 @@ func TestTurbine(t *testing.T) { } func TestSharding(t *testing.T) { - ctx := testJava(t, ` + ctx, _ := testJava(t, ` java_library { name: "bar", srcs: ["a.java","b.java","c.java"], @@ -750,7 +749,7 @@ func TestSharding(t *testing.T) { } func TestDroiddoc(t *testing.T) { - ctx := testJava(t, ` + ctx, _ := testJava(t, ` droiddoc_template { name: "droiddoc-templates-sdk", path: ".", @@ -793,7 +792,7 @@ func TestDroiddoc(t *testing.T) { } func TestJarGenrules(t *testing.T) { - ctx := testJava(t, ` + ctx, _ := testJava(t, ` java_library { name: "foo", srcs: ["a.java"], @@ -847,7 +846,7 @@ func TestJarGenrules(t *testing.T) { } func TestExcludeFileGroupInSrcs(t *testing.T) { - ctx := testJava(t, ` + ctx, _ := testJava(t, ` java_library { name: "foo", srcs: ["a.java", ":foo-srcs"], @@ -874,7 +873,7 @@ func TestExcludeFileGroupInSrcs(t *testing.T) { func TestJavaLibrary(t *testing.T) { config := testConfig(nil) - ctx := testContext(config, "", map[string][]byte{ + ctx := testContext("", map[string][]byte{ "libcore/Android.bp": []byte(` java_library { name: "core", @@ -886,7 +885,7 @@ func TestJavaLibrary(t *testing.T) { } func TestJavaSdkLibrary(t *testing.T) { - ctx := testJava(t, ` + ctx, _ := testJava(t, ` droiddoc_template { name: "droiddoc-templates-sdk", path: ".", @@ -1057,7 +1056,7 @@ func TestPatchModule(t *testing.T) { t.Run("Java language level 8", func(t *testing.T) { // Test default javac -source 1.8 -target 1.8 - ctx := testJava(t, bp) + ctx, _ := testJava(t, bp) checkPatchModuleFlag(t, ctx, "foo", "") checkPatchModuleFlag(t, ctx, "bar", "") @@ -1067,7 +1066,7 @@ func TestPatchModule(t *testing.T) { t.Run("Java language level 9", func(t *testing.T) { // Test again with javac -source 9 -target 9 config := testConfig(map[string]string{"EXPERIMENTAL_JAVA_LANGUAGE_LEVEL_9": "true"}) - ctx := testContext(config, bp, nil) + ctx := testContext(bp, nil) run(t, ctx, config) checkPatchModuleFlag(t, ctx, "foo", "") diff --git a/java/kotlin_test.go b/java/kotlin_test.go index e0eb0c06d..5c6d45f45 100644 --- a/java/kotlin_test.go +++ b/java/kotlin_test.go @@ -22,7 +22,7 @@ import ( ) func TestKotlin(t *testing.T) { - ctx := testJava(t, ` + ctx, _ := testJava(t, ` java_library { name: "foo", srcs: ["a.java", "b.kt"], @@ -84,7 +84,7 @@ func TestKotlin(t *testing.T) { } func TestKapt(t *testing.T) { - ctx := testJava(t, ` + ctx, _ := testJava(t, ` java_library { name: "foo", srcs: ["a.java", "b.kt"], diff --git a/java/plugin_test.go b/java/plugin_test.go index d1aef2c19..c7913d3db 100644 --- a/java/plugin_test.go +++ b/java/plugin_test.go @@ -20,7 +20,7 @@ import ( ) func TestNoPlugin(t *testing.T) { - ctx := testJava(t, ` + ctx, _ := testJava(t, ` java_library { name: "foo", srcs: ["a.java"], @@ -44,7 +44,7 @@ func TestNoPlugin(t *testing.T) { } func TestPlugin(t *testing.T) { - ctx := testJava(t, ` + ctx, _ := testJava(t, ` java_library { name: "foo", srcs: ["a.java"], @@ -83,7 +83,7 @@ func TestPlugin(t *testing.T) { } func TestPluginGeneratesApi(t *testing.T) { - ctx := testJava(t, ` + ctx, _ := testJava(t, ` java_library { name: "foo", srcs: ["a.java"], diff --git a/java/sdk_test.go b/java/sdk_test.go index f82a4fba9..6be17eb88 100644 --- a/java/sdk_test.go +++ b/java/sdk_test.go @@ -282,7 +282,7 @@ func TestClasspath(t *testing.T) { if testcase.pdk { config.TestProductVariables.Pdk = proptools.BoolPtr(true) } - ctx := testContext(config, bp, nil) + ctx := testContext(bp, nil) run(t, ctx, config) checkClasspath(t, ctx) @@ -309,7 +309,7 @@ func TestClasspath(t *testing.T) { if testcase.pdk { config.TestProductVariables.Pdk = proptools.BoolPtr(true) } - ctx := testContext(config, bp, nil) + ctx := testContext(bp, nil) run(t, ctx, config) javac := ctx.ModuleForTests("foo", variant).Rule("javac") @@ -335,7 +335,7 @@ func TestClasspath(t *testing.T) { if testcase.pdk { config.TestProductVariables.Pdk = proptools.BoolPtr(true) } - ctx := testContext(config, bp, nil) + ctx := testContext(bp, nil) run(t, ctx, config) checkClasspath(t, ctx)