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

Added detecting cucumber support to pts scripts #948

Merged
merged 4 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class Capture {
'net.jqwik.engine.JqwikTestEngine' : 'jqwik',
'com.tngtech.archunit.junit.ArchUnitTestEngine' : 'archunit',
'co.helmethair.scalatest.ScalatestEngine' : 'scalatest',
'io.kotest.runner.junit.platform.KotestJunitPlatformTestEngine' : 'kotest-runner'
'io.kotest.runner.junit.platform.KotestJunitPlatformTestEngine' : 'kotest-runner',
'io.cucumber.junit.platform.engine.CucumberTestEngine' : 'cucumber-junit-platform'
]
private Logger logger
private BuildScanExtension buildScanApi
Expand All @@ -48,7 +49,7 @@ class Capture {
if (t.getTestFramework().getClass().getName() == 'org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestFramework') {
def engines = testEngines(t)
buildScanApi.value("${t.identityPath}#engines", "${engines}")
if (!engines.isEmpty() && engines.stream().allMatch { e -> supportedEngines.containsKey(e) }) {
if (ptsSupported(t, engines)) {
buildScanApi.value("${t.identityPath}#pts", 'SUPPORTED')
} else {
buildScanApi.value("${t.identityPath}#pts", 'ENGINES_NOT_ALL_SUPPORTED')
Expand All @@ -58,6 +59,19 @@ class Capture {
}
}

boolean ptsSupported(Test t, Set<String> engines) {
if (!engines.isEmpty() && engines.stream().allMatch { e -> supportedEngines.containsKey(e) }) {
// If cucumber is used without companion it's not supported, otherwise it is.
return !(cucumberUsed(t, engines) && !t.project.plugins.hasPlugin('com.gradle.cucumber.companion'))
erichaagdev marked this conversation as resolved.
Show resolved Hide resolved
} else {
return false
}
}

boolean cucumberUsed(Test t, Set<String> engines) {
return t.classpath.any { f -> f.name.contains('cucumber')} || engines.any { it.contains('cucumber')}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way we can be more specific here and check the group id? I want to prevent another package that has the word cucumber in it from causing confusion here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

}

Set<String> testEngines(Test t) {
try {
Stream<String> engines = t.classpath.files.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ class Capture(val api: BuildScanExtension, val logger: Logger) {
"net.jqwik.engine.JqwikTestEngine" to "jqwik",
"com.tngtech.archunit.junit.ArchUnitTestEngine" to "archunit",
"co.helmethair.scalatest.ScalatestEngine" to "scalatest",
"io.kotest.runner.junit.platform.KotestJunitPlatformTestEngine" to "kotest-runner"
"io.kotest.runner.junit.platform.KotestJunitPlatformTestEngine" to "kotest-runner",
"io.cucumber.junit.platform.engine.CucumberTestEngine" to "cucumber-junit-platform"
)

fun capturePts(t: Test) {
if (t.getTestFramework()::class.java.name == "org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestFramework") {
val engines = testEngines(t)
api.value("${t.identityPath}#engines", "${engines}")
if (!engines.isEmpty() && engines.stream().allMatch { e -> supportedEngines.containsKey(e) }) {
if (ptsSupported(t, engines)) {
api.value("${t.identityPath}#pts", "SUPPORTED")
} else {
api.value("${t.identityPath}#pts", "ENGINES_NOT_ALL_SUPPORTED")
Expand All @@ -54,6 +55,19 @@ class Capture(val api: BuildScanExtension, val logger: Logger) {
}
}

private fun ptsSupported(t: Test, engines: Set<String>): Boolean {
return if (!engines.isEmpty() && engines.stream().allMatch { e -> supportedEngines.containsKey(e) }) {
// If cucumber is used without companion it's not supported, otherwise it is.
!(cucumberUsed(t, engines) && !t.project.plugins.hasPlugin("com.gradle.cucumber.companion"))
} else {
false
}
}

private fun cucumberUsed(t: Test, engines: Set<String>): Boolean {
return t.classpath.any { f -> f.name.contains("cucumber")} || engines.any { it.contains("cucumber")}
}

private fun testEngines(t: Test): Set<String> {
try {
var engines = t.classpath.files.stream().filter { f -> f.name.endsWith(".jar") }
Expand Down