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.
This commit is contained in:
qx
2017-05-02 16:01:30 +03:00
parent 71de20b9e6
commit 11bc0d87b8
@@ -38,6 +38,7 @@ import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.test.InTextDirectivesUtils import org.jetbrains.kotlin.test.InTextDirectivesUtils
import org.junit.Assert import org.junit.Assert
import java.io.File import java.io.File
import java.io.IOException
abstract class AbstractQuickFixTest : KotlinLightCodeInsightFixtureTestCase() { abstract class AbstractQuickFixTest : KotlinLightCodeInsightFixtureTestCase() {
@Throws(Exception::class) @Throws(Exception::class)
@@ -115,7 +116,7 @@ abstract class AbstractQuickFixTest : KotlinLightCodeInsightFixtureTestCase() {
} }
private fun applyAction(contents: String, testFullPath: String) { 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 actionHint = ActionHint.parse(myFixture.file, contents.replace("\${file}", fileName, ignoreCase = true))
val intention = findActionWithText(actionHint.expectedText) val intention = findActionWithText(actionHint.expectedText)
if (actionHint.shouldPresent()) { if (actionHint.shouldPresent()) {
@@ -227,4 +228,17 @@ abstract class AbstractQuickFixTest : KotlinLightCodeInsightFixtureTestCase() {
fun checkForUnexpectedErrors() { fun checkForUnexpectedErrors() {
DirectiveBasedActionUtils.checkForUnexpectedErrors(myFixture.file as KtFile) 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
}
}
} }