Add test for java_sdk_library dist properties

Add tests that cover the owner, core_lib and dist_stem properties.

Bug: 186723288
Test: TestJavaSdkLibraryDist
Change-Id: I4c2ae2a23dcd9a668c46ed5cc23b1d7dcfae798a
Merged-In: I4c2ae2a23dcd9a668c46ed5cc23b1d7dcfae798a
(cherry picked from commit 30c491b885c3dbd9094146b1e8054f3d62e2f55a)
This commit is contained in:
Colin Cross 2021-06-01 13:39:09 -07:00
parent 76069a30a4
commit 3b538082fe
1 changed files with 79 additions and 0 deletions

View File

@ -838,3 +838,82 @@ func TestJavaSdkLibraryEnforce(t *testing.T) {
enforceJavaSdkLibraryCheck: true,
}, "")
}
func TestJavaSdkLibraryDist(t *testing.T) {
result := android.GroupFixturePreparers(
PrepareForTestWithJavaBuildComponents,
PrepareForTestWithJavaDefaultModules,
PrepareForTestWithJavaSdkLibraryFiles,
).RunTestWithBp(t, `
java_sdk_library {
name: "sdklib_no_owner",
unsafe_ignore_missing_latest_api: true,
srcs: ["foo.java"],
}
java_sdk_library {
name: "sdklib_owner_foo",
unsafe_ignore_missing_latest_api: true,
srcs: ["foo.java"],
owner: "foo",
}
java_sdk_library {
name: "sdklib_stem_foo",
unsafe_ignore_missing_latest_api: true,
srcs: ["foo.java"],
dist_stem: "foo",
}
java_sdk_library {
name: "sdklib_core_lib",
unsafe_ignore_missing_latest_api: true,
srcs: ["foo.java"],
core_lib: true,
}
`)
type testCase struct {
module string
distDir string
distStem string
}
testCases := []testCase{
{
module: "sdklib_no_owner",
distDir: "apistubs/android/public",
distStem: "sdklib_no_owner.jar",
},
{
module: "sdklib_owner_foo",
distDir: "apistubs/foo/public",
distStem: "sdklib_owner_foo.jar",
},
{
module: "sdklib_stem_foo",
distDir: "apistubs/android/public",
distStem: "foo.jar",
},
{
module: "sdklib_core_lib",
distDir: "apistubs/core/public",
distStem: "sdklib_core_lib.jar",
},
}
for _, tt := range testCases {
t.Run(tt.module, func(t *testing.T) {
m := result.ModuleForTests(tt.module+".stubs", "android_common").Module().(*Library)
dists := m.Dists()
if len(dists) != 1 {
t.Fatalf("expected exactly 1 dist entry, got %d", len(dists))
}
if g, w := String(dists[0].Dir), tt.distDir; g != w {
t.Errorf("expected dist dir %q, got %q", w, g)
}
if g, w := String(dists[0].Dest), tt.distStem; g != w {
t.Errorf("expected dist stem %q, got %q", w, g)
}
})
}
}