Use test path relative to testDataPath in fixture.configureByFile to be complaint with 193

This commit is contained in:
Vladimir Dolzhenko
2019-09-29 09:45:42 +02:00
parent 7c80c6ba63
commit 3e2dac6586
8 changed files with 32 additions and 26 deletions
@@ -30,7 +30,7 @@ abstract class AbstractCompletionIncrementalResolveTest : KotlinLightCodeInsight
try { try {
val file = File(testPath) val file = File(testPath)
val hasCaretMarker = FileUtil.loadFile(file, true).contains("<caret>") val hasCaretMarker = FileUtil.loadFile(file, true).contains("<caret>")
myFixture.configureByFile(testPath) myFixture.configureByFile(fileName())
val document = myFixture.editor.document val document = myFixture.editor.document
val beforeMarkerOffset = document.text.indexOf(BEFORE_MARKER) val beforeMarkerOffset = document.text.indexOf(BEFORE_MARKER)
@@ -62,6 +62,9 @@ abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFix
protected open val captureExceptions = true protected open val captureExceptions = true
protected fun testPath(): String =
File(testDataPath, fileName()).toString()
override fun setUp() { override fun setUp() {
super.setUp() super.setUp()
// We do it here to avoid possible initialization problems // We do it here to avoid possible initialization problems
@@ -59,7 +59,8 @@ abstract class AbstractPerformanceCompletionHandlerTests(
super.tearDown() super.tearDown()
} }
protected open fun doPerfTest(testPath: String) { protected open fun doPerfTest(unused: String) {
val testPath = testPath()
setUpFixture(testPath) setUpFixture(testPath)
val tempSettings = CodeStyle.getSettings(project).clone() val tempSettings = CodeStyle.getSettings(project).clone()
@@ -65,10 +65,11 @@ abstract class AbstractPerformanceCompletionIncrementalResolveTest : KotlinLight
} }
} }
protected fun doPerfTest(testPath: String) { protected fun doPerfTest(unused: String) {
val testPath = testPath()
val testName = getTestName(false) val testName = getTestName(false)
innerPerfTest(testName) { innerPerfTest(testName) {
myFixture.configureByFile(testPath) myFixture.configureByFile(fileName())
val document = myFixture.editor.document val document = myFixture.editor.document
val beforeMarkerOffset = document.text.indexOf(BEFORE_MARKER) val beforeMarkerOffset = document.text.indexOf(BEFORE_MARKER)
@@ -54,10 +54,10 @@ abstract class AbstractPerformanceHighlightingTest : KotlinLightCodeInsightFixtu
} }
} }
protected fun doPerfTest(filePath: String) { protected fun doPerfTest(unused: String) {
val testName = getTestName(false) val testName = getTestName(false)
innerPerfTest(testName) { innerPerfTest(testName) {
myFixture.configureByFile(filePath) myFixture.configureByFile(fileName())
val project = myFixture.project val project = myFixture.project
commitAllDocuments() commitAllDocuments()
@@ -26,12 +26,11 @@ import java.io.File
abstract class AbstractPerformanceImportTest : KotlinLightCodeInsightFixtureTestCase() { abstract class AbstractPerformanceImportTest : KotlinLightCodeInsightFixtureTestCase() {
override fun getTestDataPath() = KotlinTestUtils.getHomeDirectory()
override fun getProjectDescriptor(): LightProjectDescriptor = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE override fun getProjectDescriptor(): LightProjectDescriptor = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
protected abstract fun stats(): Stats protected abstract fun stats(): Stats
protected fun doPerfTest(testPath: String) { protected fun doPerfTest(unused: String) {
val testName = getTestName(false) val testName = getTestName(false)
CodeStyle.setTemporarySettings(project, CodeStyle.getSettings(project).clone()) CodeStyle.setTemporarySettings(project, CodeStyle.getSettings(project).clone())
@@ -41,13 +40,13 @@ abstract class AbstractPerformanceImportTest : KotlinLightCodeInsightFixtureTest
val fixture = myFixture val fixture = myFixture
val dependencySuffixes = listOf(".dependency.kt", ".dependency.java", ".dependency1.kt", ".dependency2.kt") val dependencySuffixes = listOf(".dependency.kt", ".dependency.java", ".dependency1.kt", ".dependency2.kt")
for (suffix in dependencySuffixes) { for (suffix in dependencySuffixes) {
val dependencyPath = testPath.replace(".kt", suffix) val dependencyPath = fileName().replace(".kt", suffix)
if (File(dependencyPath).exists()) { if (File(testDataPath, dependencyPath).exists()) {
fixture.configureByFile(dependencyPath) fixture.configureByFile(dependencyPath)
} }
} }
fixture.configureByFile(testPath) fixture.configureByFile(fileName())
var file = fixture.file as KtFile var file = fixture.file as KtFile
@@ -84,7 +83,7 @@ abstract class AbstractPerformanceImportTest : KotlinLightCodeInsightFixtureTest
stats().perfTest<Unit, String>( stats().perfTest<Unit, String>(
testName = testName, testName = testName,
setUp = { setUp = {
fixture.configureByFile(testPath) fixture.configureByFile(fileName())
file = fixture.file as KtFile file = fixture.file as KtFile
fileText = file.text fileText = file.text
@@ -96,7 +95,9 @@ abstract class AbstractPerformanceImportTest : KotlinLightCodeInsightFixtureTest
}, },
tearDown = { tearDown = {
val log = it.value val log = it.value
KotlinTestUtils.assertEqualsToFile(File("$testPath.after"), fixture.file.text) val testPath = testPath()
val afterFile = File("$testPath.after")
KotlinTestUtils.assertEqualsToFile(afterFile, fixture.file.text)
if (log != null) { if (log != null) {
val logFile = File("$testPath.log") val logFile = File("$testPath.log")
if (log.isNotEmpty()) { if (log.isNotEmpty()) {
@@ -33,7 +33,7 @@ public abstract class AbstractPsiCheckerTest extends KotlinLightCodeInsightFixtu
} }
public void doTest(@NotNull String filePath) throws Exception { public void doTest(@NotNull String filePath) throws Exception {
myFixture.configureByFile(filePath); myFixture.configureByFile(fileName());
checkHighlighting(true, false, false); checkHighlighting(true, false, false);
checkResolveToDescriptor(); checkResolveToDescriptor();
} }
@@ -46,7 +46,7 @@ public abstract class AbstractPsiCheckerTest extends KotlinLightCodeInsightFixtu
public void doTestWithInfos(@NotNull String filePath) throws Exception { public void doTestWithInfos(@NotNull String filePath) throws Exception {
try { try {
myFixture.configureByFile(filePath); myFixture.configureByFile(fileName());
//noinspection unchecked //noinspection unchecked
myFixture.enableInspections(SpellCheckingInspection.class); myFixture.enableInspections(SpellCheckingInspection.class);
@@ -6,8 +6,6 @@
package org.jetbrains.kotlin.idea.conversion.copy package org.jetbrains.kotlin.idea.conversion.copy
import com.intellij.openapi.actionSystem.IdeActions import com.intellij.openapi.actionSystem.IdeActions
import com.intellij.openapi.util.registry.Registry
import org.jetbrains.kotlin.idea.AbstractCopyPasteTest
import org.jetbrains.kotlin.idea.editor.KotlinEditorOptions import org.jetbrains.kotlin.idea.editor.KotlinEditorOptions
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
@@ -37,27 +35,29 @@ abstract class AbstractJavaToKotlinCopyPasteConversionTest : AbstractJ2kCopyPast
super.tearDown() super.tearDown()
} }
fun doTest(path: String) { fun doTest(unused: String) {
myFixture.testDataPath = BASE_PATH val path = testPath()
val testName = getTestName(false) val baseName = fileName().replace(".java", "")
myFixture.configureByFiles(testName + ".java") myFixture.configureByFiles("$baseName.java")
val fileText = myFixture.editor.document.text val fileText = myFixture.editor.document.text
val noConversionExpected = InTextDirectivesUtils.findListWithPrefixes(fileText, "// NO_CONVERSION_EXPECTED").isNotEmpty() val noConversionExpected = InTextDirectivesUtils.findListWithPrefixes(fileText, "// NO_CONVERSION_EXPECTED").isNotEmpty()
myFixture.performEditorAction(IdeActions.ACTION_COPY) myFixture.performEditorAction(IdeActions.ACTION_COPY)
configureByDependencyIfExists(testName + ".dependency.kt") configureByDependencyIfExists("$baseName.dependency.kt")
configureByDependencyIfExists(testName + ".dependency.java") configureByDependencyIfExists("$baseName.dependency.java")
configureTargetFile(testName + ".to.kt") configureTargetFile("$baseName.to.kt")
ConvertJavaCopyPasteProcessor.conversionPerformed = false ConvertJavaCopyPasteProcessor.conversionPerformed = false
myFixture.performEditorAction(IdeActions.ACTION_PASTE) myFixture.performEditorAction(IdeActions.ACTION_PASTE)
assertEquals(noConversionExpected, !ConvertJavaCopyPasteProcessor.conversionPerformed, assertEquals(
if (noConversionExpected) "Conversion to Kotlin should not be suggested" else "No conversion to Kotlin suggested") noConversionExpected, !ConvertJavaCopyPasteProcessor.conversionPerformed,
if (noConversionExpected) "Conversion to Kotlin should not be suggested" else "No conversion to Kotlin suggested"
)
KotlinTestUtils.assertEqualsToFile(File(path.replace(".java", ".expected.kt")), myFixture.file.text) KotlinTestUtils.assertEqualsToFile(File(path.replace(".java", ".expected.kt")), myFixture.file.text)
} }