diff --git a/annotations/com/intellij/testFramework/fixtures/annotations.xml b/annotations/com/intellij/testFramework/fixtures/annotations.xml index 409755505e2..b8f79647ddc 100644 --- a/annotations/com/intellij/testFramework/fixtures/annotations.xml +++ b/annotations/com/intellij/testFramework/fixtures/annotations.xml @@ -1,5 +1,6 @@ - + @@ -7,4 +8,10 @@ + + + + + + \ No newline at end of file diff --git a/annotations/com/intellij/testFramework/fixtures/impl/annotations.xml b/annotations/com/intellij/testFramework/fixtures/impl/annotations.xml new file mode 100644 index 00000000000..64a9d7312f2 --- /dev/null +++ b/annotations/com/intellij/testFramework/fixtures/impl/annotations.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt index 3014280c0a4..f4736a964cb 100644 --- a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt @@ -391,7 +391,7 @@ fun main(args: Array) { } testClass(javaClass()) { - model("codeInsight/inspections", extension = null, recursive = false) + model("intentions", pattern = "^(inspections\\.test)$", singleClass = true) } testClass(javaClass()) { diff --git a/idea/testData/codeInsight/inspections/replaceGet/expected.xml b/idea/testData/codeInsight/inspections/replaceGet/expected.xml deleted file mode 100644 index e0440b9c359..00000000000 --- a/idea/testData/codeInsight/inspections/replaceGet/expected.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - main.kt - 3 - light_idea_test_case - - Explicit 'get' - Replace 'get' call with index operator - - \ No newline at end of file diff --git a/idea/testData/codeInsight/inspections/replaceGet/src/main.kt b/idea/testData/codeInsight/inspections/replaceGet/src/main.kt deleted file mode 100644 index 1d0f1ba3c10..00000000000 --- a/idea/testData/codeInsight/inspections/replaceGet/src/main.kt +++ /dev/null @@ -1,4 +0,0 @@ -fun foo() { - val a = Array(10) { it } - println(a.get(5)) -} \ No newline at end of file diff --git a/idea/testData/intentions/attributeCallReplacements/replaceGetIntention/inspectionData/expected.xml b/idea/testData/intentions/attributeCallReplacements/replaceGetIntention/inspectionData/expected.xml new file mode 100644 index 00000000000..5c12ac8ae17 --- /dev/null +++ b/idea/testData/intentions/attributeCallReplacements/replaceGetIntention/inspectionData/expected.xml @@ -0,0 +1,127 @@ + + + unnamedAndNamed.kt + 6 + light_idea_test_case + + Explicit 'get' + Replace 'get' call with index operator + + + + unacceptableVararg.kt + 7 + light_idea_test_case + + Explicit 'get' + Replace 'get' call with index operator + + + + singleNamedArgument.kt + 6 + light_idea_test_case + + Explicit 'get' + Replace 'get' call with index operator + + + + singleArgument.kt + 6 + light_idea_test_case + + Explicit 'get' + Replace 'get' call with index operator + + + + namedAndFunction.kt + 6 + light_idea_test_case + + Explicit 'get' + Replace 'get' call with index operator + + + + multiArgument.kt + 6 + light_idea_test_case + + Explicit 'get' + Replace 'get' call with index operator + + + + missingDefaultArgument.kt + 7 + light_idea_test_case + + Explicit 'get' + Replace 'get' call with index operator + + + + missingArgument.kt + 8 + light_idea_test_case + + Explicit 'get' + Replace 'get' call with index operator + + + + invalidArgument.kt + 8 + light_idea_test_case + + Explicit 'get' + Replace 'get' call with index operator + + + + functionalArgument.kt + 6 + light_idea_test_case + + Explicit 'get' + Replace 'get' call with index operator + + + + extensionFunction.kt + 6 + light_idea_test_case + + Explicit 'get' + Replace 'get' call with index operator + + + + duplicateArguments.kt + 9 + light_idea_test_case + + Explicit 'get' + Replace 'get' call with index operator + + + + argumentAndFunction.kt + 6 + light_idea_test_case + + Explicit 'get' + Replace 'get' call with index operator + + + + acceptableVararg.kt + 6 + light_idea_test_case + + Explicit 'get' + Replace 'get' call with index operator + + \ No newline at end of file diff --git a/idea/testData/codeInsight/inspections/replaceGet/options.test b/idea/testData/intentions/attributeCallReplacements/replaceGetIntention/inspectionData/inspections.test similarity index 100% rename from idea/testData/codeInsight/inspections/replaceGet/options.test rename to idea/testData/intentions/attributeCallReplacements/replaceGetIntention/inspectionData/inspections.test diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/AbstractJetInspectionTest.kt b/idea/tests/org/jetbrains/jet/plugin/codeInsight/AbstractJetInspectionTest.kt index 57272cbf0b1..9bfbd1a4c35 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/AbstractJetInspectionTest.kt +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/AbstractJetInspectionTest.kt @@ -23,24 +23,42 @@ import com.intellij.codeInspection.LocalInspectionTool import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase import com.intellij.testFramework.LightProjectDescriptor import org.jetbrains.jet.plugin.JetLightProjectDescriptor -import org.jetbrains.jet.plugin.PluginTestCaseBase -import com.intellij.codeInspection.InspectionEP import com.intellij.codeInspection.ex.LocalInspectionToolWrapper +import com.intellij.analysis.AnalysisScope +import com.intellij.codeInspection.ex.InspectionManagerEx +import com.intellij.testFramework.InspectionTestUtil +import com.intellij.codeInspection.InspectionManager +import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl +import org.jetbrains.jet.JetTestCaseBuilder public abstract class AbstractJetInspectionTest: LightCodeInsightFixtureTestCase() { override fun getProjectDescriptor(): LightProjectDescriptor = JetLightProjectDescriptor.INSTANCE - override fun setUp() { - super.setUp() - myFixture!!.setTestDataPath("${PluginTestCaseBase.getTestDataPathBase()}/codeInsight/inspections") - } - protected fun doTest(path: String) { - val testDir = File(path).getName() + val optionsFile = File(path) + val options = FileUtil.loadFile(optionsFile, true) - val options = FileUtil.loadFile(File(path, "options.test"), true) val inspectionClass = Class.forName(InTextDirectivesUtils.findStringWithPrefixes(options, "// INSPECTION_CLASS: ")!!) + val toolWrapper = LocalInspectionToolWrapper(inspectionClass.newInstance() as LocalInspectionTool) - myFixture!!.testInspection(testDir, LocalInspectionToolWrapper(inspectionClass.newInstance() as LocalInspectionTool)) + val inspectionsTestDir = optionsFile.getParentFile()!! + val srcDir = inspectionsTestDir.getParentFile()!! + + with(myFixture!!) { + setTestDataPath("${JetTestCaseBuilder.getHomeDirectory()}/$srcDir") + + val virtualFiles = srcDir + .listFiles { it.getName().endsWith(".kt") }!! + .map { configureByFile(it.getName())!!.getVirtualFile()!! } + + val scope = AnalysisScope(getProject(), virtualFiles) + scope.invalidate() + + val inspectionManager = (InspectionManager.getInstance(getProject()) as InspectionManagerEx) + val globalContext = CodeInsightTestFixtureImpl.createGlobalContextForTool(scope, getProject(), inspectionManager, toolWrapper) + + InspectionTestUtil.runTool(toolWrapper, scope, globalContext, inspectionManager) + InspectionTestUtil.compareToolResults(globalContext, toolWrapper, false, inspectionsTestDir.getPath()) + } } } diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/JetInspectionTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/JetInspectionTestGenerated.java index ba2e3323023..8c31f4c530e 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/JetInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/JetInspectionTestGenerated.java @@ -30,15 +30,15 @@ import org.jetbrains.jet.plugin.codeInsight.AbstractJetInspectionTest; /** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ @SuppressWarnings("all") -@TestMetadata("idea/testData/codeInsight/inspections") +@TestMetadata("idea/testData/intentions") public class JetInspectionTestGenerated extends AbstractJetInspectionTest { - public void testAllFilesPresentInInspections() throws Exception { - JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/codeInsight/inspections"), Pattern.compile("^([^\\.]+)$"), false); + public void testAllFilesPresentInIntentions() throws Exception { + JetTestUtils.assertAllTestsPresentInSingleGeneratedClass(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/intentions"), Pattern.compile("^(inspections\\.test)$")); } - @TestMetadata("replaceGet") - public void testReplaceGet() throws Exception { - doTest("idea/testData/codeInsight/inspections/replaceGet"); + @TestMetadata("attributeCallReplacements/replaceGetIntention/inspectionData/inspections.test") + public void testAttributeCallReplacements_replaceGetIntention_inspectionData_Inspections_test() throws Exception { + doTest("idea/testData/intentions/attributeCallReplacements/replaceGetIntention/inspectionData/inspections.test"); } } diff --git a/idea/tests/org/jetbrains/jet/plugin/intentions/CodeTransformationTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/intentions/CodeTransformationTestGenerated.java index dbaee1285b4..c6eeda86bcb 100644 --- a/idea/tests/org/jetbrains/jet/plugin/intentions/CodeTransformationTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/intentions/CodeTransformationTestGenerated.java @@ -2193,6 +2193,7 @@ public class CodeTransformationTestGenerated extends AbstractCodeTransformationT } @TestMetadata("idea/testData/intentions/attributeCallReplacements/replaceGetIntention") + @InnerTestClasses({}) public static class ReplaceGetIntention extends AbstractCodeTransformationTest { @TestMetadata("acceptableVararg.kt") public void testAcceptableVararg() throws Exception { @@ -2278,6 +2279,11 @@ public class CodeTransformationTestGenerated extends AbstractCodeTransformationT doTestReplaceGetIntention("idea/testData/intentions/attributeCallReplacements/replaceGetIntention/unnamedAndNamed.kt"); } + public static Test innerSuite() { + TestSuite suite = new TestSuite("ReplaceGetIntention"); + suite.addTestSuite(ReplaceGetIntention.class); + return suite; + } } @TestMetadata("idea/testData/intentions/attributeCallReplacements/replaceContainsIntention") @@ -3210,7 +3216,7 @@ public class CodeTransformationTestGenerated extends AbstractCodeTransformationT suite.addTestSuite(ReplaceItWithExplicitFunctionLiteralParam.class); suite.addTestSuite(RemoveBraces.class); suite.addTestSuite(AddBraces.class); - suite.addTestSuite(ReplaceGetIntention.class); + suite.addTest(ReplaceGetIntention.innerSuite()); suite.addTestSuite(ReplaceContainsIntention.class); suite.addTestSuite(ReplaceBinaryInfixIntention.class); suite.addTestSuite(ReplaceUnaryPrefixIntention.class);