Select runtime with directive in test data file instead of test name in PsiChecker tests
This commit is contained in:
@@ -828,6 +828,20 @@ public class KotlinTestUtils {
|
|||||||
return testClassMetadata.value();
|
return testClassMetadata.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return test data file name specified in the metadata of test method
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public static String getTestDataFileName(@NotNull Class<?> testCaseClass, @NotNull String testName) {
|
||||||
|
try {
|
||||||
|
Method method = testCaseClass.getDeclaredMethod(testName);
|
||||||
|
return getMethodMetadata(method);
|
||||||
|
}
|
||||||
|
catch (NoSuchMethodException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void assertAllTestsPresentByMetadata(
|
public static void assertAllTestsPresentByMetadata(
|
||||||
@NotNull Class<?> testCaseClass,
|
@NotNull Class<?> testCaseClass,
|
||||||
@NotNull File testDataDir,
|
@NotNull File testDataDir,
|
||||||
@@ -898,12 +912,18 @@ public class KotlinTestUtils {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private static String getMethodMetadata(Method method) {
|
||||||
|
TestMetadata testMetadata = method.getAnnotation(TestMetadata.class);
|
||||||
|
return (testMetadata != null) ? testMetadata.value() : null;
|
||||||
|
}
|
||||||
|
|
||||||
private static Set<String> collectMethodsMetadata(Class<?> testCaseClass) {
|
private static Set<String> collectMethodsMetadata(Class<?> testCaseClass) {
|
||||||
Set<String> filePaths = Sets.newHashSet();
|
Set<String> filePaths = Sets.newHashSet();
|
||||||
for (Method method : testCaseClass.getDeclaredMethods()) {
|
for (Method method : testCaseClass.getDeclaredMethods()) {
|
||||||
TestMetadata testMetadata = method.getAnnotation(TestMetadata.class);
|
String path = getMethodMetadata(method);
|
||||||
if (testMetadata != null) {
|
if (path != null) {
|
||||||
filePaths.add(testMetadata.value());
|
filePaths.add(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return filePaths;
|
return filePaths;
|
||||||
|
|||||||
+1
-1
@@ -128,7 +128,7 @@ abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFix
|
|||||||
protected fun isAllFilesPresentInTest(): Boolean = KotlinTestUtils.isAllFilesPresentTest(getTestName(false))
|
protected fun isAllFilesPresentInTest(): Boolean = KotlinTestUtils.isAllFilesPresentTest(getTestName(false))
|
||||||
|
|
||||||
protected open fun fileName(): String
|
protected open fun fileName(): String
|
||||||
= getTestName(false) + ".kt"
|
= KotlinTestUtils.getTestDataFileName(this.javaClass, this.name) ?: (getTestName(false) + ".kt")
|
||||||
|
|
||||||
protected fun performNotWriteEditorAction(actionId: String): Boolean {
|
protected fun performNotWriteEditorAction(actionId: String): Boolean {
|
||||||
val dataContext = (myFixture.editor as EditorEx).dataContext
|
val dataContext = (myFixture.editor as EditorEx).dataContext
|
||||||
|
|||||||
+3
-2
@@ -1,3 +1,4 @@
|
|||||||
|
// RUNTIME
|
||||||
fun none() {}
|
fun none() {}
|
||||||
|
|
||||||
fun unitEmptyInfer() {}
|
fun unitEmptyInfer() {}
|
||||||
@@ -16,8 +17,8 @@ fun bbb() {
|
|||||||
fun foo(<warning>expr</warning>: StringBuilder): Int {
|
fun foo(<warning>expr</warning>: StringBuilder): Int {
|
||||||
val c = 'a'
|
val c = 'a'
|
||||||
when(c) {
|
when(c) {
|
||||||
0.toChar() -> throw Throwable("zero")
|
0.toChar() -> throw Exception("zero")
|
||||||
else -> throw Throwable("nonzero" + c)
|
else -> throw Exception("nonzero" + c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// RUNTIME
|
||||||
<error descr="[WRONG_ANNOTATION_TARGET] This annotation is not applicable to target 'class'">@JvmStatic</error>
|
<error descr="[WRONG_ANNOTATION_TARGET] This annotation is not applicable to target 'class'">@JvmStatic</error>
|
||||||
class A {
|
class A {
|
||||||
<error descr="[WRONG_ANNOTATION_TARGET] This annotation is not applicable to target 'companion object'">@JvmStatic</error>
|
<error descr="[WRONG_ANNOTATION_TARGET] This annotation is not applicable to target 'companion object'">@JvmStatic</error>
|
||||||
|
|||||||
Vendored
+1
@@ -1,3 +1,4 @@
|
|||||||
|
// RUNTIME
|
||||||
@file:JvmName("TopLevelMultifile")
|
@file:JvmName("TopLevelMultifile")
|
||||||
@file:JvmMultifileClass
|
@file:JvmMultifileClass
|
||||||
package test
|
package test
|
||||||
|
|||||||
+4
-3
@@ -1,3 +1,4 @@
|
|||||||
|
// RUNTIME
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
import java.io.*
|
import java.io.*
|
||||||
@@ -9,15 +10,15 @@ fun takeFirst(expr: StringBuilder): Char {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun evaluateArg(expr: CharSequence, numbers: ArrayList<Int>): Int {
|
fun evaluateArg(expr: CharSequence, numbers: ArrayList<Int>): Int {
|
||||||
if (expr.length == 0) throw Throwable("Syntax error: Character expected");
|
if (expr.length == 0) throw Exception("Syntax error: Character expected");
|
||||||
val c = takeFirst(<error>expr</error>)
|
val c = takeFirst(<error>expr</error>)
|
||||||
if (c >= '0' && c <= '9') {
|
if (c >= '0' && c <= '9') {
|
||||||
val n = c - '0'
|
val n = c - '0'
|
||||||
if (!numbers.contains(n)) throw Throwable("You used incorrect number: " + n)
|
if (!numbers.contains(n)) throw Exception("You used incorrect number: " + n)
|
||||||
numbers.remove(n)
|
numbers.remove(n)
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
throw Throwable("Syntax error: Unrecognized character " + c)
|
throw Exception("Syntax error: Unrecognized character " + c)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun evaluateAdd(expr: StringBuilder, numbers: ArrayList<Int>): Int {
|
fun evaluateAdd(expr: StringBuilder, numbers: ArrayList<Int>): Int {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.psi.KtDeclaration;
|
|||||||
import org.jetbrains.kotlin.psi.KtFile;
|
import org.jetbrains.kotlin.psi.KtFile;
|
||||||
import org.jetbrains.kotlin.psi.KtTreeVisitorVoid;
|
import org.jetbrains.kotlin.psi.KtTreeVisitorVoid;
|
||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode;
|
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode;
|
||||||
|
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
@@ -90,9 +91,9 @@ public abstract class AbstractPsiCheckerTest extends KotlinLightCodeInsightFixtu
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
@Override
|
||||||
protected LightProjectDescriptor getProjectDescriptor() {
|
protected String getTestDataPath() {
|
||||||
return getProjectDescriptorFromTestName();
|
return KotlinTestUtils.getTestsRoot(this.getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
package org.jetbrains.kotlin.checkers
|
package org.jetbrains.kotlin.checkers
|
||||||
|
|
||||||
import com.intellij.codeInspection.ex.EntryPointsManagerBase
|
import com.intellij.codeInspection.ex.EntryPointsManagerBase
|
||||||
|
import com.intellij.testFramework.LightProjectDescriptor
|
||||||
|
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||||
|
|
||||||
class PsiCheckerCustomTest : AbstractPsiCheckerTest() {
|
class PsiCheckerCustomTest : AbstractPsiCheckerTest() {
|
||||||
fun testNoUnusedParameterWhenCustom() {
|
fun testNoUnusedParameterWhenCustom() {
|
||||||
@@ -41,4 +43,8 @@ class PsiCheckerCustomTest : AbstractPsiCheckerTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getTestDataFile(localName: String) = "idea/testData/checker/custom/$localName"
|
private fun getTestDataFile(localName: String) = "idea/testData/checker/custom/$localName"
|
||||||
|
|
||||||
|
override fun getTestDataPath(): String = KotlinTestUtils.getHomeDirectory()
|
||||||
|
|
||||||
|
override fun getProjectDescriptor(): LightProjectDescriptor = getProjectDescriptorFromTestName()
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user