Inspections: Implement multi-file test class
This commit is contained in:
@@ -39,10 +39,7 @@ import org.jetbrains.kotlin.generators.tests.generator.TestGenerator.TargetBacke
|
|||||||
import org.jetbrains.kotlin.generators.tests.reservedWords.generateTestDataForReservedWords
|
import org.jetbrains.kotlin.generators.tests.reservedWords.generateTestDataForReservedWords
|
||||||
import org.jetbrains.kotlin.idea.AbstractExpressionSelectionTest
|
import org.jetbrains.kotlin.idea.AbstractExpressionSelectionTest
|
||||||
import org.jetbrains.kotlin.idea.AbstractSmartSelectionTest
|
import org.jetbrains.kotlin.idea.AbstractSmartSelectionTest
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.AbstractInsertImportOnPasteTest
|
import org.jetbrains.kotlin.idea.codeInsight.*
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.AbstractJetInspectionTest
|
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.AbstractLineMarkersTest
|
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.AbstractOutOfBlockModificationTest
|
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.moveUpDown.AbstractCodeMoverTest
|
import org.jetbrains.kotlin.idea.codeInsight.moveUpDown.AbstractCodeMoverTest
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.surroundWith.AbstractSurroundWithTest
|
import org.jetbrains.kotlin.idea.codeInsight.surroundWith.AbstractSurroundWithTest
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.unwrap.AbstractUnwrapRemoveTest
|
import org.jetbrains.kotlin.idea.codeInsight.unwrap.AbstractUnwrapRemoveTest
|
||||||
@@ -502,6 +499,10 @@ fun main(args: Array<String>) {
|
|||||||
model("multiFileIntentions", extension = "test", singleClass = true)
|
model("multiFileIntentions", extension = "test", singleClass = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testClass(javaClass<AbstractJetMultiFileInspectionTest>()) {
|
||||||
|
model("multiFileInspections", extension = "test", singleClass = true)
|
||||||
|
}
|
||||||
|
|
||||||
testClass(javaClass<AbstractConfigureProjectByChangingFileTest>()) {
|
testClass(javaClass<AbstractConfigureProjectByChangingFileTest>()) {
|
||||||
model("configuration/android-gradle", pattern = """(\w+)_before\.gradle$""", testMethod = "doTestAndroidGradle")
|
model("configuration/android-gradle", pattern = """(\w+)_before\.gradle$""", testMethod = "doTestAndroidGradle")
|
||||||
model("configuration/gradle", pattern = """(\w+)_before\.gradle$""", testMethod = "doTestGradle")
|
model("configuration/gradle", pattern = """(\w+)_before\.gradle$""", testMethod = "doTestGradle")
|
||||||
|
|||||||
+96
@@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.codeInsight
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject
|
||||||
|
import com.google.gson.JsonParser
|
||||||
|
import com.intellij.analysis.AnalysisScope
|
||||||
|
import com.intellij.codeInspection.InspectionManager
|
||||||
|
import com.intellij.codeInspection.LocalInspectionTool
|
||||||
|
import com.intellij.codeInspection.ex.InspectionManagerEx
|
||||||
|
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper
|
||||||
|
import com.intellij.openapi.util.io.FileUtil
|
||||||
|
import com.intellij.testFramework.IdeaTestUtil
|
||||||
|
import com.intellij.testFramework.InspectionTestUtil
|
||||||
|
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl
|
||||||
|
import org.jetbrains.kotlin.idea.refactoring.move.getString
|
||||||
|
import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil
|
||||||
|
import org.jetbrains.kotlin.idea.test.KotlinMultiFileTestCase
|
||||||
|
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
public abstract class AbstractJetMultiFileInspectionTest: KotlinMultiFileTestCase() {
|
||||||
|
init {
|
||||||
|
myDoCompare = false
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun doTest(path: String) {
|
||||||
|
val configFile = File(path)
|
||||||
|
val config = JsonParser().parse(FileUtil.loadFile(configFile, true)) as JsonObject
|
||||||
|
val inspection = LocalInspectionToolWrapper(Class.forName(config.getString("inspectionClass")).newInstance() as LocalInspectionTool)
|
||||||
|
|
||||||
|
val withRuntime = config["withRuntime"]?.getAsBoolean() ?: false
|
||||||
|
if (withRuntime) {
|
||||||
|
ConfigLibraryUtil.configureKotlinRuntimeAndSdk(myModule, PluginTestCaseBase.mockJdk())
|
||||||
|
}
|
||||||
|
|
||||||
|
val withFullJdk = config["withFullJdk"]?.getAsBoolean() ?: false
|
||||||
|
|
||||||
|
doTest({ rootDir, rootAfter ->
|
||||||
|
try {
|
||||||
|
if (withRuntime) {
|
||||||
|
ConfigLibraryUtil.configureKotlinRuntimeAndSdk(
|
||||||
|
getModule(),
|
||||||
|
if (withFullJdk) PluginTestCaseBase.fullJdk() else PluginTestCaseBase.mockJdk()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
val scope = AnalysisScope(myProject)
|
||||||
|
scope.invalidate()
|
||||||
|
|
||||||
|
val globalContext = CodeInsightTestFixtureImpl.createGlobalContextForTool(
|
||||||
|
scope,
|
||||||
|
myProject,
|
||||||
|
InspectionManager.getInstance(myProject) as InspectionManagerEx,
|
||||||
|
inspection
|
||||||
|
)
|
||||||
|
|
||||||
|
InspectionTestUtil.runTool(inspection, scope, globalContext)
|
||||||
|
InspectionTestUtil.compareToolResults(globalContext, inspection, false, configFile.getParent())
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (withRuntime) {
|
||||||
|
ConfigLibraryUtil.unConfigureKotlinRuntimeAndSdk(getModule(), IdeaTestUtil.getMockJdk17())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getTestDirName(true))
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun getTestDirName(lowercaseFirstLetter : Boolean) : String {
|
||||||
|
val testName = getTestName(lowercaseFirstLetter)
|
||||||
|
return testName.substring(0, testName.lastIndexOf('_')).replace('_', '/')
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override fun getTestRoot() : String {
|
||||||
|
return "/multiFileInspections/"
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override fun getTestDataPath() : String {
|
||||||
|
return PluginTestCaseBase.getTestDataPathBase()
|
||||||
|
}
|
||||||
|
}
|
||||||
+37
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.codeInsight;
|
||||||
|
|
||||||
|
import com.intellij.testFramework.TestDataPath;
|
||||||
|
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||||
|
import org.jetbrains.kotlin.test.JetTestUtils;
|
||||||
|
import org.jetbrains.kotlin.test.TestMetadata;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
@TestMetadata("idea/testData/multiFileInspections")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public class JetMultiFileInspectionTestGenerated extends AbstractJetMultiFileInspectionTest {
|
||||||
|
public void testAllFilesPresentInMultiFileInspections() throws Exception {
|
||||||
|
JetTestUtils.assertAllTestsPresentInSingleGeneratedClass(this.getClass(), new File("idea/testData/multiFileInspections"), Pattern.compile("^(.+)\\.test$"));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user