mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
[jvm] IJ-CR-27265 Support Kotlin stdlib assertions in 'TestWithoutAssertions' inspection
GitOrigin-RevId: 011d04d671ccf8a8125d9787f6adfc72c666fcb4
This commit is contained in:
committed by
intellij-monorepo-bot
parent
5bc13c84f9
commit
7ac0a00b4d
@@ -45,6 +45,8 @@ class TestMethodWithoutAssertionInspection : AbstractBaseUastLocalInspectionTool
|
||||
.add("org.junit.rules.ExpectedException", "expect.*")
|
||||
.add(ORG_HAMCREST_MATCHER_ASSERT, "assertThat")
|
||||
.add("mockit.Verifications", "Verifications")
|
||||
.add("kotlin.PreconditionsKt__AssertionsJVMKt", "assert")
|
||||
.add("kotlin.test.AssertionsKt__AssertionsKt", "assert.*|fail.*|expect")
|
||||
.finishDefault()
|
||||
|
||||
override fun createOptionsPanel(): JComponent? {
|
||||
@@ -110,7 +112,7 @@ private class TestMethodWithoutAssertionVisitor(
|
||||
else -> method.uastBody
|
||||
} ?: return false
|
||||
val callExpression = lastExpression.castSafelyTo<UCallExpression>() ?: return false
|
||||
val targetMethod = callExpression.resolve()?.toUElementOfType<UMethod>() ?: return false
|
||||
val targetMethod = callExpression.resolveToUElement()?.castSafelyTo<UMethod>() ?: return false
|
||||
return containsAssertion(targetMethod)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.intellij.codeInspection.tests.test.TestMethodWithoutAssertionInspecti
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.roots.ContentEntry
|
||||
import com.intellij.openapi.roots.ModifiableRootModel
|
||||
import com.intellij.project.IntelliJProjectConfiguration
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
import com.intellij.testFramework.PsiTestUtil
|
||||
import com.intellij.util.PathUtil
|
||||
@@ -14,8 +15,10 @@ class KotlinTestMethodWithoutAssertionInspectionTest : TestMethodWithoutAssertio
|
||||
override fun getProjectDescriptor(): LightProjectDescriptor = object : JUnitProjectDescriptor(sdkLevel) {
|
||||
override fun configureModule(module: Module, model: ModifiableRootModel, contentEntry: ContentEntry) {
|
||||
super.configureModule(module, model, contentEntry)
|
||||
val jar = File(PathUtil.getJarPathForClass(JvmStatic::class.java))
|
||||
PsiTestUtil.addLibrary(model, "kotlin-stdlib", jar.parent, jar.name)
|
||||
val stdLibJar = File(PathUtil.getJarPathForClass(JvmStatic::class.java))
|
||||
PsiTestUtil.addLibrary(model, "kotlin-stdlib", stdLibJar.parent, stdLibJar.name)
|
||||
val ktTestJar = File(IntelliJProjectConfiguration.getProjectLibraryClassesRootPaths("kotlin-test").first())
|
||||
PsiTestUtil.addLibrary(model, "kotlin-test", ktTestJar.parent, ktTestJar.name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,12 +48,12 @@ class KotlinTestMethodWithoutAssertionInspectionTest : TestMethodWithoutAssertio
|
||||
import mockit.*
|
||||
|
||||
class TestMethodWithoutAssertion : TestCase() {
|
||||
//@Test
|
||||
//public fun fourOhTest2() { Assert.assertTrue(true) }
|
||||
//
|
||||
//public fun test2() { assertTrue(true) }
|
||||
//
|
||||
//public fun test3() { fail() }
|
||||
@Test
|
||||
public fun fourOhTest2() { Assert.assertTrue(true) }
|
||||
|
||||
public fun test2() { assertTrue(true) }
|
||||
|
||||
public fun test3() { fail() }
|
||||
|
||||
@Test
|
||||
public fun delegateOnly() { check() }
|
||||
@@ -79,4 +82,19 @@ class KotlinTestMethodWithoutAssertionInspectionTest : TestMethodWithoutAssertio
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test no highlighting kotlin stdlib assertion`() {
|
||||
myFixture.testHighlighting(ULanguage.KOTLIN, """
|
||||
import org.junit.Test
|
||||
import kotlin.test.*
|
||||
|
||||
class TestMethodWithAssertion {
|
||||
@Test
|
||||
public fun ktPrecondition1() { assert(true) }
|
||||
|
||||
@Test
|
||||
public fun ktTestAssertion1() { assertTrue(true) }
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user