Support Kotlin in Robolectric test

Currently, Robolectric test written in Kotlin may not run, especially
when shards are in used, for example SettingsRoboTests has 10 shards.

This is because Robolectric test currently only recognize java files,
adding kt files to fix.

Rename current uniqueSrcFiles to uniqueJavaFiles, and compiledJavaSrcs
to uniqueSrcFiles. uniqueSrcFiles will contains both Java and Kotlin
files.

Note: android.FirstUniquePaths cannot be used, seems the behavior is
different and cause build error.

Bug: 252355400
Test: cd build/soong && mm
Test: m RunSettingsRoboTests with Kotlin tests
Change-Id: Id530ae4dcabffe01a06f44fe4234ffc67b73a601
This commit is contained in:
Chaohui Wang
2022-10-11 11:13:30 +08:00
parent 922875d187
commit dcbe33ced2
3 changed files with 34 additions and 28 deletions

View File

@@ -188,9 +188,9 @@ func (r *robolectricTest) GenerateAndroidBuildActions(ctx android.ModuleContext)
// TODO: this could all be removed if tradefed was used as the test runner, it will find everything
// annotated as a test and run it.
for _, src := range r.compiledJavaSrcs {
for _, src := range r.uniqueSrcFiles {
s := src.Rel()
if !strings.HasSuffix(s, "Test.java") {
if !strings.HasSuffix(s, "Test.java") && !strings.HasSuffix(s, "Test.kt") {
continue
} else if strings.HasSuffix(s, "/BaseRobolectricTest.java") {
continue