193: Fix test fixture configuration
Path to test data file should be relative to test data directory
This commit is contained in:
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.completion.test
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionType
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractKotlinSourceInJavaCompletionTest : KotlinFixtureCompletionBaseTestCase() {
|
||||
override fun getPlatform() = JvmPlatforms.unspecifiedJvmPlatform
|
||||
|
||||
override fun doTest(testPath: String) {
|
||||
val mockPath = RELATIVE_COMPLETION_TEST_DATA_BASE_PATH + "/injava/mockLib"
|
||||
val mockLibDir = File(mockPath)
|
||||
fun collectPaths(dir: File): List<String> {
|
||||
return dir.listFiles()!!.flatMap {
|
||||
if (it.isDirectory) {
|
||||
collectPaths(it)
|
||||
} else listOf(FileUtil.toSystemIndependentName(it.path))
|
||||
}
|
||||
}
|
||||
|
||||
val paths = collectPaths(mockLibDir).toTypedArray()
|
||||
paths.forEach { path ->
|
||||
val vFile = myFixture.copyFileToProject(path.substringAfter(testDataPath), path.substring(mockPath.length))
|
||||
myFixture.configureFromExistingVirtualFile(vFile)
|
||||
}
|
||||
|
||||
LightClassComputationControl.testWithControl(project, FileUtil.loadFile(File(testPath))) {
|
||||
super.doTest(testPath)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getProjectDescriptor() = LightCodeInsightFixtureTestCase.JAVA_LATEST
|
||||
override fun defaultCompletionType() = CompletionType.BASIC
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.completion.test
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionType
|
||||
import com.intellij.codeInsight.lookup.LookupElement
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import org.jetbrains.kotlin.idea.caches.project.LibraryModificationTracker
|
||||
import org.jetbrains.kotlin.idea.test.CompilerTestDirectives
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.idea.test.configureCompilerOptions
|
||||
import org.jetbrains.kotlin.idea.test.rollbackCompilerOptions
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import java.io.File
|
||||
|
||||
abstract class KotlinFixtureCompletionBaseTestCase : KotlinLightCodeInsightFixtureTestCase() {
|
||||
abstract fun getPlatform(): TargetPlatform
|
||||
|
||||
protected open fun complete(completionType: CompletionType, invocationCount: Int): Array<LookupElement>? =
|
||||
myFixture.complete(completionType, invocationCount)
|
||||
|
||||
protected abstract fun defaultCompletionType(): CompletionType
|
||||
protected open fun defaultInvocationCount(): Int = 0
|
||||
|
||||
open fun doTest(testPath: String) {
|
||||
setUpFixture(fileName())
|
||||
|
||||
val fileText = FileUtil.loadFile(File(testPath), true)
|
||||
val configured = configureCompilerOptions(fileText, project, module)
|
||||
try {
|
||||
|
||||
assertTrue("\"<caret>\" is missing in file \"$testPath\"", fileText.contains("<caret>"))
|
||||
|
||||
if (ExpectedCompletionUtils.shouldRunHighlightingBeforeCompletion(fileText)) {
|
||||
myFixture.doHighlighting()
|
||||
}
|
||||
|
||||
testCompletion(
|
||||
fileText,
|
||||
getPlatform(),
|
||||
{ completionType, count -> complete(completionType, count) },
|
||||
defaultCompletionType(),
|
||||
defaultInvocationCount(),
|
||||
additionalValidDirectives = CompilerTestDirectives.ALL_COMPILER_TEST_DIRECTIVES
|
||||
)
|
||||
} finally {
|
||||
if (configured) {
|
||||
rollbackCompilerOptions(project, module)
|
||||
}
|
||||
tearDownFixture()
|
||||
}
|
||||
}
|
||||
|
||||
protected open fun setUpFixture(testPath: String) {
|
||||
//TODO: this is a hacky workaround for js second completion tests failing with PsiInvalidElementAccessException
|
||||
LibraryModificationTracker.getInstance(project).incModificationCount()
|
||||
|
||||
myFixture.configureByFile(testPath)
|
||||
}
|
||||
|
||||
protected open fun tearDownFixture() {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user