Add first test for new multiplatform highlighting #KT-27494 Fixed
This commit is contained in:
+91
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. 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.gradle
|
||||
|
||||
import com.intellij.codeInsight.EditorInfo
|
||||
import com.intellij.codeInsight.daemon.DaemonAnalyzerTestCase
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.editor.impl.EditorImpl
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager
|
||||
import com.intellij.openapi.fileEditor.OpenFileDescriptor
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.PsiDocumentManager
|
||||
import org.jetbrains.kotlin.idea.codeInsight.gradle.GradleImportingTestCase
|
||||
import org.jetbrains.kotlin.test.testFramework.runInEdtAndWait
|
||||
import org.jetbrains.plugins.gradle.tooling.annotation.TargetVersions
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
|
||||
class GradleMultiplatformHighlightingTest : GradleImportingTestCase() {
|
||||
|
||||
@TargetVersions("4.7+")
|
||||
@Test
|
||||
fun testFirst() {
|
||||
val files = importProjectFromTestData()
|
||||
val project = myTestFixture.project
|
||||
|
||||
checkFiles(files, project) { editor ->
|
||||
daemonAnalyzerTestCase.checkHighlighting(editor, project)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private val daemonAnalyzerTestCase = object : DaemonAnalyzerTestCase() {
|
||||
fun checkHighlighting(editor: Editor, project: Project) {
|
||||
myProject = project
|
||||
runInEdtAndWait {
|
||||
checkHighlighting(editor, /* checkWarnings = */ true, /* checkInfos = */ false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkFiles(files: List<VirtualFile>, project: Project, check: (Editor) -> Unit) {
|
||||
var atLeastOneFile = false
|
||||
files.filter { it.extension == "kt" }.forEach { file ->
|
||||
val editor = configureEditorByExistingFile(file, project)
|
||||
atLeastOneFile = true
|
||||
check(editor)
|
||||
}
|
||||
Assert.assertTrue(atLeastOneFile)
|
||||
}
|
||||
|
||||
private fun configureEditorByExistingFile(virtualFile: VirtualFile, project: Project): Editor {
|
||||
var result: Editor? = null
|
||||
runInEdtAndWait {
|
||||
val editor = createEditor(virtualFile, project)
|
||||
val document = editor.document
|
||||
val editorInfo = EditorInfo(document.text)
|
||||
val newFileText = editorInfo.newFileText
|
||||
ApplicationManager.getApplication().runWriteAction {
|
||||
if (document.text != newFileText) {
|
||||
document.setText(newFileText)
|
||||
}
|
||||
|
||||
editorInfo.applyToEditor(editor)
|
||||
}
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments()
|
||||
result = editor
|
||||
}
|
||||
return result!!
|
||||
}
|
||||
|
||||
private fun createEditor(file: VirtualFile, project: Project): Editor {
|
||||
val instance = FileEditorManager.getInstance(this.myProject)
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments()
|
||||
val editor = instance.openTextEditor(OpenFileDescriptor(this.myProject, file, 0), false)
|
||||
(editor as EditorImpl).setCaretActive()
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments()
|
||||
DaemonCodeAnalyzer.getInstance(project).restart()
|
||||
return editor
|
||||
}
|
||||
|
||||
override fun testDataDirName(): String {
|
||||
return "newMultiplatformHighlighting"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
plugins {
|
||||
id 'kotlin-multiplatform' version '1.3.0'
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
jcenter()
|
||||
}
|
||||
kotlin {
|
||||
targets {
|
||||
fromPreset(presets.jvm, 'jvm')
|
||||
fromPreset(presets.js, 'js')
|
||||
}
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib-common'
|
||||
}
|
||||
}
|
||||
jvmMain {
|
||||
dependencies {
|
||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
|
||||
}
|
||||
}
|
||||
jsMain {
|
||||
dependencies {
|
||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib-js'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
pluginManagement {
|
||||
resolutionStrategy {
|
||||
eachPlugin {
|
||||
if (requested.id.id == "kotlin-multiplatform") {
|
||||
useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
||||
maven { url 'https://plugins.gradle.org/m2/' }
|
||||
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
rootProject.name = 'first'
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
expect class <error descr="[NO_ACTUAL_FOR_EXPECT] Expected class 'My' has no actual declaration in module first_jsMain for JS">My</error> {
|
||||
fun foo()
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
fun foo() = "Java Script"
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
actual class My {
|
||||
actual fun foo() {}
|
||||
|
||||
actual fun <error descr="[ACTUAL_WITHOUT_EXPECT] Actual function 'bar' has no corresponding expected declaration">bar</error>() {}
|
||||
}
|
||||
Reference in New Issue
Block a user