Refactor bp2build tests
Moves to specifying attributes as a map, such at it is possible to add
additional attributes conditionally. This is in particular useful once
supporting the `enabled` property which will add
`target_compatible_with`
Test: go test soong tests
Change-Id: Iade8eed1ce3acb1d1712a9ee3119d9ae59675624
diff --git a/bp2build/python_binary_conversion_test.go b/bp2build/python_binary_conversion_test.go
index 5b4829e..01b6aa2 100644
--- a/bp2build/python_binary_conversion_test.go
+++ b/bp2build/python_binary_conversion_test.go
@@ -7,7 +7,8 @@
"android/soong/python"
)
-func runBp2BuildTestCaseWithLibs(t *testing.T, tc bp2buildTestCase) {
+func runBp2BuildTestCaseWithPythonLibraries(t *testing.T, tc bp2buildTestCase) {
+ t.Helper()
runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
ctx.RegisterModuleType("python_library", python.PythonLibraryFactory)
ctx.RegisterModuleType("python_library_host", python.PythonLibraryHostFactory)
@@ -15,7 +16,7 @@
}
func TestPythonBinaryHostSimple(t *testing.T) {
- runBp2BuildTestCaseWithLibs(t, bp2buildTestCase{
+ runBp2BuildTestCaseWithPythonLibraries(t, bp2buildTestCase{
description: "simple python_binary_host converts to a native py_binary",
moduleTypeUnderTest: "python_binary_host",
moduleTypeUnderTestFactory: python.PythonBinaryHostFactory,
@@ -41,17 +42,17 @@
srcs: ["b/e.py"],
bazel_module: { bp2build_available: true },
}`,
- expectedBazelTargets: []string{`py_binary(
- name = "foo",
- data = ["files/data.txt"],
- deps = [":bar"],
- main = "a.py",
- srcs = [
+ expectedBazelTargets: []string{
+ makeBazelTarget("py_binary", "foo", attrNameToString{
+ "data": `["files/data.txt"]`,
+ "deps": `[":bar"]`,
+ "main": `"a.py"`,
+ "srcs": `[
"a.py",
"b/c.py",
"b/d.py",
- ],
-)`,
+ ]`,
+ }),
},
})
}
@@ -77,11 +78,11 @@
bazel_module: { bp2build_available: true },
}
`,
- expectedBazelTargets: []string{`py_binary(
- name = "foo",
- python_version = "PY2",
- srcs = ["a.py"],
-)`,
+ expectedBazelTargets: []string{
+ makeBazelTarget("py_binary", "foo", attrNameToString{
+ "python_version": `"PY2"`,
+ "srcs": `["a.py"]`,
+ }),
},
})
}
@@ -109,10 +110,9 @@
`,
expectedBazelTargets: []string{
// python_version is PY3 by default.
- `py_binary(
- name = "foo",
- srcs = ["a.py"],
-)`,
+ makeBazelTarget("py_binary", "foo", attrNameToString{
+ "srcs": `["a.py"]`,
+ }),
},
})
}
@@ -139,14 +139,13 @@
},
}`,
expectedBazelTargets: []string{
- `py_binary(
- name = "foo-arm",
- srcs = select({
+ makeBazelTarget("py_binary", "foo-arm", attrNameToString{
+ "srcs": `select({
"//build/bazel/platforms/arch:arm": ["arm.py"],
"//build/bazel/platforms/arch:x86": ["x86.py"],
"//conditions:default": [],
- }),
-)`,
+ })`,
+ }),
},
})
}