Support CONFIGURE_LIBRARY directive in intention tests

Also restore tests for ConvertCamelCaseTestFunctionToSpaced
and apply fix for KT-18375
This commit is contained in:
Dmitry Jemerov
2017-06-14 12:09:46 +02:00
parent 4fa75256b7
commit 0e2bdb8e66
12 changed files with 92 additions and 51 deletions
@@ -42,7 +42,7 @@ class ConvertCamelCaseTestFunctionToSpacedIntention : SelfTargetingRangeIntentio
val name = element.name ?: return null
val newName = decamelize(name)
if (newName == name) return null
if (newName == name.quoteIfNeeded()) return null
val lightMethod = element.toLightMethods().firstOrNull() ?: return null
if (!TestFrameworks.getInstance().isTestMethod(lightMethod)) return null
@@ -0,0 +1,10 @@
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
import org.junit.Test
class A {
@Test fun <caret>testTwoPlusTwoEqualsFour() {}
}
fun test() {
A().testTwoPlusTwoEqualsFour()
}
@@ -0,0 +1,10 @@
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
import org.junit.Test
class A {
@Test fun `test two plus two equals four`() {}
}
fun test() {
A().`test two plus two equals four`()
}
@@ -1,12 +0,0 @@
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
// ERROR: Cannot access class 'java.lang.Class'. Check your module classpath for missing or conflicting dependencies
// ERROR: This annotation is not applicable to target 'member function'
import org.junit.Test
class A {
@Test fun <caret>testTwoPlusTwoEqualsFour() {}
}
fun test() {
A().testTwoPlusTwoEqualsFour()
}
@@ -0,0 +1,10 @@
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
import org.junit.Test
class A {
@Test fun <caret>`testTwo + Two==Four`() {}
}
fun test() {
A().`testTwo + Two==Four`()
}
@@ -0,0 +1,10 @@
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
import org.junit.Test
class A {
@Test fun `test two + two == four`() {}
}
fun test() {
A().`test two + two == four`()
}
@@ -1,12 +0,0 @@
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
// ERROR: Cannot access class 'java.lang.Class'. Check your module classpath for missing or conflicting dependencies
// ERROR: This annotation is not applicable to target 'member function'
import org.junit.Test
class A {
@Test fun <caret>`testTwo + Two==Four`() {}
}
fun test() {
A().`testTwo + Two==Four`()
}
@@ -0,0 +1,8 @@
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
// IS_APPLICABLE: false
import org.junit.Test
class A {
@Test fun `<caret>foo bar`() {}
}
@@ -1,10 +0,0 @@
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
// ERROR: Cannot access class 'java.lang.Class'. Check your module classpath for missing or conflicting dependencies
// ERROR: This annotation is not applicable to target 'member function'
// IS_APPLICABLE: false
import org.junit.Test
class A {
@Test fun `<caret>foo bar`() {}
}
@@ -662,6 +662,12 @@ public class FormatterTestGenerated extends AbstractFormatterTest {
doTest(fileName);
}
@TestMetadata("SpaceBeforeIfParentheses.after.kt")
public void testSpaceBeforeIfParentheses() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/SpaceBeforeIfParentheses.after.kt");
doTest(fileName);
}
@TestMetadata("SpaceBeforeIndices.after.kt")
public void testSpaceBeforeIndices() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/SpaceBeforeIndices.after.kt");
@@ -674,12 +680,6 @@ public class FormatterTestGenerated extends AbstractFormatterTest {
doTest(fileName);
}
@TestMetadata("SpaceBeforeIfParentheses.after.kt")
public void testSpaceBeforeIfParentheses() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/SpaceBeforeIfParentheses.after.kt");
doTest(fileName);
}
@TestMetadata("SpaceBeforeWhenParentheses.after.kt")
public void testSpaceBeforeWhenParentheses() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/SpaceBeforeWhenParentheses.after.kt");
@@ -26,8 +26,10 @@ import com.intellij.openapi.util.text.StringUtil
import com.intellij.psi.PsiFile
import com.intellij.refactoring.BaseRefactoringProcessor
import com.intellij.refactoring.util.CommonRefactoringUtil
import com.intellij.testFramework.PlatformTestUtil
import junit.framework.ComparisonFailure
import junit.framework.TestCase
import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil
import org.jetbrains.kotlin.idea.test.DirectiveBasedActionUtils
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
@@ -99,19 +101,26 @@ abstract class AbstractIntentionTest : KotlinLightCodeInsightFixtureTestCase() {
val fileText = FileUtil.loadFile(mainFile, true)
TestCase.assertTrue("\"<caret>\" is missing in file \"$mainFile\"", fileText.contains("<caret>"))
ConfigLibraryUtil.configureLibrariesByDirective(myModule, PlatformTestUtil.getCommunityPath(), fileText)
val minJavaVersion = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// MIN_JAVA_VERSION: ")
if (minJavaVersion != null && !SystemInfo.isJavaVersionAtLeast(minJavaVersion)) return
try {
TestCase.assertTrue("\"<caret>\" is missing in file \"$mainFile\"", fileText.contains("<caret>"))
if (file is KtFile && !InTextDirectivesUtils.isDirectiveDefined(fileText, "// SKIP_ERRORS_BEFORE")) {
DirectiveBasedActionUtils.checkForUnexpectedErrors(file as KtFile)
val minJavaVersion = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// MIN_JAVA_VERSION: ")
if (minJavaVersion != null && !SystemInfo.isJavaVersionAtLeast(minJavaVersion)) return
if (file is KtFile && !InTextDirectivesUtils.isDirectiveDefined(fileText, "// SKIP_ERRORS_BEFORE")) {
DirectiveBasedActionUtils.checkForUnexpectedErrors(file as KtFile)
}
doTestFor(mainFile.name, pathToFiles, intentionAction, fileText)
if (file is KtFile && !InTextDirectivesUtils.isDirectiveDefined(fileText, "// SKIP_ERRORS_AFTER")) {
DirectiveBasedActionUtils.checkForUnexpectedErrors(file as KtFile)
}
}
doTestFor(mainFile.name, pathToFiles, intentionAction, fileText)
if (file is KtFile && !InTextDirectivesUtils.isDirectiveDefined(fileText, "// SKIP_ERRORS_AFTER")) {
DirectiveBasedActionUtils.checkForUnexpectedErrors(file as KtFile)
finally {
ConfigLibraryUtil.unconfigureLibrariesByDirective(myModule, fileText)
}
}
@@ -3992,12 +3992,24 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/convertCamelCaseTestFunctionToSpaced"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("letters.kt")
public void testLetters() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/letters.kt");
doTest(fileName);
}
@TestMetadata("nonFunction.kt")
public void testNonFunction() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/nonFunction.kt");
doTest(fileName);
}
@TestMetadata("nonLetters.kt")
public void testNonLetters() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/nonLetters.kt");
doTest(fileName);
}
@TestMetadata("notAtIdentifier.kt")
public void testNotAtIdentifier() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/notAtIdentifier.kt");
@@ -4009,6 +4021,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/notTestFunction.kt");
doTest(fileName);
}
@TestMetadata("unchanged.kt")
public void testUnchanged() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/unchanged.kt");
doTest(fileName);
}
}
@TestMetadata("idea/testData/intentions/convertEnumToSealedClass")