diff options
Diffstat (limited to 'java/java_test.go')
| -rw-r--r-- | java/java_test.go | 90 |
1 files changed, 60 insertions, 30 deletions
diff --git a/java/java_test.go b/java/java_test.go index 96ecdb689..17f3a218a 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)) @@ -193,6 +192,7 @@ func testContext(config android.Config, bp string, "bar-doc/a.java": nil, "bar-doc/b.java": nil, "bar-doc/IFoo.aidl": nil, + "bar-doc/IBar.aidl": nil, "bar-doc/known_oj_tags.txt": nil, "external/doclava/templates-sdk": nil, @@ -222,13 +222,36 @@ 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 testJavaError(t *testing.T, pattern string, bp string) { t.Helper() config := testConfig(nil) - ctx := testContext(config, bp, nil) + ctx := testContext(bp, nil) + + pathCtx := android.PathContextForTesting(config, nil) + setDexpreoptTestGlobalConfig(config, dexpreopt.GlobalConfigForTests(pathCtx)) + + ctx.Register() + _, errs := ctx.ParseBlueprintsFiles("Android.bp") + if len(errs) > 0 { + android.FailIfNoMatchingErrors(t, pattern, errs) + return + } + _, errs = ctx.PrepareBuildActions(config) + if len(errs) > 0 { + android.FailIfNoMatchingErrors(t, pattern, errs) + return + } + + t.Fatalf("missing expected error %q (0 errors are returned)", pattern) +} + +func testJava(t *testing.T, bp string) (*android.TestContext, android.Config) { + t.Helper() + config := testConfig(nil) + ctx := testContext(bp, nil) run(t, ctx, config) - return ctx + return ctx, config } func moduleToPath(name string) string { @@ -243,7 +266,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 +310,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 +336,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 +355,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 +384,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 +435,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 +581,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 +610,7 @@ func TestResources(t *testing.T) { } func TestIncludeSrcs(t *testing.T) { - ctx := testJava(t, ` + ctx, _ := testJava(t, ` java_library { name: "foo", srcs: [ @@ -650,7 +673,7 @@ func TestIncludeSrcs(t *testing.T) { } func TestGeneratedSources(t *testing.T) { - ctx := testJava(t, ` + ctx, _ := testJava(t, ` java_library { name: "foo", srcs: [ @@ -683,7 +706,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 +755,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,16 +773,22 @@ func TestSharding(t *testing.T) { } func TestDroiddoc(t *testing.T) { - ctx := testJava(t, ` + ctx, _ := testJava(t, ` droiddoc_template { name: "droiddoc-templates-sdk", path: ".", } + filegroup { + name: "bar-doc-aidl-srcs", + srcs: ["bar-doc/IBar.aidl"], + path: "bar-doc", + } droiddoc { name: "bar-doc", srcs: [ "bar-doc/*.java", "bar-doc/IFoo.aidl", + ":bar-doc-aidl-srcs", ], exclude_srcs: [ "bar-doc/b.java" @@ -777,23 +806,24 @@ func TestDroiddoc(t *testing.T) { } `) - stubsJar := filepath.Join(buildDir, ".intermediates", "bar-doc", "android_common", "bar-doc-stubs.srcjar") - barDoc := ctx.ModuleForTests("bar-doc", "android_common").Output("bar-doc-stubs.srcjar") - if stubsJar != barDoc.Output.String() { - t.Errorf("expected stubs Jar [%q], got %q", stubsJar, barDoc.Output.String()) - } inputs := ctx.ModuleForTests("bar-doc", "android_common").Rule("javadoc").Inputs var javaSrcs []string for _, i := range inputs { javaSrcs = append(javaSrcs, i.Base()) } - if len(javaSrcs) != 2 || javaSrcs[0] != "a.java" || javaSrcs[1] != "IFoo.java" { - t.Errorf("inputs of bar-doc must be []string{\"a.java\", \"IFoo.java\", but was %#v.", javaSrcs) + if len(javaSrcs) != 3 || javaSrcs[0] != "a.java" || javaSrcs[1] != "IFoo.java" || javaSrcs[2] != "IBar.java" { + t.Errorf("inputs of bar-doc must be []string{\"a.java\", \"IFoo.java\", \"IBar.java\", but was %#v.", javaSrcs) + } + + aidlRule := ctx.ModuleForTests("bar-doc", "android_common").Output(inputs[2].String()) + aidlFlags := aidlRule.Args["aidlFlags"] + if !strings.Contains(aidlFlags, "-Ibar-doc") { + t.Errorf("aidl flags for IBar.aidl should contain \"-Ibar-doc\", but was %q", aidlFlags) } } func TestJarGenrules(t *testing.T) { - ctx := testJava(t, ` + ctx, _ := testJava(t, ` java_library { name: "foo", srcs: ["a.java"], @@ -847,7 +877,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 +904,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 +916,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 +1087,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 +1097,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", "") |
