From 0e2bdb8e6646667c12d0afc46485d4f2bb8ada45 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 14 Jun 2017 12:09:46 +0200 Subject: [PATCH] Support CONFIGURE_LIBRARY directive in intention tests Also restore tests for ConvertCamelCaseTestFunctionToSpaced and apply fix for KT-18375 --- ...tCamelCaseTestFunctionToSpacedIntention.kt | 2 +- .../letters.kt | 10 +++++++ .../letters.kt.after | 10 +++++++ .../letters.kt_ignored | 12 -------- .../nonLetters.kt | 10 +++++++ .../nonLetters.kt.after | 10 +++++++ .../nonLetters.kt_ignored | 12 -------- .../unchanged.kt | 8 +++++ .../unchanged.kt_ignored | 10 ------- .../formatter/FormatterTestGenerated.java | 12 ++++---- .../idea/intentions/AbstractIntentionTest.kt | 29 ++++++++++++------- .../intentions/IntentionTestGenerated.java | 18 ++++++++++++ 12 files changed, 92 insertions(+), 51 deletions(-) create mode 100644 idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/letters.kt create mode 100644 idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/letters.kt.after delete mode 100644 idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/letters.kt_ignored create mode 100644 idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/nonLetters.kt create mode 100644 idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/nonLetters.kt.after delete mode 100644 idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/nonLetters.kt_ignored create mode 100644 idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/unchanged.kt delete mode 100644 idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/unchanged.kt_ignored diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertCamelCaseTestFunctionToSpacedIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertCamelCaseTestFunctionToSpacedIntention.kt index d150256bb6a..5b4ac9d28cf 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertCamelCaseTestFunctionToSpacedIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertCamelCaseTestFunctionToSpacedIntention.kt @@ -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 diff --git a/idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/letters.kt b/idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/letters.kt new file mode 100644 index 00000000000..f2d77798d58 --- /dev/null +++ b/idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/letters.kt @@ -0,0 +1,10 @@ +// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar +import org.junit.Test + +class A { + @Test fun testTwoPlusTwoEqualsFour() {} +} + +fun test() { + A().testTwoPlusTwoEqualsFour() +} \ No newline at end of file diff --git a/idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/letters.kt.after b/idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/letters.kt.after new file mode 100644 index 00000000000..bf442c2cb5b --- /dev/null +++ b/idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/letters.kt.after @@ -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`() +} \ No newline at end of file diff --git a/idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/letters.kt_ignored b/idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/letters.kt_ignored deleted file mode 100644 index 205868cb33d..00000000000 --- a/idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/letters.kt_ignored +++ /dev/null @@ -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 testTwoPlusTwoEqualsFour() {} -} - -fun test() { - A().testTwoPlusTwoEqualsFour() -} \ No newline at end of file diff --git a/idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/nonLetters.kt b/idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/nonLetters.kt new file mode 100644 index 00000000000..7e00ae40b22 --- /dev/null +++ b/idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/nonLetters.kt @@ -0,0 +1,10 @@ +// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar +import org.junit.Test + +class A { + @Test fun `testTwo + Two==Four`() {} +} + +fun test() { + A().`testTwo + Two==Four`() +} \ No newline at end of file diff --git a/idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/nonLetters.kt.after b/idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/nonLetters.kt.after new file mode 100644 index 00000000000..d874be4bc57 --- /dev/null +++ b/idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/nonLetters.kt.after @@ -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`() +} \ No newline at end of file diff --git a/idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/nonLetters.kt_ignored b/idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/nonLetters.kt_ignored deleted file mode 100644 index 4cbf550fbb3..00000000000 --- a/idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/nonLetters.kt_ignored +++ /dev/null @@ -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 `testTwo + Two==Four`() {} -} - -fun test() { - A().`testTwo + Two==Four`() -} \ No newline at end of file diff --git a/idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/unchanged.kt b/idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/unchanged.kt new file mode 100644 index 00000000000..454f4bfabf9 --- /dev/null +++ b/idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/unchanged.kt @@ -0,0 +1,8 @@ +// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar +// IS_APPLICABLE: false + +import org.junit.Test + +class A { + @Test fun `foo bar`() {} +} \ No newline at end of file diff --git a/idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/unchanged.kt_ignored b/idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/unchanged.kt_ignored deleted file mode 100644 index 7825ab491ff..00000000000 --- a/idea/testData/intentions/convertCamelCaseTestFunctionToSpaced/unchanged.kt_ignored +++ /dev/null @@ -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 `foo bar`() {} -} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java b/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java index 600510de62e..22f93f39ed4 100644 --- a/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java @@ -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"); diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/AbstractIntentionTest.kt b/idea/tests/org/jetbrains/kotlin/idea/intentions/AbstractIntentionTest.kt index 71062f89a25..7509bd51c0d 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/AbstractIntentionTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/AbstractIntentionTest.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("\"\" is missing in file \"$mainFile\"", fileText.contains("")) + ConfigLibraryUtil.configureLibrariesByDirective(myModule, PlatformTestUtil.getCommunityPath(), fileText) - val minJavaVersion = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// MIN_JAVA_VERSION: ") - if (minJavaVersion != null && !SystemInfo.isJavaVersionAtLeast(minJavaVersion)) return + try { + TestCase.assertTrue("\"\" is missing in file \"$mainFile\"", fileText.contains("")) - 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) } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index 392be935151..0f982eeb5e9 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -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")