mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
tests(gradle-plugin): update assertions
This commit is contained in:
+16
-4
@@ -18,7 +18,9 @@
|
||||
package com.itsaky.androidide.gradle
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import com.itsaky.androidide.buildinfo.BuildInfo
|
||||
import com.itsaky.androidide.utils.FileProvider
|
||||
import org.gradle.testkit.runner.BuildResult
|
||||
import org.gradle.testkit.runner.GradleRunner
|
||||
import org.gradle.testkit.runner.internal.PluginUnderTestMetadataReading
|
||||
import org.junit.jupiter.api.Test
|
||||
@@ -30,8 +32,16 @@ import kotlin.io.path.pathString
|
||||
class AndroidIDEInitScriptPluginTest {
|
||||
|
||||
@Test
|
||||
fun `test init script plugin is applied`() {
|
||||
val projectRoot = openProject()
|
||||
fun `test plugins are applied and log sender dependency is added properly`() {
|
||||
val result = buildProject()
|
||||
assertBasics(result)
|
||||
}
|
||||
|
||||
private fun buildProject(
|
||||
agpVersion: String = BuildInfo.AGP_VERSION_LATEST,
|
||||
vararg plugins: String
|
||||
): BuildResult {
|
||||
val projectRoot = openProject(agpVersion, *plugins)
|
||||
val initScript = FileProvider.testHomeDir().resolve(".androidide/init/androidide.init.gradle")
|
||||
val mavenLocal = FileProvider.projectRoot().resolve("gradle-plugin/build/maven-local")
|
||||
|
||||
@@ -48,8 +58,10 @@ class AndroidIDEInitScriptPluginTest {
|
||||
writeInitScript(initScript.toFile(),
|
||||
PluginUnderTestMetadataReading.readImplementationClasspath())
|
||||
|
||||
val result = runner.build()
|
||||
return runner.build()
|
||||
}
|
||||
|
||||
private fun assertBasics(result: BuildResult) {
|
||||
// These plugins must be applied to the
|
||||
for ((project, plugins) in mapOf(
|
||||
":app" to arrayOf(AndroidIDEGradlePlugin::class, LogSenderPlugin::class))) {
|
||||
@@ -64,7 +76,7 @@ class AndroidIDEInitScriptPluginTest {
|
||||
for ((project, variants) in mapOf(":app" to arrayOf("demoDebug", "fullDebug"))) {
|
||||
for (variant in variants) {
|
||||
assertThat(result.output).contains(
|
||||
"Adding LogSender dependency to variant '${variant}' of project '${project}'"
|
||||
"Adding LogSender dependency (version '${BuildInfo.VERSION_NAME_SIMPLE}') to variant '${variant}' of project '${project}'"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
package com.itsaky.androidide.gradle
|
||||
|
||||
import com.itsaky.androidide.buildinfo.BuildInfo
|
||||
import com.itsaky.androidide.utils.FileProvider
|
||||
import java.io.File
|
||||
import java.nio.file.Path
|
||||
@@ -46,7 +47,10 @@ internal fun writeInitScript(file: File, deps: List<File>) {
|
||||
}
|
||||
}
|
||||
|
||||
internal fun openProject(agpVersion: String = "", vararg plugins: String): Path {
|
||||
internal fun openProject(
|
||||
agpVersion: String = BuildInfo.AGP_VERSION_LATEST,
|
||||
vararg plugins: String
|
||||
): Path {
|
||||
val projectRoot = FileProvider.projectRoot()
|
||||
.resolve("gradle-plugin/src/test/resources/sample-project")
|
||||
|
||||
@@ -67,7 +71,11 @@ internal fun openProject(agpVersion: String = "", vararg plugins: String): Path
|
||||
private fun File.replaceAllPlaceholders(entries: Map<String, String>) {
|
||||
val sb = StringBuilder(parentFile.resolve("${name}.in").readText())
|
||||
for ((placeholder, value) in entries) {
|
||||
sb.replace("@@${placeholder}@@".toRegex(RegexOption.LITERAL), value)
|
||||
val regex = Regex.escape("@@${placeholder}@@").toRegex()
|
||||
val result = regex.findAll(sb)
|
||||
for (matchResult in result) {
|
||||
sb.replace(matchResult.range.first, matchResult.range.last + 1, value)
|
||||
}
|
||||
}
|
||||
writeText(sb.toString())
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
plugins {
|
||||
id("com.android.application") version "8.1.0" apply false
|
||||
id("com.android.library") version "8.1.0" apply false
|
||||
|
||||
}
|
||||
|
||||
tasks.register<Delete>("clean") {
|
||||
delete(rootProject.buildDir)
|
||||
}
|
||||
Reference in New Issue
Block a user