Scratch tests: add check for toolwindow output
This commit is contained in:
+24
-2
@@ -20,6 +20,7 @@ import com.intellij.execution.impl.ConsoleViewImpl
|
||||
import com.intellij.execution.ui.ConsoleViewContentType
|
||||
import com.intellij.ide.scratch.ScratchFileType
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.command.WriteCommandAction
|
||||
import com.intellij.openapi.editor.ex.EditorEx
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.Disposer
|
||||
@@ -27,26 +28,34 @@ import com.intellij.openapi.wm.ToolWindow
|
||||
import com.intellij.openapi.wm.ToolWindowAnchor
|
||||
import com.intellij.openapi.wm.ToolWindowFactory
|
||||
import com.intellij.openapi.wm.ToolWindowManager
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import org.jetbrains.kotlin.idea.scratch.ScratchExpression
|
||||
import org.jetbrains.kotlin.idea.scratch.ScratchFile
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
|
||||
object ToolWindowScratchOutputHandler : ScratchOutputHandlerAdapter() {
|
||||
|
||||
override fun handle(file: ScratchFile, expression: ScratchExpression, output: ScratchOutput) {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode) {
|
||||
return testPrint(file, output.text)
|
||||
}
|
||||
|
||||
printToConsole(file.project) {
|
||||
print(output.text, output.type.convert())
|
||||
}
|
||||
}
|
||||
|
||||
override fun error(file: ScratchFile, message: String) {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode) {
|
||||
return testPrint(file, message)
|
||||
}
|
||||
|
||||
printToConsole(file.project) {
|
||||
print(message, ConsoleViewContentType.ERROR_OUTPUT)
|
||||
}
|
||||
}
|
||||
|
||||
private fun printToConsole(project: Project, print: ConsoleViewImpl.() -> Unit) {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode) return
|
||||
|
||||
ApplicationManager.getApplication().invokeLater {
|
||||
val toolWindow = getToolWindow(project) ?: createToolWindow(project)
|
||||
val contents = toolWindow.contentManager.contents
|
||||
@@ -97,6 +106,19 @@ object ToolWindowScratchOutputHandler : ScratchOutputHandlerAdapter() {
|
||||
ScratchToolWindowFactory().createToolWindowContent(project, window)
|
||||
return window
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
private fun testPrint(file: ScratchFile, output: String) {
|
||||
ApplicationManager.getApplication().invokeLater {
|
||||
WriteCommandAction.runWriteCommandAction(file.project) {
|
||||
val psiFile = file.getPsiFile()!!
|
||||
psiFile.addAfter(
|
||||
KtPsiFactory(file.project).createComment("/** $output */"),
|
||||
psiFile.lastChild
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ScratchToolWindowFactory : ToolWindowFactory {
|
||||
|
||||
+3
-1
@@ -1 +1,3 @@
|
||||
foo() // ERROR: Unresolved reference: foo
|
||||
foo() // ERROR: Unresolved reference: foo
|
||||
/** Unresolved reference: foo */
|
||||
/** Compilation Error */
|
||||
+6
-1
@@ -1 +1,6 @@
|
||||
foo() // ERROR: error: unresolved reference: foo
|
||||
foo() // ERROR: error: unresolved reference: foo
|
||||
/** error: unresolved reference: foo
|
||||
|
||||
foo()
|
||||
|
||||
^ */
|
||||
+7
-1
@@ -4,4 +4,10 @@ foo.forEach { // ERROR: Unresolved reference: foo; Cannot choose among
|
||||
|
||||
fun goo(a: String) { // ERROR: Unresolved reference: goo
|
||||
super.goo(a)
|
||||
}
|
||||
}
|
||||
/** Unresolved reference: foo */
|
||||
/** Cannot choose among the following candidates without completing type inference:
|
||||
@HidesMembers public inline fun <T> Iterable<???>.forEach(action: (???) -> Unit): Unit defined in kotlin.collections
|
||||
@HidesMembers public inline fun <K, V> Map<out ???, ???>.forEach(action: (Map.Entry<???, ???>) -> Unit): Unit defined in kotlin.collections */
|
||||
/** Unresolved reference: goo */
|
||||
/** Compilation Error */
|
||||
+21
-3
@@ -1,7 +1,25 @@
|
||||
foo.forEach { // ERROR: error: unresolved reference: foo
|
||||
foo.forEach { // ERROR: error: unresolved reference: foo
|
||||
1 + 1
|
||||
}
|
||||
|
||||
fun goo(a: String) { // ERROR: error: unresolved reference: goo
|
||||
fun goo(a: String) { // ERROR: error: unresolved reference: goo
|
||||
super.goo(a)
|
||||
}
|
||||
}
|
||||
/** error: unresolved reference: foo
|
||||
|
||||
foo.forEach {
|
||||
|
||||
^
|
||||
|
||||
error: cannot choose among the following candidates without completing type inference:
|
||||
@HidesMembers public inline fun <T> Iterable<???>.forEach(action: (???) -> Unit): Unit defined in kotlin.collections
|
||||
@HidesMembers public inline fun <K, V> Map<out ???, ???>.forEach(action: (Map.Entry<???, ???>) -> Unit): Unit defined in kotlin.collections
|
||||
|
||||
foo.forEach {
|
||||
|
||||
^ */
|
||||
/** error: unresolved reference: goo
|
||||
|
||||
super.goo(a)
|
||||
|
||||
^ */
|
||||
+2
-1
@@ -1,2 +1,3 @@
|
||||
val a = "a".repeat(100) // RESULT: val a: String
|
||||
a // RESULT: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
|
||||
a // RESULT: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
|
||||
/** aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa */
|
||||
+2
-1
@@ -1,2 +1,3 @@
|
||||
val a = "a".repeat(100)
|
||||
a // RESULT: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
|
||||
a // RESULT: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
|
||||
/** aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa */
|
||||
Reference in New Issue
Block a user