Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit 0f53646

Browse files
committed
tests(tooling-api): fix test for minimum supported AGP version
1 parent e2502f3 commit 0f53646

File tree

2 files changed

+49
-63
lines changed

2 files changed

+49
-63
lines changed

subprojects/tooling-api-impl/src/test/java/com/itsaky/androidide/tooling/impl/CIOnlyToolingApiTests.kt

Lines changed: 31 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
package com.itsaky.androidide.tooling.impl
1919

20-
import ch.qos.logback.classic.Logger
21-
import ch.qos.logback.classic.LoggerContext
2220
import com.google.common.truth.Truth.assertThat
2321
import com.itsaky.androidide.builder.model.IDESyncIssue
2422
import com.itsaky.androidide.buildinfo.BuildInfo
@@ -30,7 +28,6 @@ import org.junit.Rule
3028
import org.junit.Test
3129
import org.junit.runner.RunWith
3230
import org.junit.runners.JUnit4
33-
import org.slf4j.LoggerFactory
3431

3532
/**
3633
* @author Akash Yadav
@@ -69,72 +66,47 @@ class CIOnlyToolingApiTests {
6966

7067
@Test
7168
fun `test CI-only latest tested AGP version warning`() {
72-
collectOuput { appender ->
73-
val agpVersion = AndroidPluginVersion.parse(BuildInfo.AGP_VERSION_LATEST)
69+
val agpVersion = AndroidPluginVersion.parse(BuildInfo.AGP_VERSION_LATEST)
7470

75-
val client = ToolingApiTestLauncher.MultiVersionTestClient(
76-
agpVersion = agpVersion.toStringSimple(),
77-
gradleVersion = BuildInfo.AGP_VERSION_GRADLE_LATEST
78-
)
79-
80-
ToolingApiTestLauncher.launchServer(
81-
client = client,
82-
83-
// Version of Android Gradle Plugin that the tooling API should recognize
84-
// as the latest one
85-
sysProps = mapOf(
86-
ToolingProps.TESTING_LATEST_AGP_VERSION
87-
to ToolingApiTestLauncher.MultiVersionTestClient.DEFAULT_AGP_VERSION
88-
)
89-
) {
90-
val output = appender.toString()
91-
92-
if (result?.isSuccessful != true) {
93-
// print the output if the initialization fails
94-
println(output)
95-
}
71+
val client = ToolingApiTestLauncher.MultiVersionTestClient(
72+
agpVersion = agpVersion.toStringSimple(),
73+
gradleVersion = BuildInfo.AGP_VERSION_GRADLE_LATEST
74+
)
9675

97-
assertThat(result?.isSuccessful).isTrue()
76+
ToolingApiTestLauncher.launchServer(
77+
client = client,
9878

99-
val syncIssues = project.getProjectSyncIssues().get()
100-
assertThat(syncIssues).isNotNull()
101-
assertThat(syncIssues.syncIssues).isNotEmpty()
102-
assertThat(
103-
syncIssues.syncIssues.find { it.type == IDESyncIssue.TYPE_AGP_VERSION_TOO_NEW }).isNotNull()
104-
}
79+
// Version of Android Gradle Plugin that the tooling API should recognize
80+
// as the latest one
81+
sysProps = mapOf(
82+
ToolingProps.TESTING_LATEST_AGP_VERSION
83+
to ToolingApiTestLauncher.MultiVersionTestClient.DEFAULT_AGP_VERSION
84+
)
85+
) {
86+
assertThat(result?.isSuccessful).isTrue()
87+
88+
val syncIssues = project.getProjectSyncIssues().get()
89+
assertThat(syncIssues).isNotNull()
90+
assertThat(syncIssues.syncIssues).isNotEmpty()
91+
assertThat(
92+
syncIssues.syncIssues.find { it.type == IDESyncIssue.TYPE_AGP_VERSION_TOO_NEW }).isNotNull()
10593
}
10694
}
10795

10896
@Test
10997
fun `test CI-only minimum AGP version failure`() {
110-
collectOuput { appender ->
111-
val agpVersion = "7.1.0"
112-
val client = ToolingApiTestLauncher.MultiVersionTestClient(agpVersion = agpVersion,
113-
gradleVersion = "7.2")
114-
ToolingApiTestLauncher.launchServer(client = client) {
115-
assertThat(result?.isSuccessful).isFalse()
116-
117-
val output = appender.toString()
118-
assertThat(output).contains(
119-
"Android Gradle Plugin version $agpVersion is not supported by AndroidIDE.")
98+
val agpVersion = "7.1.0"
99+
val client = ToolingApiTestLauncher.MultiVersionTestClient(
100+
agpVersion = agpVersion,
101+
gradleVersion = "7.2",
102+
outputValidator = { line ->
103+
line.contains("Android Gradle Plugin version $agpVersion is not supported by AndroidIDE.")
120104
}
121-
}
122-
}
123-
124-
private fun <T : Any?> collectOuput(action: (appender: CollectingAppender) -> T): T {
125-
126-
val appender = CollectingAppender()
127-
val rootLogger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME) as Logger
128-
appender.context = LoggerFactory.getILoggerFactory() as LoggerContext
129-
appender.start()
130-
131-
rootLogger.addAppender(appender)
105+
)
132106

133-
return try {
134-
action(appender)
135-
} finally {
136-
appender.stop()
137-
rootLogger.detachAppender(appender)
107+
ToolingApiTestLauncher.launchServer(client = client) {
108+
assertThat(result?.isSuccessful).isFalse()
109+
assertThat(client.isOutputValid).isTrue()
138110
}
139111
}
140112
}

testing/tooling/src/main/java/com/itsaky/androidide/testing/tooling/ToolingApiTestLauncher.kt

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package com.itsaky.androidide.testing.tooling
1919

20+
import com.google.common.truth.Truth.assertThat
2021
import com.itsaky.androidide.testing.tooling.models.ToolingApiTestLauncherParams
2122
import com.itsaky.androidide.testing.tooling.models.ToolingApiTestScope
2223
import com.itsaky.androidide.tooling.api.IProject
@@ -80,7 +81,7 @@ object ToolingApiTestLauncher {
8081
log: Logger = LoggerFactory.getLogger("BuildOutputLogger"),
8182
sysProps: Map<String, String> = emptyMap(),
8283
sysEnvs: Map<String, String> = emptyMap(),
83-
action: ToolingApiTestScope.() -> Unit
84+
action: ToolingApiTestScope.() -> Unit,
8485
) = launchServer(
8586
ToolingApiTestLauncherParams(projectDir, client, initParams, log, sysProps, sysEnvs), action)
8687

@@ -196,12 +197,17 @@ object ToolingApiTestLauncher {
196197
private val androidBlockConfig: String = "",
197198
private val log: Logger = LoggerFactory.getLogger(MultiVersionTestClient::class.java),
198199
private val extraArgs: List<String> = emptyList(),
199-
private var excludeUnresolvedDependency: Boolean = false
200+
private var excludeUnresolvedDependency: Boolean = false,
201+
var outputValidator: (String) -> Boolean = { true },
200202
) : IToolingApiClient {
201203

204+
var isOutputValid = false
205+
private set
206+
202207
val gradleDistParams: GradleDistributionParams
203208
get() = GradleDistributionParams.forVersion(this.gradleVersion)
204209

210+
@Suppress("ConstPropertyName")
205211
companion object {
206212

207213
const val buildFile = "build.gradle"
@@ -232,7 +238,15 @@ object ToolingApiTestLauncher {
232238
}
233239

234240
override fun logOutput(line: String) {
235-
log.debug(line.trim())
241+
val trimmed = line.trim()
242+
val curr = this.isOutputValid;
243+
this.isOutputValid = this.isOutputValid || outputValidator(trimmed)
244+
245+
if (!curr && this.isOutputValid) {
246+
log.debug("Output validation succeeded")
247+
}
248+
249+
log.debug(trimmed)
236250
}
237251

238252
override fun prepareBuild(buildInfo: BuildInfo) {
@@ -261,7 +275,7 @@ object ToolingApiTestLauncher {
261275
onBuildResult(result)
262276
}
263277

264-
private fun onBuildResult(result: BuildResult) {
278+
private fun onBuildResult(@Suppress("UNUSED_PARAMETER") result: BuildResult) {
265279
projectDir.resolve(buildFile).deleteIfExists()
266280
projectDir.resolve(appBuildFile).deleteIfExists()
267281
}

0 commit comments

Comments
 (0)