Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filter out projects without a build file #224

Merged
merged 1 commit into from Aug 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,11 +1,13 @@
package kotlinx.kover.test.functional.cases

import kotlinx.kover.test.functional.cases.utils.*
import kotlinx.kover.test.functional.cases.utils.defaultMergedXmlReport
import kotlinx.kover.test.functional.core.*
import kotlinx.kover.test.functional.core.BaseGradleScriptTest
import org.gradle.testkit.runner.*
import kotlin.test.*
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import java.nio.file.Files
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

internal class MultiProjectTests : BaseGradleScriptTest() {
private val subprojectName = "common"
Expand Down Expand Up @@ -190,4 +192,120 @@ internal class MultiProjectTests : BaseGradleScriptTest() {
}
}
}

@Test
fun testNestedProjectInsideEmptyProject() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment, it is good, but in the future it is necessary to create folder with examples of such special case tests.
It is worth separating the various tests, and the tests of special cases when there is no need to run the test in different languages and engines.


val projectDir = Files.createTempDirectory("nested-project").toFile()

projectDir.resolve("settings.gradle.kts").apply {
//language=kts
writeText(
"""
rootProject.name = "nested-project"

include(":subprojects:alpha-project")
""".trimIndent()
)
}

projectDir.resolve("build.gradle.kts").apply {
//language=kts
writeText(
"""
plugins {
base
id("org.jetbrains.kotlinx.kover")
}

repositories { mavenCentral() }

kover {
isDisabled.set(false)
}

koverMerged {
enable()
}
""".trimIndent()
)
}


projectDir.resolve("subprojects/alpha-project/build.gradle.kts").apply {
parentFile.mkdirs()
//language=kts
writeText(
"""
plugins {
kotlin("jvm") version embeddedKotlinVersion
id("org.jetbrains.kotlinx.kover")
}

repositories { mavenCentral() }

dependencies {
testImplementation(kotlin("test"))
}

kover {
isDisabled.set(false)
}
""".trimIndent()
)
}

projectDir.resolve("subprojects/alpha-project/src/test/kotlin/MyTest.kt").apply {
parentFile.mkdirs()
//language=kotlin
writeText(
"""
import kotlin.test.*

class MyTest {
@Test
fun foo() {
assertEquals("123", 123.toString())
}
}
""".trimIndent()
)
}

val gradleRunner = GradleRunner.create()
.withProjectDir(projectDir)
.withPluginClasspath()

gradleRunner
.withArguments(":tasks", "--stacktrace", "--info")
.build().also { result ->
assertTrue(result.output.contains("koverMergedReport"))
assertEquals(
TaskOutcome.SUCCESS,
result.task(":tasks")?.outcome,
result.output
)
}

gradleRunner
.withArguments("check", "--stacktrace", "--info")
.build().also { result ->
assertEquals(
TaskOutcome.SUCCESS,
result.task(":subprojects:alpha-project:test")?.outcome,
result.output
)
}

gradleRunner
.withArguments(":koverMergedReport", "--stacktrace", "--info")
.build().also { result ->
assertTrue(result.output.contains("koverMergedReport"))
assertEquals(
TaskOutcome.SUCCESS,
result.task(":koverMergedReport")?.outcome,
result.output
)
}
}
}
11 changes: 7 additions & 4 deletions src/main/kotlin/kotlinx/kover/appliers/KoverMergedApplier.kt
Expand Up @@ -178,13 +178,16 @@ private inline fun Project.mergedFilesProvider(


private fun filterProjects(filters: KoverProjectsFilter, allProjects: Iterable<Project>): List<Project> {

val actualProjects = allProjects.filter { it.buildFile.exists() }

if (filters.excludes.isEmpty()) {
return allProjects.toList()
return actualProjects.toList()
}

val projectsByPath = allProjects.associateBy { p -> p.path }.toMutableMap()
val pathsByName = allProjects.associate { it.name to mutableListOf<String>() }
allProjects.forEach { pathsByName.getValue(it.name) += it.path }
val projectsByPath = actualProjects.associateBy { p -> p.path }.toMutableMap()
val pathsByName = actualProjects.associate { it.name to mutableListOf<String>() }
actualProjects.forEach { pathsByName.getValue(it.name) += it.path }

val excludedPaths = filters.excludes.map {
if (it.startsWith(':')) {
Expand Down