From 0ed42d3c9d208a6f06c3351fae3ffcf1e52ab4be Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Sat, 13 Mar 2021 02:19:32 +0000 Subject: [PATCH] Clean up testApp and testAppConfig Previously, testAppConfig added some extra files to the mock filesystem before passing them to testConfig. However, those files are only needed for TestApp so this converts TestApp to use test fixtures and populates the mock filesystem with the extra files. Without those extra files testApp and testAppConfig are equivalent to testJava and testConfig respectively. Bug: 181070625 Test: m nothing Change-Id: I1d8a51223adde5b656948725bc4bc91040533625 --- java/app_test.go | 75 ++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 40 deletions(-) diff --git a/java/app_test.go b/java/app_test.go index 78e1a57a9..3b37473ba 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -28,70 +28,68 @@ import ( "android/soong/cc" ) -var ( - resourceFiles = []string{ +// testAppConfig is a legacy way of creating a test Config for testing java app modules. +// +// See testJava for an explanation as to how to stop using this deprecated method. +// +// deprecated +func testAppConfig(env map[string]string, bp string, fs map[string][]byte) android.Config { + return testConfig(env, bp, fs) +} + +// testApp runs tests using the javaFixtureFactory +// +// 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) + return result.TestContext +} + +func TestApp(t *testing.T) { + resourceFiles := []string{ "res/layout/layout.xml", "res/values/strings.xml", "res/values-en-rUS/strings.xml", } - compiledResourceFiles = []string{ + compiledResourceFiles := []string{ "aapt2/res/layout_layout.xml.flat", "aapt2/res/values_strings.arsc.flat", "aapt2/res/values-en-rUS_strings.arsc.flat", } -) -func testAppConfig(env map[string]string, bp string, fs map[string][]byte) android.Config { - appFS := map[string][]byte{} - for k, v := range fs { - appFS[k] = v - } - - for _, file := range resourceFiles { - appFS[file] = nil - } - - return testConfig(env, bp, appFS) -} - -func testApp(t *testing.T, bp string) *android.TestContext { - config := testAppConfig(nil, bp, nil) - - ctx := testContext(config) - - run(t, ctx, config) - - return ctx -} - -func TestApp(t *testing.T) { for _, moduleType := range []string{"android_app", "android_library"} { t.Run(moduleType, func(t *testing.T) { - ctx := testApp(t, moduleType+` { + result := javaFixtureFactory.Extend( + android.FixtureModifyMockFS(func(fs android.MockFS) { + for _, file := range resourceFiles { + fs[file] = nil + } + }), + ).RunTestWithBp(t, moduleType+` { name: "foo", srcs: ["a.java"], sdk_version: "current" } `) - foo := ctx.ModuleForTests("foo", "android_common") + foo := result.ModuleForTests("foo", "android_common") var expectedLinkImplicits []string manifestFixer := foo.Output("manifest_fixer/AndroidManifest.xml") expectedLinkImplicits = append(expectedLinkImplicits, manifestFixer.Output.String()) - frameworkRes := ctx.ModuleForTests("framework-res", "android_common") + frameworkRes := result.ModuleForTests("framework-res", "android_common") expectedLinkImplicits = append(expectedLinkImplicits, frameworkRes.Output("package-res.apk").Output.String()) // Test the mapping from input files to compiled output file names compile := foo.Output(compiledResourceFiles[0]) - if !reflect.DeepEqual(resourceFiles, compile.Inputs.Strings()) { - t.Errorf("expected aapt2 compile inputs expected:\n %#v\n got:\n %#v", - resourceFiles, compile.Inputs.Strings()) - } + android.AssertDeepEquals(t, "aapt2 compile inputs", resourceFiles, compile.Inputs.Strings()) compiledResourceOutputs := compile.Outputs.Strings() sort.Strings(compiledResourceOutputs) @@ -102,11 +100,8 @@ func TestApp(t *testing.T) { expectedLinkImplicits = append(expectedLinkImplicits, list.Output.String()) // Check that the link rule uses - res := ctx.ModuleForTests("foo", "android_common").Output("package-res.apk") - if !reflect.DeepEqual(expectedLinkImplicits, res.Implicits.Strings()) { - t.Errorf("expected aapt2 link implicits expected:\n %#v\n got:\n %#v", - expectedLinkImplicits, res.Implicits.Strings()) - } + res := result.ModuleForTests("foo", "android_common").Output("package-res.apk") + android.AssertDeepEquals(t, "aapt2 link implicits", expectedLinkImplicits, res.Implicits.Strings()) }) } }