diff options
| author | Colin Cross <ccross@android.com> | 2017-09-15 19:44:24 -0700 |
|---|---|---|
| committer | Colin Cross <ccross@android.com> | 2017-09-20 13:20:45 -0700 |
| commit | 2acdae88531f9f4b297c488ffbbc1b7419587f9f (patch) | |
| tree | ec19d506743a04f209ea6f5c1c6d20ea6b56ab3f /java/java_test.go | |
| parent | 4c428dfb283a8339e0c6e9c8225851f88639c21d (diff) | |
Fix java sdk tests
Fix the java module sdk tests, and expand them to cover testing
all classpaths including for the host.
Test: java_test.go
Change-Id: I71be13cc5545f5c4d5b377c4c8de3dccbb09abf9
Diffstat (limited to 'java/java_test.go')
| -rw-r--r-- | java/java_test.go | 220 |
1 files changed, 144 insertions, 76 deletions
diff --git a/java/java_test.go b/java/java_test.go index 4a6baa9ef..040adb440 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -56,8 +56,10 @@ func testJava(t *testing.T, bp string) *android.TestContext { ctx := android.NewTestArchContext() ctx.RegisterModuleType("android_app", android.ModuleFactoryAdaptor(AndroidAppFactory)) ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(LibraryFactory)) + ctx.RegisterModuleType("java_library_host", android.ModuleFactoryAdaptor(LibraryHostFactory)) ctx.RegisterModuleType("java_import", android.ModuleFactoryAdaptor(ImportFactory)) ctx.RegisterModuleType("java_defaults", android.ModuleFactoryAdaptor(defaultsFactory)) + ctx.RegisterModuleType("android_prebuilt_sdk", android.ModuleFactoryAdaptor(SdkPrebuiltFactory)) ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators) ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators) ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) @@ -69,7 +71,9 @@ func testJava(t *testing.T, bp string) *android.TestContext { "framework", "ext", "okhttp", - "sdk_v14", + "android_stubs_current", + "android_system_stubs_current", + "android_test_stubs_current", } for _, extra := range extraModules { @@ -82,13 +86,21 @@ func testJava(t *testing.T, bp string) *android.TestContext { `, extra) } + bp += ` + android_prebuilt_sdk { + name: "sdk_v14", + jars: ["sdk_v14.jar"], + } + ` + ctx.MockFileSystem(map[string][]byte{ - "Android.bp": []byte(bp), - "a.java": nil, - "b.java": nil, - "c.java": nil, - "a.jar": nil, - "b.jar": nil, + "Android.bp": []byte(bp), + "a.java": nil, + "b.java": nil, + "c.java": nil, + "a.jar": nil, + "b.jar": nil, + "sdk_v14.jar": nil, }) _, errs := ctx.ParseBlueprintsFiles("Android.bp") @@ -99,6 +111,17 @@ func testJava(t *testing.T, bp string) *android.TestContext { return ctx } +func moduleToPath(name string) string { + switch { + case name == `""`: + return name + case strings.HasPrefix(name, "sdk_v"): + return name + ".jar" + default: + return filepath.Join(buildDir, ".intermediates", name, "android_common", "classes-desugar.jar") + } +} + func TestSimple(t *testing.T) { ctx := testJava(t, ` java_library { @@ -142,85 +165,130 @@ func TestSimple(t *testing.T) { } } -func TestSdk(t *testing.T) { - t.Skip("not working yet") - - ctx := testJava(t, ` - java_library { - name: "foo1", - srcs: ["a.java"], - } - - java_library { - name: "foo2", - srcs: ["a.java"], - sdk_version: "", - } - - java_library { - name: "foo3", - srcs: ["a.java"], - sdk_version: "14", - } - - java_library { - name: "foo4", - srcs: ["a.java"], - sdk_version: "current", - } - - java_library { - name: "foo5", - srcs: ["a.java"], - sdk_version: "system_current", - } - - java_library { - name: "foo6", - srcs: ["a.java"], - sdk_version: "test_current", - } - `) +var classpathTestcases = []struct { + name string + host android.OsClass + properties string + bootclasspath []string + classpath []string +}{ + { + name: "default", + bootclasspath: []string{"core-oj", "core-libart"}, + classpath: []string{"ext", "framework", "okhttp"}, + }, + { + name: "blank sdk version", + properties: `sdk_version: "",`, + bootclasspath: []string{"core-oj", "core-libart"}, + classpath: []string{"ext", "framework", "okhttp"}, + }, + { + + name: "sdk v14", + properties: `sdk_version: "14",`, + bootclasspath: []string{"sdk_v14"}, + classpath: []string{}, + }, + { + + name: "current", + properties: `sdk_version: "current",`, + bootclasspath: []string{"android_stubs_current"}, + classpath: []string{}, + }, + { + + name: "system_current", + properties: `sdk_version: "system_current",`, + bootclasspath: []string{"android_system_stubs_current"}, + classpath: []string{}, + }, + { + + name: "test_current", + properties: `sdk_version: "test_current",`, + bootclasspath: []string{"android_test_stubs_current"}, + classpath: []string{}, + }, + { + + name: "nostdlib", + properties: `no_standard_libs: true`, + bootclasspath: []string{`""`}, + classpath: []string{}, + }, + { + + name: "host default", + host: android.Host, + properties: ``, + classpath: []string{}, + }, + { + name: "host nostdlib", + host: android.Host, + properties: `no_standard_libs: true`, + classpath: []string{}, + }, +} - type depType int - const ( - staticLib = iota - classpathLib - bootclasspathLib - ) +func TestClasspath(t *testing.T) { + for _, testcase := range classpathTestcases { + t.Run(testcase.name, func(t *testing.T) { + hostExtra := "" + if testcase.host == android.Host { + hostExtra = "_host" + } + ctx := testJava(t, ` + java_library`+hostExtra+` { + name: "foo", + srcs: ["a.java"], + `+testcase.properties+` + } + `) + + convertModulesToPaths := func(cp []string) []string { + ret := make([]string, len(cp)) + for i, e := range cp { + ret[i] = moduleToPath(e) + } + return ret + } - check := func(module string, depType depType, deps ...string) { - for i := range deps { - deps[i] = filepath.Join(buildDir, ".intermediates", deps[i], "classes-desugar.jar") - } - dep := strings.Join(deps, ":") + bootclasspath := convertModulesToPaths(testcase.bootclasspath) + classpath := convertModulesToPaths(testcase.classpath) - javac := ctx.ModuleForTests(module, "").Rule("javac") + variant := "android_common" + if testcase.host == android.Host { + variant = android.BuildOs.String() + "_common" + } + javac := ctx.ModuleForTests("foo", variant).Rule("javac") - if depType == bootclasspathLib { got := strings.TrimPrefix(javac.Args["bootClasspath"], "-bootclasspath ") - if got != dep { - t.Errorf("module %q bootclasspath %q != %q", module, got, dep) + bc := strings.Join(bootclasspath, ":") + if got != bc { + t.Errorf("bootclasspath expected %q != got %q", bc, got) } - } else if depType == classpathLib { - got := strings.TrimPrefix(javac.Args["classpath"], "-classpath ") - if got != dep { - t.Errorf("module %q classpath %q != %q", module, got, dep) + + got = strings.TrimPrefix(javac.Args["classpath"], "-classpath ") + c := strings.Join(classpath, ":") + if got != c { + t.Errorf("classpath expected %q != got %q", c, got) } - } - if !reflect.DeepEqual(javac.Implicits.Strings(), deps) { - t.Errorf("module %q implicits %q != %q", module, javac.Implicits.Strings(), deps) - } + var deps []string + if len(bootclasspath) > 0 && bootclasspath[0] != `""` { + deps = append(deps, bootclasspath...) + } + deps = append(deps, classpath...) + + if !reflect.DeepEqual(javac.Implicits.Strings(), deps) { + t.Errorf("implicits expected %q != got %q", deps, javac.Implicits.Strings()) + } + }) } - check("foo1", bootclasspathLib, "core-oj", "core-libart") - check("foo2", bootclasspathLib, "core-oj", "core-libart") - // TODO(ccross): these need the arch mutator to run to work correctly - //check("foo3", bootclasspathLib, "sdk_v14") - //check("foo4", bootclasspathLib, "android_stubs_current") - //check("foo5", bootclasspathLib, "android_system_stubs_current") - //check("foo6", bootclasspathLib, "android_test_stubs_current") } func TestPrebuilts(t *testing.T) { |
