diff --git a/bp2build/cc_test_conversion_test.go b/bp2build/cc_test_conversion_test.go index 8c2d30d24..b20f6ffbc 100644 --- a/bp2build/cc_test_conversion_test.go +++ b/bp2build/cc_test_conversion_test.go @@ -26,6 +26,7 @@ import ( type ccTestBp2buildTestCase struct { description string blueprint string + filesystem map[string]string targets []testBazelTarget } @@ -41,12 +42,12 @@ func registerCcTestModuleTypes(ctx android.RegistrationContext) { func runCcTestTestCase(t *testing.T, testCase ccTestBp2buildTestCase) { t.Helper() moduleTypeUnderTest := "cc_test" - description := fmt.Sprintf("%s %s", moduleTypeUnderTest, testCase.description) t.Run(description, func(t *testing.T) { t.Helper() RunBp2BuildTestCase(t, registerCcTestModuleTypes, Bp2buildTestCase{ ExpectedBazelTargets: generateBazelTargetsForTest(testCase.targets, android.HostAndDeviceSupported), + Filesystem: testCase.filesystem, ModuleTypeUnderTest: moduleTypeUnderTest, ModuleTypeUnderTestFactory: cc.TestFactory, Description: description, @@ -172,3 +173,90 @@ cc_test { }, }) } + +func TestCcTest_TestConfig(t *testing.T) { + runCcTestTestCase(t, ccTestBp2buildTestCase{ + description: "cc test that sets a test_config", + filesystem: map[string]string{ + "test_config.xml": "", + }, + blueprint: ` +cc_test { + name: "mytest", + srcs: ["test.cpp"], + test_config: "test_config.xml", +} +`, + targets: []testBazelTarget{ + {"cc_test", "mytest", AttrNameToString{ + "gtest": "True", + "isolated": "True", + "local_includes": `["."]`, + "srcs": `["test.cpp"]`, + "target_compatible_with": `["//build/bazel/platforms/os:android"]`, + "test_config": `"test_config.xml"`, + }, + }, + }, + }) +} + +func TestCcTest_TestConfigAndroidTestXML(t *testing.T) { + runCcTestTestCase(t, ccTestBp2buildTestCase{ + description: "cc test that defaults to test config AndroidTest.xml", + filesystem: map[string]string{ + "AndroidTest.xml": "", + }, + blueprint: ` +cc_test { + name: "mytest", + srcs: ["test.cpp"], +} +`, + targets: []testBazelTarget{ + {"cc_test", "mytest", AttrNameToString{ + "gtest": "True", + "isolated": "True", + "local_includes": `["."]`, + "srcs": `["test.cpp"]`, + "target_compatible_with": `["//build/bazel/platforms/os:android"]`, + "test_config": `"AndroidTest.xml"`, + }, + }, + }, + }) +} + +func TestCcTest_TestConfigTemplateOptions(t *testing.T) { + runCcTestTestCase(t, ccTestBp2buildTestCase{ + description: "cc test that sets test config template attributes", + filesystem: map[string]string{ + "test_config_template.xml": "", + }, + blueprint: ` +cc_test { + name: "mytest", + srcs: ["test.cpp"], + test_config_template: "test_config_template.xml", + auto_gen_config: true, +} +`, + targets: []testBazelTarget{ + {"cc_test", "mytest", AttrNameToString{ + "auto_generate_test_config": "True", + "gtest": "True", + "isolated": "True", + "local_includes": `["."]`, + "srcs": `["test.cpp"]`, + "target_compatible_with": `["//build/bazel/platforms/os:android"]`, + "template_configs": `[ + "'\\n '", + "'