From 6b7559d70d029617a4973bda76afc97e264a8c27 Mon Sep 17 00:00:00 2001 From: 0xera <56160164+0xera@users.noreply.github.com> Date: Tue, 8 Oct 2024 12:04:45 +0300 Subject: [PATCH] add function test to check pom file --- grease/build.gradle.kts | 18 +++ .../tools/grease/GeneratedPomFileTest.kt | 104 ++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 grease/src/functionalTest/kotlin/io/deepmedia/tools/grease/GeneratedPomFileTest.kt diff --git a/grease/build.gradle.kts b/grease/build.gradle.kts index cd9a10f..8144800 100644 --- a/grease/build.gradle.kts +++ b/grease/build.gradle.kts @@ -1,4 +1,5 @@ plugins { + `jvm-test-suite` `kotlin-dsl` alias(libs.plugins.publisher) } @@ -6,6 +7,21 @@ plugins { group = "io.deepmedia.tools" version = "0.3.2" +testing { + suites { + register("functionalTest") { + useJUnit() + testType.set(TestSuiteType.FUNCTIONAL_TEST) + + dependencies { + implementation(gradleTestKit()) + implementation(project.dependencies.kotlin("test") as String) + implementation(project.dependencies.kotlin("test-junit") as String) + } + } + } +} + gradlePlugin { plugins { create("grease") { @@ -13,6 +29,8 @@ gradlePlugin { implementationClass = "io.deepmedia.tools.grease.GreasePlugin" } } + + testSourceSets(sourceSets["functionalTest"]) } dependencies { diff --git a/grease/src/functionalTest/kotlin/io/deepmedia/tools/grease/GeneratedPomFileTest.kt b/grease/src/functionalTest/kotlin/io/deepmedia/tools/grease/GeneratedPomFileTest.kt new file mode 100644 index 0000000..98a15da --- /dev/null +++ b/grease/src/functionalTest/kotlin/io/deepmedia/tools/grease/GeneratedPomFileTest.kt @@ -0,0 +1,104 @@ +package io.deepmedia.tools.grease + +import org.gradle.testkit.runner.GradleRunner +import java.nio.file.Path +import kotlin.io.path.ExperimentalPathApi +import kotlin.io.path.createTempDirectory +import kotlin.io.path.deleteRecursively +import kotlin.io.path.readText +import kotlin.io.path.writeText +import kotlin.test.AfterTest +import kotlin.test.BeforeTest +import kotlin.test.Test +import kotlin.test.assertContains +import kotlin.test.assertFails +import kotlin.test.assertFalse + +class GeneratedPomFileTest { + + private var testProjectDir = createTempDirectory("tmp") + private lateinit var settingsFile: Path + private lateinit var buildFile: Path + + @BeforeTest + fun setup() { + settingsFile = testProjectDir.resolve("settings.gradle.kts") + buildFile = testProjectDir.resolve("build.gradle.kts") + } + + @Test + fun test() { + buildFile.writeText( + """ + plugins { + `maven-publish` + id("com.android.library") version "8.1.4" + } + + apply() + + android { + namespace = "io.deepmedia.tools.grease.sample" + compileSdk = 34 + defaultConfig { + minSdk = 21 + } + publishing { + singleVariant("debug") { + withSourcesJar() + } + } + } + + repositories { + google() + gradlePluginPortal() + mavenCentral() + } + + publishing { + publications { + create("Test", MavenPublication::class.java) { + afterEvaluate { + from(components["debug"]) + } + } + } + } + dependencies { + "grease"("com.otaliastudios:cameraview:2.7.2") + "greaseTree"("androidx.core:core:1.0.0") + } + """.trimIndent() + ) + + settingsFile.writeText(""" + pluginManagement { + repositories { + google() + gradlePluginPortal() + mavenCentral() + } + } + + rootProject.name = "Sample" + """.trimIndent()) + + GradleRunner.create() + .withPluginClasspath() + .withProjectDir(testProjectDir.toFile()) + .forwardOutput() + .withArguments("generatePomFileForTestPublication") + .build() + + val pomContent = testProjectDir.resolve("build/publications/Test/pom-default.xml").readText() + assertFalse(pomContent.contains("androidx.core") ) + assertFalse(pomContent.contains("com.otaliastudios") ) + } + + @OptIn(ExperimentalPathApi::class) + @AfterTest + fun teardown() { + testProjectDir.deleteRecursively() + } +} \ No newline at end of file