From 11bc0d87b879a9707c35eee985da32a9655b6f30 Mon Sep 17 00:00:00 2001 From: qx Date: Tue, 2 May 2017 16:01:30 +0300 Subject: [PATCH] Fixes to AbstractQuickFixTest (full path to file and file separator) The full path to file in getTestDataPath is necessary to show file diff link in exception when the test fails. The File.separatorChar fixes tests on Windows machines. --- .../kotlin/idea/quickfix/AbstractQuickFixTest.kt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixTest.kt b/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixTest.kt index 3f60a98f29f..f62155200a5 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixTest.kt @@ -38,6 +38,7 @@ import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.test.InTextDirectivesUtils import org.junit.Assert import java.io.File +import java.io.IOException abstract class AbstractQuickFixTest : KotlinLightCodeInsightFixtureTestCase() { @Throws(Exception::class) @@ -115,7 +116,7 @@ abstract class AbstractQuickFixTest : KotlinLightCodeInsightFixtureTestCase() { } private fun applyAction(contents: String, testFullPath: String) { - val fileName = testFullPath.substringAfterLast("/", "") + val fileName = testFullPath.substringAfterLast(File.separatorChar, "") val actionHint = ActionHint.parse(myFixture.file, contents.replace("\${file}", fileName, ignoreCase = true)) val intention = findActionWithText(actionHint.expectedText) if (actionHint.shouldPresent()) { @@ -227,4 +228,17 @@ abstract class AbstractQuickFixTest : KotlinLightCodeInsightFixtureTestCase() { fun checkForUnexpectedErrors() { DirectiveBasedActionUtils.checkForUnexpectedErrors(myFixture.file as KtFile) } + + override fun getTestDataPath(): String { + // Ensure full path is returned. Otherwise FileComparisonFailureException does not provide link to file diff + val testDataPath = super.getTestDataPath() + try { + return File(testDataPath).getCanonicalPath() + } + catch (e: IOException) { + e.printStackTrace() + return testDataPath + } + + } }