platform_build_soong/bp2build/python_binary_conversion_test.go
Liz Kammer e4982e8828 Mark test helpers as helpers.
This enables identifying the correct location of test failures.

from godocs:
Helper marks the calling function as a test helper function.
When printing file and line information, that function will be skipped.
Helper may be called simultaneously from multiple goroutines.

Test: go test bp2build tests
Change-Id: I52430e541494c78f5222c11510a4d273fe205a06
2021-05-25 14:41:43 +00:00

110 lines
2.6 KiB
Go

package bp2build
import (
"testing"
"android/soong/android"
"android/soong/python"
)
func runPythonTestCase(t *testing.T, tc bp2buildTestCase) {
t.Helper()
runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc)
}
func TestPythonBinaryHostSimple(t *testing.T) {
runPythonTestCase(t, bp2buildTestCase{
description: "simple python_binary_host converts to a native py_binary",
moduleTypeUnderTest: "python_binary_host",
moduleTypeUnderTestFactory: python.PythonBinaryHostFactory,
moduleTypeUnderTestBp2BuildMutator: python.PythonBinaryBp2Build,
filesystem: map[string]string{
"a.py": "",
"b/c.py": "",
"b/d.py": "",
"b/e.py": "",
"files/data.txt": "",
},
blueprint: `python_binary_host {
name: "foo",
main: "a.py",
srcs: ["**/*.py"],
exclude_srcs: ["b/e.py"],
data: ["files/data.txt",],
bazel_module: { bp2build_available: true },
}
`,
expectedBazelTargets: []string{`py_binary(
name = "foo",
data = ["files/data.txt"],
main = "a.py",
srcs = [
"a.py",
"b/c.py",
"b/d.py",
],
)`,
},
})
}
func TestPythonBinaryHostPy2(t *testing.T) {
runPythonTestCase(t, bp2buildTestCase{
description: "py2 python_binary_host",
moduleTypeUnderTest: "python_binary_host",
moduleTypeUnderTestFactory: python.PythonBinaryHostFactory,
moduleTypeUnderTestBp2BuildMutator: python.PythonBinaryBp2Build,
blueprint: `python_binary_host {
name: "foo",
srcs: ["a.py"],
version: {
py2: {
enabled: true,
},
py3: {
enabled: false,
},
},
bazel_module: { bp2build_available: true },
}
`,
expectedBazelTargets: []string{`py_binary(
name = "foo",
python_version = "PY2",
srcs = ["a.py"],
)`,
},
})
}
func TestPythonBinaryHostPy3(t *testing.T) {
runPythonTestCase(t, bp2buildTestCase{
description: "py3 python_binary_host",
moduleTypeUnderTest: "python_binary_host",
moduleTypeUnderTestFactory: python.PythonBinaryHostFactory,
moduleTypeUnderTestBp2BuildMutator: python.PythonBinaryBp2Build,
blueprint: `python_binary_host {
name: "foo",
srcs: ["a.py"],
version: {
py2: {
enabled: false,
},
py3: {
enabled: true,
},
},
bazel_module: { bp2build_available: true },
}
`,
expectedBazelTargets: []string{
// python_version is PY3 by default.
`py_binary(
name = "foo",
srcs = ["a.py"],
)`,
},
})
}