in sources/amper-cli/src/org/jetbrains/amper/cli/AmperBackend.kt [236:302]
suspend fun test(
includeModules: Set<String>?,
requestedPlatforms: Set<Platform>?,
excludeModules: Set<String>,
buildType: BuildType?,
) {
require(requestedPlatforms == null || requestedPlatforms.isNotEmpty())
val moduleNamesToCheck = (includeModules ?: emptySet()) + excludeModules
moduleNamesToCheck.forEach { resolveModule(it) }
requestedPlatforms
?.filter { it !in PlatformUtil.platformsMayRunOnCurrentSystem }
?.takeIf { it.isNotEmpty() }
?.let { unsupportedPlatforms ->
val message = """
Unable to run requested platform(s) on the current system.
Requested unsupported platforms: ${formatPlatforms(unsupportedPlatforms)}
Runnable platforms on the current system: ${formatPlatforms(PlatformUtil.platformsMayRunOnCurrentSystem)}
""".trimIndent()
userReadableError(message)
}
val allTestTasks = taskGraph.tasks.filterIsInstance<TestTask>()
if (allTestTasks.isEmpty()) {
userReadableError("No test tasks were found in the entire project")
}
val platformTestTasks = allTestTasks
.filter { it.platform in (requestedPlatforms ?: PlatformUtil.platformsMayRunOnCurrentSystem) }
.filterByBuildTypeAndReport(
explicit = buildType?.let(::setOf),
default = BuildType.Debug,
)
requestedPlatforms?.filter { requestedPlatform ->
platformTestTasks.none { it.platform == requestedPlatform }
}?.takeIf { it.isNotEmpty() }?.let { platformsWithMissingTests ->
userReadableError("No test tasks were found for platforms: " +
platformsWithMissingTests.map { it.name }.sorted().joinToString(" ")
)
}
val includedTestTasks = if (includeModules != null) {
platformTestTasks.filter { task -> includeModules.contains(task.module.userReadableName) }
} else {
platformTestTasks
}
if (includedTestTasks.isEmpty()) {
userReadableError("No test tasks were found for specified include filters")
}
if (runSettings.userJvmArgs.isNotEmpty() &&
includedTestTasks.none { it.platform in setOf(Platform.JVM, Platform.ANDROID) }
) {
logger.warn("The $UserJvmArgsOption option has no effect when running only non-JVM tests")
}
val testTasks = includedTestTasks
.filter { task -> !excludeModules.contains(task.module.userReadableName) }
.map { it.taskName }
.toSet()
if (testTasks.isEmpty()) {
userReadableError("No test tasks were found after applying exclude filters")
}
taskExecutor.runTasksAndReportOnFailure(testTasks)
}