From 3b538082fe8e6e0e68f748dbb0b3e900ca282b4e Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 1 Jun 2021 13:39:09 -0700 Subject: [PATCH] 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) --- java/sdk_library_test.go | 79 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/java/sdk_library_test.go b/java/sdk_library_test.go index bec535779..84b5a242a 100644 --- a/java/sdk_library_test.go +++ b/java/sdk_library_test.go @@ -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) + } + }) + } +}