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

@@ -7,27 +7,27 @@ import (
"android/soong/python"
)
func runBp2BuildTestCaseWithPythonLibraries(t *testing.T, tc bp2buildTestCase) {
func runBp2BuildTestCaseWithPythonLibraries(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
ctx.RegisterModuleType("python_library", python.PythonLibraryFactory)
ctx.RegisterModuleType("python_library_host", python.PythonLibraryHostFactory)
}, tc)
}
func TestPythonBinaryHostSimple(t *testing.T) {
runBp2BuildTestCaseWithPythonLibraries(t, bp2buildTestCase{
description: "simple python_binary_host converts to a native py_binary",
moduleTypeUnderTest: "python_binary_host",
moduleTypeUnderTestFactory: python.PythonBinaryHostFactory,
filesystem: map[string]string{
runBp2BuildTestCaseWithPythonLibraries(t, Bp2buildTestCase{
Description: "simple python_binary_host converts to a native py_binary",
ModuleTypeUnderTest: "python_binary_host",
ModuleTypeUnderTestFactory: python.PythonBinaryHostFactory,
Filesystem: map[string]string{
"a.py": "",
"b/c.py": "",
"b/d.py": "",
"b/e.py": "",
"files/data.txt": "",
},
blueprint: `python_binary_host {
Blueprint: `python_binary_host {
name: "foo",
main: "a.py",
srcs: ["**/*.py"],
@@ -41,8 +41,8 @@ func TestPythonBinaryHostSimple(t *testing.T) {
srcs: ["b/e.py"],
bazel_module: { bp2build_available: false },
}`,
expectedBazelTargets: []string{
makeBazelTarget("py_binary", "foo", attrNameToString{
ExpectedBazelTargets: []string{
makeBazelTarget("py_binary", "foo", AttrNameToString{
"data": `["files/data.txt"]`,
"deps": `[":bar"]`,
"main": `"a.py"`,
@@ -62,11 +62,11 @@ func TestPythonBinaryHostSimple(t *testing.T) {
}
func TestPythonBinaryHostPy2(t *testing.T) {
runBp2BuildTestCaseSimple(t, bp2buildTestCase{
description: "py2 python_binary_host",
moduleTypeUnderTest: "python_binary_host",
moduleTypeUnderTestFactory: python.PythonBinaryHostFactory,
blueprint: `python_binary_host {
runBp2BuildTestCaseSimple(t, Bp2buildTestCase{
Description: "py2 python_binary_host",
ModuleTypeUnderTest: "python_binary_host",
ModuleTypeUnderTestFactory: python.PythonBinaryHostFactory,
Blueprint: `python_binary_host {
name: "foo",
srcs: ["a.py"],
version: {
@@ -81,8 +81,8 @@ func TestPythonBinaryHostPy2(t *testing.T) {
bazel_module: { bp2build_available: true },
}
`,
expectedBazelTargets: []string{
makeBazelTarget("py_binary", "foo", attrNameToString{
ExpectedBazelTargets: []string{
makeBazelTarget("py_binary", "foo", AttrNameToString{
"python_version": `"PY2"`,
"imports": `["."]`,
"srcs": `["a.py"]`,
@@ -96,11 +96,11 @@ func TestPythonBinaryHostPy2(t *testing.T) {
}
func TestPythonBinaryHostPy3(t *testing.T) {
runBp2BuildTestCaseSimple(t, bp2buildTestCase{
description: "py3 python_binary_host",
moduleTypeUnderTest: "python_binary_host",
moduleTypeUnderTestFactory: python.PythonBinaryHostFactory,
blueprint: `python_binary_host {
runBp2BuildTestCaseSimple(t, Bp2buildTestCase{
Description: "py3 python_binary_host",
ModuleTypeUnderTest: "python_binary_host",
ModuleTypeUnderTestFactory: python.PythonBinaryHostFactory,
Blueprint: `python_binary_host {
name: "foo",
srcs: ["a.py"],
version: {
@@ -115,9 +115,9 @@ func TestPythonBinaryHostPy3(t *testing.T) {
bazel_module: { bp2build_available: true },
}
`,
expectedBazelTargets: []string{
ExpectedBazelTargets: []string{
// python_version is PY3 by default.
makeBazelTarget("py_binary", "foo", attrNameToString{
makeBazelTarget("py_binary", "foo", AttrNameToString{
"imports": `["."]`,
"srcs": `["a.py"]`,
"target_compatible_with": `select({
@@ -130,15 +130,15 @@ func TestPythonBinaryHostPy3(t *testing.T) {
}
func TestPythonBinaryHostArchVariance(t *testing.T) {
runBp2BuildTestCaseSimple(t, bp2buildTestCase{
description: "test arch variants",
moduleTypeUnderTest: "python_binary_host",
moduleTypeUnderTestFactory: python.PythonBinaryHostFactory,
filesystem: map[string]string{
runBp2BuildTestCaseSimple(t, Bp2buildTestCase{
Description: "test arch variants",
ModuleTypeUnderTest: "python_binary_host",
ModuleTypeUnderTestFactory: python.PythonBinaryHostFactory,
Filesystem: map[string]string{
"dir/arm.py": "",
"dir/x86.py": "",
},
blueprint: `python_binary_host {
Blueprint: `python_binary_host {
name: "foo-arm",
arch: {
arm: {
@@ -149,8 +149,8 @@ func TestPythonBinaryHostArchVariance(t *testing.T) {
},
},
}`,
expectedBazelTargets: []string{
makeBazelTarget("py_binary", "foo-arm", attrNameToString{
ExpectedBazelTargets: []string{
makeBazelTarget("py_binary", "foo-arm", AttrNameToString{
"imports": `["."]`,
"srcs": `select({
"//build/bazel/platforms/arch:arm": ["arm.py"],