Skip to content

Commit b428d27

Browse files
Limit the test generator to kotest only (#373)
Co-authored-by: Sam <[email protected]>
1 parent 188e156 commit b428d27

File tree

3 files changed

+22
-41
lines changed

3 files changed

+22
-41
lines changed

build.gradle.kts

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,10 @@ data class PluginDescriptor(
3232

3333
val descriptors = listOf(
3434
PluginDescriptor(
35-
since = "242.*", // this version is 2024.2.x
36-
until = "243.*",
37-
sdkVersion = "2024.2.2",
38-
sourceFolder = "IC-242",
39-
useInstaller = true,
40-
jdkTarget = JavaVersion.VERSION_17,
41-
),
42-
PluginDescriptor(
43-
since = "243.*", // this version is 2024.3.x
44-
until = "251.*",
45-
sdkVersion = "2024.3.1",
46-
sourceFolder = "IC-243",
47-
useInstaller = true,
48-
jdkTarget = JavaVersion.VERSION_17,
49-
),
50-
PluginDescriptor(
51-
since = "251.*", // this version is 2025.1.x
52-
until = "252.*",
53-
sdkVersion = "2025.1",
54-
sourceFolder = "IC-251",
35+
since = "252.*", // this version is 2025.2.x
36+
until = "261.*",
37+
sdkVersion = "2025.2",
38+
sourceFolder = "IC-252",
5539
useInstaller = true,
5640
jdkTarget = JavaVersion.VERSION_21,
5741
),
@@ -65,7 +49,7 @@ val descriptors = listOf(
6549
),
6650
)
6751

68-
val productName = System.getenv("PRODUCT_NAME") ?: "IC-251"
52+
val productName = System.getenv("PRODUCT_NAME") ?: "IC-252"
6953
val descriptor: PluginDescriptor = descriptors.first { it.sourceFolder == productName }
7054
val jvmTargetVersion: String = System.getenv("JVM_TARGET") ?: descriptor.jdkTarget.majorVersion
7155

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[versions]
2+
kotlin = "2.2.0"
23
runtime-kotest = "4.2.0"
34
# We separate these from the actual runtime dependencies
45
test-kotest = "5.9.1"

src/main/kotlin/io/kotest/plugin/intellij/tests/KotestTestGenerator.kt

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import com.intellij.psi.PsiFile
1313
import com.intellij.psi.impl.source.PostprocessReformattingAspect
1414
import com.intellij.refactoring.util.classMembers.MemberInfo
1515
import com.intellij.testIntegration.createTest.CreateTestDialog
16-
import com.intellij.testIntegration.createTest.JavaTestGenerator
16+
import com.intellij.testIntegration.createTest.TestGenerator
1717
import com.intellij.util.concurrency.annotations.RequiresReadLock
1818
import io.kotest.plugin.intellij.Constants
1919
import io.kotest.plugin.intellij.KotestTestFramework
@@ -27,32 +27,28 @@ import org.jetbrains.kotlin.idea.KotlinLanguage
2727
import org.jetbrains.kotlin.idea.refactoring.memberInfo.toKotlinMemberInfo
2828
import org.jetbrains.kotlin.name.FqName
2929
import java.util.Properties
30-
3130
/**
3231
* Used to create "Template" test class files.
3332
*/
34-
class KotestTestGenerator : JavaTestGenerator() {
33+
class KotestTestGenerator : TestGenerator {
3534

3635
override fun toString(): String = KotlinLanguage.INSTANCE.displayName
3736

38-
override fun generateTest(project: Project, d: CreateTestDialog): PsiElement? {
39-
// I do not currently know how to limit the test generator to only kotest, therefore we can check
40-
// the framework name and delegate to the JavaTestGenerator one. But this only works while JavaTestGenerator
41-
// is public, and has a zero arg constructor, so I would like to find a better long term solution:
42-
// https://intellij-support.jetbrains.com/hc/en-us/community/posts/15040678418450-How-to-choose-when-to-apply-TestGenerator
43-
if (d.selectedTestFrameworkDescriptor.name != Constants.FRAMEWORK_NAME)
44-
return super.generateTest(project, d)
45-
return PostprocessReformattingAspect.getInstance(project).postponeFormattingInside(Computable {
46-
ApplicationManager.getApplication().runWriteAction(Computable<PsiElement?> {
47-
val file = generateTestFile(project, d)
48-
if (file != null) {
49-
// without this the file is created but the caret stays in the original file
50-
CodeInsightUtil.positionCursor(project, file, file)
51-
}
52-
file
37+
override fun generateTest(project: Project, d: CreateTestDialog): PsiElement? =
38+
if (d.selectedTestFrameworkDescriptor.name == Constants.FRAMEWORK_NAME) {
39+
PostprocessReformattingAspect.getInstance(project).postponeFormattingInside(Computable {
40+
ApplicationManager.getApplication().runWriteAction(Computable<PsiElement?> {
41+
val file = generateTestFile(project, d)
42+
if (file != null) {
43+
// without this the file is created but the caret stays in the original file
44+
CodeInsightUtil.positionCursor(project, file, file)
45+
}
46+
file
47+
})
5348
})
54-
})
55-
}
49+
} else {
50+
null
51+
}
5652

5753
private fun styleForSuperClass(fqn: FqName): SpecStyle =
5854
SpecStyle.Companion.styles.find { it.fqn() == fqn } ?: FunSpecStyle

0 commit comments

Comments
 (0)