mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
tests(tooling-api): fix test for minimum supported AGP version
This commit is contained in:
+31
-59
@@ -17,8 +17,6 @@
|
||||
|
||||
package com.itsaky.androidide.tooling.impl
|
||||
|
||||
import ch.qos.logback.classic.Logger
|
||||
import ch.qos.logback.classic.LoggerContext
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import com.itsaky.androidide.builder.model.IDESyncIssue
|
||||
import com.itsaky.androidide.buildinfo.BuildInfo
|
||||
@@ -30,7 +28,6 @@ import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.JUnit4
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
/**
|
||||
* @author Akash Yadav
|
||||
@@ -69,72 +66,47 @@ class CIOnlyToolingApiTests {
|
||||
|
||||
@Test
|
||||
fun `test CI-only latest tested AGP version warning`() {
|
||||
collectOuput { appender ->
|
||||
val agpVersion = AndroidPluginVersion.parse(BuildInfo.AGP_VERSION_LATEST)
|
||||
val agpVersion = AndroidPluginVersion.parse(BuildInfo.AGP_VERSION_LATEST)
|
||||
|
||||
val client = ToolingApiTestLauncher.MultiVersionTestClient(
|
||||
agpVersion = agpVersion.toStringSimple(),
|
||||
gradleVersion = BuildInfo.AGP_VERSION_GRADLE_LATEST
|
||||
val client = ToolingApiTestLauncher.MultiVersionTestClient(
|
||||
agpVersion = agpVersion.toStringSimple(),
|
||||
gradleVersion = BuildInfo.AGP_VERSION_GRADLE_LATEST
|
||||
)
|
||||
|
||||
ToolingApiTestLauncher.launchServer(
|
||||
client = client,
|
||||
|
||||
// Version of Android Gradle Plugin that the tooling API should recognize
|
||||
// as the latest one
|
||||
sysProps = mapOf(
|
||||
ToolingProps.TESTING_LATEST_AGP_VERSION
|
||||
to ToolingApiTestLauncher.MultiVersionTestClient.DEFAULT_AGP_VERSION
|
||||
)
|
||||
) {
|
||||
assertThat(result?.isSuccessful).isTrue()
|
||||
|
||||
ToolingApiTestLauncher.launchServer(
|
||||
client = client,
|
||||
|
||||
// Version of Android Gradle Plugin that the tooling API should recognize
|
||||
// as the latest one
|
||||
sysProps = mapOf(
|
||||
ToolingProps.TESTING_LATEST_AGP_VERSION
|
||||
to ToolingApiTestLauncher.MultiVersionTestClient.DEFAULT_AGP_VERSION
|
||||
)
|
||||
) {
|
||||
val output = appender.toString()
|
||||
|
||||
if (result?.isSuccessful != true) {
|
||||
// print the output if the initialization fails
|
||||
println(output)
|
||||
}
|
||||
|
||||
assertThat(result?.isSuccessful).isTrue()
|
||||
|
||||
val syncIssues = project.getProjectSyncIssues().get()
|
||||
assertThat(syncIssues).isNotNull()
|
||||
assertThat(syncIssues.syncIssues).isNotEmpty()
|
||||
assertThat(
|
||||
syncIssues.syncIssues.find { it.type == IDESyncIssue.TYPE_AGP_VERSION_TOO_NEW }).isNotNull()
|
||||
}
|
||||
val syncIssues = project.getProjectSyncIssues().get()
|
||||
assertThat(syncIssues).isNotNull()
|
||||
assertThat(syncIssues.syncIssues).isNotEmpty()
|
||||
assertThat(
|
||||
syncIssues.syncIssues.find { it.type == IDESyncIssue.TYPE_AGP_VERSION_TOO_NEW }).isNotNull()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test CI-only minimum AGP version failure`() {
|
||||
collectOuput { appender ->
|
||||
val agpVersion = "7.1.0"
|
||||
val client = ToolingApiTestLauncher.MultiVersionTestClient(agpVersion = agpVersion,
|
||||
gradleVersion = "7.2")
|
||||
ToolingApiTestLauncher.launchServer(client = client) {
|
||||
assertThat(result?.isSuccessful).isFalse()
|
||||
|
||||
val output = appender.toString()
|
||||
assertThat(output).contains(
|
||||
"Android Gradle Plugin version $agpVersion is not supported by AndroidIDE.")
|
||||
val agpVersion = "7.1.0"
|
||||
val client = ToolingApiTestLauncher.MultiVersionTestClient(
|
||||
agpVersion = agpVersion,
|
||||
gradleVersion = "7.2",
|
||||
outputValidator = { line ->
|
||||
line.contains("Android Gradle Plugin version $agpVersion is not supported by AndroidIDE.")
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
private fun <T : Any?> collectOuput(action: (appender: CollectingAppender) -> T): T {
|
||||
|
||||
val appender = CollectingAppender()
|
||||
val rootLogger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME) as Logger
|
||||
appender.context = LoggerFactory.getILoggerFactory() as LoggerContext
|
||||
appender.start()
|
||||
|
||||
rootLogger.addAppender(appender)
|
||||
|
||||
return try {
|
||||
action(appender)
|
||||
} finally {
|
||||
appender.stop()
|
||||
rootLogger.detachAppender(appender)
|
||||
ToolingApiTestLauncher.launchServer(client = client) {
|
||||
assertThat(result?.isSuccessful).isFalse()
|
||||
assertThat(client.isOutputValid).isTrue()
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
-4
@@ -17,6 +17,7 @@
|
||||
|
||||
package com.itsaky.androidide.testing.tooling
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import com.itsaky.androidide.testing.tooling.models.ToolingApiTestLauncherParams
|
||||
import com.itsaky.androidide.testing.tooling.models.ToolingApiTestScope
|
||||
import com.itsaky.androidide.tooling.api.IProject
|
||||
@@ -80,7 +81,7 @@ object ToolingApiTestLauncher {
|
||||
log: Logger = LoggerFactory.getLogger("BuildOutputLogger"),
|
||||
sysProps: Map<String, String> = emptyMap(),
|
||||
sysEnvs: Map<String, String> = emptyMap(),
|
||||
action: ToolingApiTestScope.() -> Unit
|
||||
action: ToolingApiTestScope.() -> Unit,
|
||||
) = launchServer(
|
||||
ToolingApiTestLauncherParams(projectDir, client, initParams, log, sysProps, sysEnvs), action)
|
||||
|
||||
@@ -196,12 +197,17 @@ object ToolingApiTestLauncher {
|
||||
private val androidBlockConfig: String = "",
|
||||
private val log: Logger = LoggerFactory.getLogger(MultiVersionTestClient::class.java),
|
||||
private val extraArgs: List<String> = emptyList(),
|
||||
private var excludeUnresolvedDependency: Boolean = false
|
||||
private var excludeUnresolvedDependency: Boolean = false,
|
||||
var outputValidator: (String) -> Boolean = { true },
|
||||
) : IToolingApiClient {
|
||||
|
||||
var isOutputValid = false
|
||||
private set
|
||||
|
||||
val gradleDistParams: GradleDistributionParams
|
||||
get() = GradleDistributionParams.forVersion(this.gradleVersion)
|
||||
|
||||
@Suppress("ConstPropertyName")
|
||||
companion object {
|
||||
|
||||
const val buildFile = "build.gradle"
|
||||
@@ -232,7 +238,15 @@ object ToolingApiTestLauncher {
|
||||
}
|
||||
|
||||
override fun logOutput(line: String) {
|
||||
log.debug(line.trim())
|
||||
val trimmed = line.trim()
|
||||
val curr = this.isOutputValid;
|
||||
this.isOutputValid = this.isOutputValid || outputValidator(trimmed)
|
||||
|
||||
if (!curr && this.isOutputValid) {
|
||||
log.debug("Output validation succeeded")
|
||||
}
|
||||
|
||||
log.debug(trimmed)
|
||||
}
|
||||
|
||||
override fun prepareBuild(buildInfo: BuildInfo) {
|
||||
@@ -261,7 +275,7 @@ object ToolingApiTestLauncher {
|
||||
onBuildResult(result)
|
||||
}
|
||||
|
||||
private fun onBuildResult(result: BuildResult) {
|
||||
private fun onBuildResult(@Suppress("UNUSED_PARAMETER") result: BuildResult) {
|
||||
projectDir.resolve(buildFile).deleteIfExists()
|
||||
projectDir.resolve(appBuildFile).deleteIfExists()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user