Reuse intention test data in inspection tests
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
<root>
|
<root>
|
||||||
<item name='com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase com.intellij.psi.PsiManager getPsiManager()'>
|
<item
|
||||||
|
name='com.intellij.testFramework.fixtures.CodeInsightTestFixture com.intellij.openapi.vfs.VirtualFile copyDirectoryToProject(java.lang.String, java.lang.String)'>
|
||||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
</item>
|
</item>
|
||||||
<item name='com.intellij.testFramework.fixtures.CodeInsightTestFixture void assertPreferredCompletionItems(int, java.lang.String...)'>
|
<item name='com.intellij.testFramework.fixtures.CodeInsightTestFixture void assertPreferredCompletionItems(int, java.lang.String...)'>
|
||||||
@@ -7,4 +8,10 @@
|
|||||||
<val name="value" val=""fun assertPreferredCompletionItems(selected: Int, vararg expected: String)""/>
|
<val name="value" val=""fun assertPreferredCompletionItems(selected: Int, vararg expected: String)""/>
|
||||||
</annotation>
|
</annotation>
|
||||||
</item>
|
</item>
|
||||||
|
<item name='com.intellij.testFramework.fixtures.IdeaProjectTestFixture com.intellij.openapi.project.Project getProject()'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
</item>
|
||||||
|
<item name='com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase com.intellij.psi.PsiManager getPsiManager()'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
</item>
|
||||||
</root>
|
</root>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<root>
|
||||||
|
<item
|
||||||
|
name='com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl com.intellij.openapi.vfs.VirtualFile copyDirectoryToProject(java.lang.String, java.lang.String)'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
</item>
|
||||||
|
</root>
|
||||||
@@ -391,7 +391,7 @@ fun main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
testClass(javaClass<AbstractJetInspectionTest>()) {
|
testClass(javaClass<AbstractJetInspectionTest>()) {
|
||||||
model("codeInsight/inspections", extension = null, recursive = false)
|
model("intentions", pattern = "^(inspections\\.test)$", singleClass = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
testClass(javaClass<AbstractHierarchyTest>()) {
|
testClass(javaClass<AbstractHierarchyTest>()) {
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
<problems>
|
|
||||||
<problem>
|
|
||||||
<file>main.kt</file>
|
|
||||||
<line>3</line>
|
|
||||||
<module>light_idea_test_case</module>
|
|
||||||
<entry_point TYPE="file" FQNAME="temp:///src/src/main.kt" />
|
|
||||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Explicit 'get'</problem_class>
|
|
||||||
<description>Replace 'get' call with index operator</description>
|
|
||||||
</problem>
|
|
||||||
</problems>
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
fun foo() {
|
|
||||||
val a = Array<Int>(10) { it }
|
|
||||||
println(a.get(5))
|
|
||||||
}
|
|
||||||
+127
@@ -0,0 +1,127 @@
|
|||||||
|
<problems>
|
||||||
|
<problem>
|
||||||
|
<file>unnamedAndNamed.kt</file>
|
||||||
|
<line>6</line>
|
||||||
|
<module>light_idea_test_case</module>
|
||||||
|
<entry_point TYPE="file" FQNAME="temp:///src/unnamedAndNamed.kt" />
|
||||||
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Explicit 'get'</problem_class>
|
||||||
|
<description>Replace 'get' call with index operator</description>
|
||||||
|
</problem>
|
||||||
|
|
||||||
|
<problem>
|
||||||
|
<file>unacceptableVararg.kt</file>
|
||||||
|
<line>7</line>
|
||||||
|
<module>light_idea_test_case</module>
|
||||||
|
<entry_point TYPE="file" FQNAME="temp:///src/unacceptableVararg.kt" />
|
||||||
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Explicit 'get'</problem_class>
|
||||||
|
<description>Replace 'get' call with index operator</description>
|
||||||
|
</problem>
|
||||||
|
|
||||||
|
<problem>
|
||||||
|
<file>singleNamedArgument.kt</file>
|
||||||
|
<line>6</line>
|
||||||
|
<module>light_idea_test_case</module>
|
||||||
|
<entry_point TYPE="file" FQNAME="temp:///src/singleNamedArgument.kt" />
|
||||||
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Explicit 'get'</problem_class>
|
||||||
|
<description>Replace 'get' call with index operator</description>
|
||||||
|
</problem>
|
||||||
|
|
||||||
|
<problem>
|
||||||
|
<file>singleArgument.kt</file>
|
||||||
|
<line>6</line>
|
||||||
|
<module>light_idea_test_case</module>
|
||||||
|
<entry_point TYPE="file" FQNAME="temp:///src/singleArgument.kt" />
|
||||||
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Explicit 'get'</problem_class>
|
||||||
|
<description>Replace 'get' call with index operator</description>
|
||||||
|
</problem>
|
||||||
|
|
||||||
|
<problem>
|
||||||
|
<file>namedAndFunction.kt</file>
|
||||||
|
<line>6</line>
|
||||||
|
<module>light_idea_test_case</module>
|
||||||
|
<entry_point TYPE="file" FQNAME="temp:///src/namedAndFunction.kt" />
|
||||||
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Explicit 'get'</problem_class>
|
||||||
|
<description>Replace 'get' call with index operator</description>
|
||||||
|
</problem>
|
||||||
|
|
||||||
|
<problem>
|
||||||
|
<file>multiArgument.kt</file>
|
||||||
|
<line>6</line>
|
||||||
|
<module>light_idea_test_case</module>
|
||||||
|
<entry_point TYPE="file" FQNAME="temp:///src/multiArgument.kt" />
|
||||||
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Explicit 'get'</problem_class>
|
||||||
|
<description>Replace 'get' call with index operator</description>
|
||||||
|
</problem>
|
||||||
|
|
||||||
|
<problem>
|
||||||
|
<file>missingDefaultArgument.kt</file>
|
||||||
|
<line>7</line>
|
||||||
|
<module>light_idea_test_case</module>
|
||||||
|
<entry_point TYPE="file" FQNAME="temp:///src/missingDefaultArgument.kt" />
|
||||||
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Explicit 'get'</problem_class>
|
||||||
|
<description>Replace 'get' call with index operator</description>
|
||||||
|
</problem>
|
||||||
|
|
||||||
|
<problem>
|
||||||
|
<file>missingArgument.kt</file>
|
||||||
|
<line>8</line>
|
||||||
|
<module>light_idea_test_case</module>
|
||||||
|
<entry_point TYPE="file" FQNAME="temp:///src/missingArgument.kt" />
|
||||||
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Explicit 'get'</problem_class>
|
||||||
|
<description>Replace 'get' call with index operator</description>
|
||||||
|
</problem>
|
||||||
|
|
||||||
|
<problem>
|
||||||
|
<file>invalidArgument.kt</file>
|
||||||
|
<line>8</line>
|
||||||
|
<module>light_idea_test_case</module>
|
||||||
|
<entry_point TYPE="file" FQNAME="temp:///src/invalidArgument.kt" />
|
||||||
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Explicit 'get'</problem_class>
|
||||||
|
<description>Replace 'get' call with index operator</description>
|
||||||
|
</problem>
|
||||||
|
|
||||||
|
<problem>
|
||||||
|
<file>functionalArgument.kt</file>
|
||||||
|
<line>6</line>
|
||||||
|
<module>light_idea_test_case</module>
|
||||||
|
<entry_point TYPE="file" FQNAME="temp:///src/functionalArgument.kt" />
|
||||||
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Explicit 'get'</problem_class>
|
||||||
|
<description>Replace 'get' call with index operator</description>
|
||||||
|
</problem>
|
||||||
|
|
||||||
|
<problem>
|
||||||
|
<file>extensionFunction.kt</file>
|
||||||
|
<line>6</line>
|
||||||
|
<module>light_idea_test_case</module>
|
||||||
|
<entry_point TYPE="file" FQNAME="temp:///src/extensionFunction.kt" />
|
||||||
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Explicit 'get'</problem_class>
|
||||||
|
<description>Replace 'get' call with index operator</description>
|
||||||
|
</problem>
|
||||||
|
|
||||||
|
<problem>
|
||||||
|
<file>duplicateArguments.kt</file>
|
||||||
|
<line>9</line>
|
||||||
|
<module>light_idea_test_case</module>
|
||||||
|
<entry_point TYPE="file" FQNAME="temp:///src/duplicateArguments.kt" />
|
||||||
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Explicit 'get'</problem_class>
|
||||||
|
<description>Replace 'get' call with index operator</description>
|
||||||
|
</problem>
|
||||||
|
|
||||||
|
<problem>
|
||||||
|
<file>argumentAndFunction.kt</file>
|
||||||
|
<line>6</line>
|
||||||
|
<module>light_idea_test_case</module>
|
||||||
|
<entry_point TYPE="file" FQNAME="temp:///src/argumentAndFunction.kt" />
|
||||||
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Explicit 'get'</problem_class>
|
||||||
|
<description>Replace 'get' call with index operator</description>
|
||||||
|
</problem>
|
||||||
|
|
||||||
|
<problem>
|
||||||
|
<file>acceptableVararg.kt</file>
|
||||||
|
<line>6</line>
|
||||||
|
<module>light_idea_test_case</module>
|
||||||
|
<entry_point TYPE="file" FQNAME="temp:///src/acceptableVararg.kt" />
|
||||||
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Explicit 'get'</problem_class>
|
||||||
|
<description>Replace 'get' call with index operator</description>
|
||||||
|
</problem>
|
||||||
|
</problems>
|
||||||
@@ -23,24 +23,42 @@ import com.intellij.codeInspection.LocalInspectionTool
|
|||||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||||
import com.intellij.testFramework.LightProjectDescriptor
|
import com.intellij.testFramework.LightProjectDescriptor
|
||||||
import org.jetbrains.jet.plugin.JetLightProjectDescriptor
|
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.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() {
|
public abstract class AbstractJetInspectionTest: LightCodeInsightFixtureTestCase() {
|
||||||
override fun getProjectDescriptor(): LightProjectDescriptor = JetLightProjectDescriptor.INSTANCE
|
override fun getProjectDescriptor(): LightProjectDescriptor = JetLightProjectDescriptor.INSTANCE
|
||||||
|
|
||||||
override fun setUp() {
|
|
||||||
super.setUp()
|
|
||||||
myFixture!!.setTestDataPath("${PluginTestCaseBase.getTestDataPathBase()}/codeInsight/inspections")
|
|
||||||
}
|
|
||||||
|
|
||||||
protected fun doTest(path: String) {
|
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 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())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 */
|
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
@TestMetadata("idea/testData/codeInsight/inspections")
|
@TestMetadata("idea/testData/intentions")
|
||||||
public class JetInspectionTestGenerated extends AbstractJetInspectionTest {
|
public class JetInspectionTestGenerated extends AbstractJetInspectionTest {
|
||||||
public void testAllFilesPresentInInspections() throws Exception {
|
public void testAllFilesPresentInIntentions() throws Exception {
|
||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/codeInsight/inspections"), Pattern.compile("^([^\\.]+)$"), false);
|
JetTestUtils.assertAllTestsPresentInSingleGeneratedClass(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/intentions"), Pattern.compile("^(inspections\\.test)$"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("replaceGet")
|
@TestMetadata("attributeCallReplacements/replaceGetIntention/inspectionData/inspections.test")
|
||||||
public void testReplaceGet() throws Exception {
|
public void testAttributeCallReplacements_replaceGetIntention_inspectionData_Inspections_test() throws Exception {
|
||||||
doTest("idea/testData/codeInsight/inspections/replaceGet");
|
doTest("idea/testData/intentions/attributeCallReplacements/replaceGetIntention/inspectionData/inspections.test");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2193,6 +2193,7 @@ public class CodeTransformationTestGenerated extends AbstractCodeTransformationT
|
|||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/intentions/attributeCallReplacements/replaceGetIntention")
|
@TestMetadata("idea/testData/intentions/attributeCallReplacements/replaceGetIntention")
|
||||||
|
@InnerTestClasses({})
|
||||||
public static class ReplaceGetIntention extends AbstractCodeTransformationTest {
|
public static class ReplaceGetIntention extends AbstractCodeTransformationTest {
|
||||||
@TestMetadata("acceptableVararg.kt")
|
@TestMetadata("acceptableVararg.kt")
|
||||||
public void testAcceptableVararg() throws Exception {
|
public void testAcceptableVararg() throws Exception {
|
||||||
@@ -2278,6 +2279,11 @@ public class CodeTransformationTestGenerated extends AbstractCodeTransformationT
|
|||||||
doTestReplaceGetIntention("idea/testData/intentions/attributeCallReplacements/replaceGetIntention/unnamedAndNamed.kt");
|
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")
|
@TestMetadata("idea/testData/intentions/attributeCallReplacements/replaceContainsIntention")
|
||||||
@@ -3210,7 +3216,7 @@ public class CodeTransformationTestGenerated extends AbstractCodeTransformationT
|
|||||||
suite.addTestSuite(ReplaceItWithExplicitFunctionLiteralParam.class);
|
suite.addTestSuite(ReplaceItWithExplicitFunctionLiteralParam.class);
|
||||||
suite.addTestSuite(RemoveBraces.class);
|
suite.addTestSuite(RemoveBraces.class);
|
||||||
suite.addTestSuite(AddBraces.class);
|
suite.addTestSuite(AddBraces.class);
|
||||||
suite.addTestSuite(ReplaceGetIntention.class);
|
suite.addTest(ReplaceGetIntention.innerSuite());
|
||||||
suite.addTestSuite(ReplaceContainsIntention.class);
|
suite.addTestSuite(ReplaceContainsIntention.class);
|
||||||
suite.addTestSuite(ReplaceBinaryInfixIntention.class);
|
suite.addTestSuite(ReplaceBinaryInfixIntention.class);
|
||||||
suite.addTestSuite(ReplaceUnaryPrefixIntention.class);
|
suite.addTestSuite(ReplaceUnaryPrefixIntention.class);
|
||||||
|
|||||||
Reference in New Issue
Block a user