export common bp2build testing functions

bp2buildTestCase
attrNameToString
runBp2BuildTestCase
makeBazelTargetNoRestrictions

The testing framework defined in the bp2build package can only be used
from within the package because many common testing functions are
private to the package. This prevents modules defined in Soong
plugins (e.g. system/tools/aidl/build) from testing bp2build conversions.

Test: go test ./bp2build
Change-Id: Ia867081327c5181d04687b13c4550e68e6a11f86
This commit is contained in:
Sam Delmerico
2022-06-21 19:28:33 +00:00
committed by Liz Kammer
parent 88e7512572
commit 3177a6e1e0
31 changed files with 1990 additions and 1986 deletions

View File

@@ -21,17 +21,17 @@ import (
"android/soong/java"
)
func runJavaLibraryHostTestCase(t *testing.T, tc bp2buildTestCase) {
func runJavaLibraryHostTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
(&tc).moduleTypeUnderTest = "java_library_host"
(&tc).moduleTypeUnderTestFactory = java.LibraryHostFactory
runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc)
(&tc).ModuleTypeUnderTest = "java_library_host"
(&tc).ModuleTypeUnderTestFactory = java.LibraryHostFactory
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc)
}
func TestJavaLibraryHost(t *testing.T) {
runJavaLibraryHostTestCase(t, bp2buildTestCase{
description: "java_library_host with srcs, exclude_srcs and libs",
blueprint: `java_library_host {
runJavaLibraryHostTestCase(t, Bp2buildTestCase{
Description: "java_library_host with srcs, exclude_srcs and libs",
Blueprint: `java_library_host {
name: "java-lib-host-1",
srcs: ["a.java", "b.java"],
exclude_srcs: ["b.java"],
@@ -45,8 +45,8 @@ java_library_host {
bazel_module: { bp2build_available: true },
java_version: "9",
}`,
expectedBazelTargets: []string{
makeBazelTarget("java_library", "java-lib-host-1", attrNameToString{
ExpectedBazelTargets: []string{
makeBazelTarget("java_library", "java-lib-host-1", AttrNameToString{
"srcs": `["a.java"]`,
"deps": `[":java-lib-host-2"]`,
"target_compatible_with": `select({
@@ -54,7 +54,7 @@ java_library_host {
"//conditions:default": [],
})`,
}),
makeBazelTarget("java_library", "java-lib-host-2", attrNameToString{
makeBazelTarget("java_library", "java-lib-host-2", AttrNameToString{
"javacopts": `["-source 1.9 -target 1.9"]`,
"srcs": `["c.java"]`,
"target_compatible_with": `select({