diff --git a/kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/cases/NoDependencyTests.kt b/kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/cases/NoDependencyTests.kt new file mode 100644 index 00000000..d7729524 --- /dev/null +++ b/kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/cases/NoDependencyTests.kt @@ -0,0 +1,44 @@ +package kotlinx.kover.gradle.plugin.test.functional.cases + +import kotlinx.kover.gradle.plugin.test.functional.framework.checker.checkNoAndroidSdk +import kotlinx.kover.gradle.plugin.test.functional.framework.runner.buildFromTemplate +import kotlinx.kover.gradle.plugin.test.functional.framework.runner.runWithParams +import org.junit.jupiter.api.Test +import kotlin.test.assertContains +import kotlin.test.assertFalse + +/** + * Tests on dependency check https://github.com/Kotlin/kotlinx-kover/issues/478. + */ +class NoDependencyTests { + @Test + fun testJvmNotApplied() { + val buildSource = buildFromTemplate("no-dependency-jvm") + val build = buildSource.generate() + val buildResult = build.runWithParams("koverHtmlReport") + assertFalse(buildResult.isSuccessful) + assertContains(buildResult.output, "Kover plugin is not applied") + } + + @Test + fun testAndroidNotApplied() { + val buildSource = buildFromTemplate("no-dependency-android") + val build = buildSource.generate() + val buildResult = build.runWithParams(":app:koverHtmlReportDebug") + buildResult.checkNoAndroidSdk() + + assertFalse(buildResult.isSuccessful) + assertContains(buildResult.output, "Kover plugin is not applied") + } + + @Test + fun testAndroidNoVariant() { + val buildSource = buildFromTemplate("no-dependency-variant-android") + val build = buildSource.generate() + val buildResult = build.runWithParams(":app-extra:koverHtmlReportExtra") + buildResult.checkNoAndroidSdk() + + assertFalse(buildResult.isSuccessful) + assertContains(buildResult.output, "Kover android variant 'extra' was not matched with any variant from dependency") + } +} \ No newline at end of file diff --git a/kover-gradle-plugin/src/functionalTest/templates/builds/no-dependency-android/app/build.gradle.kts b/kover-gradle-plugin/src/functionalTest/templates/builds/no-dependency-android/app/build.gradle.kts new file mode 100644 index 00000000..fc439e6b --- /dev/null +++ b/kover-gradle-plugin/src/functionalTest/templates/builds/no-dependency-android/app/build.gradle.kts @@ -0,0 +1,47 @@ +plugins { + id ("org.jetbrains.kotlinx.kover") + id ("com.android.application") + id ("org.jetbrains.kotlin.android") +} + +android { + namespace = "kotlinx.kover.test.android" + compileSdk = 32 + + defaultConfig { + applicationId = "kotlinx.kover.test.android" + minSdk = 21 + targetSdk = 31 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + isMinifyEnabled = true + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = "1.8" + } + buildFeatures { + viewBinding = true + } +} + +dependencies { + // error dependency + kover(project(":subproject")) + + implementation("androidx.core:core-ktx:1.8.0") + implementation("androidx.appcompat:appcompat:1.5.0") + implementation("com.google.android.material:material:1.6.1") + implementation("androidx.constraintlayout:constraintlayout:2.1.4") + testImplementation("junit:junit:4.13.2") +} diff --git a/kover-gradle-plugin/src/functionalTest/templates/builds/no-dependency-android/app/src/main/AndroidManifest.xml b/kover-gradle-plugin/src/functionalTest/templates/builds/no-dependency-android/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..358fac25 --- /dev/null +++ b/kover-gradle-plugin/src/functionalTest/templates/builds/no-dependency-android/app/src/main/AndroidManifest.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kover-gradle-plugin/src/functionalTest/templates/builds/no-dependency-android/app/src/main/java/kotlinx/kover/test/android/DebugUtil.kt b/kover-gradle-plugin/src/functionalTest/templates/builds/no-dependency-android/app/src/main/java/kotlinx/kover/test/android/DebugUtil.kt new file mode 100644 index 00000000..efe82040 --- /dev/null +++ b/kover-gradle-plugin/src/functionalTest/templates/builds/no-dependency-android/app/src/main/java/kotlinx/kover/test/android/DebugUtil.kt @@ -0,0 +1,7 @@ +package kotlinx.kover.test.android + +object DebugUtil { + fun log(message: String) { + println("DEBUG: $message") + } +} \ No newline at end of file diff --git a/kover-gradle-plugin/src/functionalTest/templates/builds/no-dependency-android/app/src/main/java/kotlinx/kover/test/android/MainActivity.kt b/kover-gradle-plugin/src/functionalTest/templates/builds/no-dependency-android/app/src/main/java/kotlinx/kover/test/android/MainActivity.kt new file mode 100644 index 00000000..1caaf5b6 --- /dev/null +++ b/kover-gradle-plugin/src/functionalTest/templates/builds/no-dependency-android/app/src/main/java/kotlinx/kover/test/android/MainActivity.kt @@ -0,0 +1,13 @@ +package kotlinx.kover.test.android + +import android.os.Bundle +import android.app.Activity + +class MainActivity : Activity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + } + +} diff --git a/kover-gradle-plugin/src/functionalTest/templates/builds/no-dependency-android/app/src/main/java/kotlinx/kover/test/android/Maths.kt b/kover-gradle-plugin/src/functionalTest/templates/builds/no-dependency-android/app/src/main/java/kotlinx/kover/test/android/Maths.kt new file mode 100644 index 00000000..03edc099 --- /dev/null +++ b/kover-gradle-plugin/src/functionalTest/templates/builds/no-dependency-android/app/src/main/java/kotlinx/kover/test/android/Maths.kt @@ -0,0 +1,13 @@ +package kotlinx.kover.test.android + +object Maths { + fun sum(a: Int, b: Int): Int { + DebugUtil.log("invoked sum") + return a + b + } + + fun sub(a: Int, b: Int): Int { + DebugUtil.log("invoked sub") + return a - b + } +} \ No newline at end of file diff --git a/kover-gradle-plugin/src/functionalTest/templates/builds/no-dependency-android/app/src/main/res/layout/activity_main.xml b/kover-gradle-plugin/src/functionalTest/templates/builds/no-dependency-android/app/src/main/res/layout/activity_main.xml new file mode 100644 index 00000000..ee57d166 --- /dev/null +++ b/kover-gradle-plugin/src/functionalTest/templates/builds/no-dependency-android/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,36 @@ + + + + + + + + \ No newline at end of file diff --git a/kover-gradle-plugin/src/functionalTest/templates/builds/no-dependency-android/app/src/main/res/values/colors.xml b/kover-gradle-plugin/src/functionalTest/templates/builds/no-dependency-android/app/src/main/res/values/colors.xml new file mode 100644 index 00000000..f8c6127d --- /dev/null +++ b/kover-gradle-plugin/src/functionalTest/templates/builds/no-dependency-android/app/src/main/res/values/colors.xml @@ -0,0 +1,10 @@ + + + #FFBB86FC + #FF6200EE + #FF3700B3 + #FF03DAC5 + #FF018786 + #FF000000 + #FFFFFFFF + \ No newline at end of file diff --git a/kover-gradle-plugin/src/functionalTest/templates/builds/no-dependency-android/app/src/main/res/values/strings.xml b/kover-gradle-plugin/src/functionalTest/templates/builds/no-dependency-android/app/src/main/res/values/strings.xml new file mode 100644 index 00000000..fa43411e --- /dev/null +++ b/kover-gradle-plugin/src/functionalTest/templates/builds/no-dependency-android/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + Android Test + \ No newline at end of file diff --git a/kover-gradle-plugin/src/functionalTest/templates/builds/no-dependency-android/app/src/main/res/values/themes.xml b/kover-gradle-plugin/src/functionalTest/templates/builds/no-dependency-android/app/src/main/res/values/themes.xml new file mode 100644 index 00000000..0b4cfc4c --- /dev/null +++ b/kover-gradle-plugin/src/functionalTest/templates/builds/no-dependency-android/app/src/main/res/values/themes.xml @@ -0,0 +1,4 @@ + + +