Inspections: Implement multi-file test class

This commit is contained in:
Alexey Sedunov
2015-04-29 18:18:55 +03:00
parent 6c28380be0
commit fe96a8563a
3 changed files with 138 additions and 4 deletions
@@ -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.idea.AbstractExpressionSelectionTest
import org.jetbrains.kotlin.idea.AbstractSmartSelectionTest
import org.jetbrains.kotlin.idea.codeInsight.AbstractInsertImportOnPasteTest
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.*
import org.jetbrains.kotlin.idea.codeInsight.moveUpDown.AbstractCodeMoverTest
import org.jetbrains.kotlin.idea.codeInsight.surroundWith.AbstractSurroundWithTest
import org.jetbrains.kotlin.idea.codeInsight.unwrap.AbstractUnwrapRemoveTest
@@ -502,6 +499,10 @@ fun main(args: Array<String>) {
model("multiFileIntentions", extension = "test", singleClass = true)
}
testClass(javaClass<AbstractJetMultiFileInspectionTest>()) {
model("multiFileInspections", extension = "test", singleClass = true)
}
testClass(javaClass<AbstractConfigureProjectByChangingFileTest>()) {
model("configuration/android-gradle", pattern = """(\w+)_before\.gradle$""", testMethod = "doTestAndroidGradle")
model("configuration/gradle", pattern = """(\w+)_before\.gradle$""", testMethod = "doTestGradle")
@@ -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()
}
}
@@ -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$"));
}
}