aboutsummaryrefslogtreecommitdiff
path: root/bp2build
diff options
context:
space:
mode:
authorJingwen Chen <jingwen@google.com>2021-01-26 21:57:27 -0500
committerJingwen Chen <jingwen@google.com>2021-01-26 21:57:27 -0500
commita42d6417b3cdef35b6c2f9e1aa9f6e8ab51c1499 (patch)
tree5125dbaf7f9f265bb83e82bebab972ae0b72235c /bp2build
parent801a6695664a0ff167cc306ac612f79d893f04e5 (diff)
downloadsoong-a42d6417b3cdef35b6c2f9e1aa9f6e8ab51c1499.tar.gz
Make bp2buildMutators registration local to TestContext.
The previous implementation relied on the implicit registration of Bp2Build mutators, resulting in test non-hermeticity. Refactor bp2build tests to explicitly specify the bp2build mutators under test. Test: Soong tests Test: TH Change-Id: I9b9674bad1ea533b3bd31b07077a9e02c99b4c1d
Diffstat (limited to 'bp2build')
-rw-r--r--bp2build/build_conversion_test.go61
1 files changed, 35 insertions, 26 deletions
diff --git a/bp2build/build_conversion_test.go b/bp2build/build_conversion_test.go
index 367e13f75..73ca92fa1 100644
--- a/bp2build/build_conversion_test.go
+++ b/bp2build/build_conversion_test.go
@@ -270,16 +270,18 @@ func TestGenerateBazelTargetModules(t *testing.T) {
func TestModuleTypeBp2Build(t *testing.T) {
testCases := []struct {
- moduleTypeUnderTest string
- moduleTypeUnderTestFactory android.ModuleFactory
- bp string
- expectedBazelTarget string
- description string
+ moduleTypeUnderTest string
+ moduleTypeUnderTestFactory android.ModuleFactory
+ moduleTypeUnderTestBp2BuildMutator func(android.TopDownMutatorContext)
+ bp string
+ expectedBazelTarget string
+ description string
}{
{
- description: "filegroup with no srcs",
- moduleTypeUnderTest: "filegroup",
- moduleTypeUnderTestFactory: android.FileGroupFactory,
+ description: "filegroup with no srcs",
+ moduleTypeUnderTest: "filegroup",
+ moduleTypeUnderTestFactory: android.FileGroupFactory,
+ moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build,
bp: `filegroup {
name: "foo",
srcs: [],
@@ -291,9 +293,10 @@ func TestModuleTypeBp2Build(t *testing.T) {
)`,
},
{
- description: "filegroup with srcs",
- moduleTypeUnderTest: "filegroup",
- moduleTypeUnderTestFactory: android.FileGroupFactory,
+ description: "filegroup with srcs",
+ moduleTypeUnderTest: "filegroup",
+ moduleTypeUnderTestFactory: android.FileGroupFactory,
+ moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build,
bp: `filegroup {
name: "foo",
srcs: ["a", "b"],
@@ -307,9 +310,10 @@ func TestModuleTypeBp2Build(t *testing.T) {
)`,
},
{
- description: "genrule with command line variable replacements",
- moduleTypeUnderTest: "genrule",
- moduleTypeUnderTestFactory: genrule.GenRuleFactory,
+ description: "genrule with command line variable replacements",
+ moduleTypeUnderTest: "genrule",
+ moduleTypeUnderTestFactory: genrule.GenRuleFactory,
+ moduleTypeUnderTestBp2BuildMutator: genrule.GenruleBp2Build,
bp: `genrule {
name: "foo",
out: ["foo.out"],
@@ -332,9 +336,10 @@ func TestModuleTypeBp2Build(t *testing.T) {
)`,
},
{
- description: "genrule using $(locations :label)",
- moduleTypeUnderTest: "genrule",
- moduleTypeUnderTestFactory: genrule.GenRuleFactory,
+ description: "genrule using $(locations :label)",
+ moduleTypeUnderTest: "genrule",
+ moduleTypeUnderTestFactory: genrule.GenRuleFactory,
+ moduleTypeUnderTestBp2BuildMutator: genrule.GenruleBp2Build,
bp: `genrule {
name: "foo",
out: ["foo.out"],
@@ -357,9 +362,10 @@ func TestModuleTypeBp2Build(t *testing.T) {
)`,
},
{
- description: "genrule using $(location) label should substitute first tool label automatically",
- moduleTypeUnderTest: "genrule",
- moduleTypeUnderTestFactory: genrule.GenRuleFactory,
+ description: "genrule using $(location) label should substitute first tool label automatically",
+ moduleTypeUnderTest: "genrule",
+ moduleTypeUnderTestFactory: genrule.GenRuleFactory,
+ moduleTypeUnderTestBp2BuildMutator: genrule.GenruleBp2Build,
bp: `genrule {
name: "foo",
out: ["foo.out"],
@@ -383,9 +389,10 @@ func TestModuleTypeBp2Build(t *testing.T) {
)`,
},
{
- description: "genrule using $(locations) label should substitute first tool label automatically",
- moduleTypeUnderTest: "genrule",
- moduleTypeUnderTestFactory: genrule.GenRuleFactory,
+ description: "genrule using $(locations) label should substitute first tool label automatically",
+ moduleTypeUnderTest: "genrule",
+ moduleTypeUnderTestFactory: genrule.GenRuleFactory,
+ moduleTypeUnderTestBp2BuildMutator: genrule.GenruleBp2Build,
bp: `genrule {
name: "foo",
out: ["foo.out"],
@@ -409,9 +416,10 @@ func TestModuleTypeBp2Build(t *testing.T) {
)`,
},
{
- description: "genrule without tools or tool_files can convert successfully",
- moduleTypeUnderTest: "genrule",
- moduleTypeUnderTestFactory: genrule.GenRuleFactory,
+ description: "genrule without tools or tool_files can convert successfully",
+ moduleTypeUnderTest: "genrule",
+ moduleTypeUnderTestFactory: genrule.GenRuleFactory,
+ moduleTypeUnderTestBp2BuildMutator: genrule.GenruleBp2Build,
bp: `genrule {
name: "foo",
out: ["foo.out"],
@@ -436,6 +444,7 @@ func TestModuleTypeBp2Build(t *testing.T) {
config := android.TestConfig(buildDir, nil, testCase.bp, nil)
ctx := android.NewTestContext(config)
ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory)
+ ctx.RegisterBp2BuildMutator(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestBp2BuildMutator)
ctx.RegisterForBazelConversion()
_, errs := ctx.ParseFileList(dir, []string{"Android.bp"})