Skip to content

Commit

Permalink
feat(intellij): execute tests from project tree view on files and fol…
Browse files Browse the repository at this point in the history
…ders
  • Loading branch information
d-biehl committed Jan 12, 2025
1 parent 678e5e8 commit b155bd1
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 35 deletions.
2 changes: 1 addition & 1 deletion intellij-client/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pluginVersion = 0.105.0

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 243
pluginUntilBuild = 243.*
pluginUntilBuild = 251.*


# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
Expand Down
2 changes: 1 addition & 1 deletion intellij-client/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
# libraries
annotations = "26.0.1"
kotlinxSerialization = "1.8.0"
kotlinxSerialization = "1.7.3"
junit = "4.13.2"
lsp4j = "0.21.1"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ class RobotCodeDebugProcess(
debugClient.onStopped.adviseSuspend(Lifetime.Eternal, Dispatchers.IO) { args ->
handleOnStopped(args)
}
debugClient.onOutput.adviseSuspend(Lifetime.Eternal, Dispatchers.IO) { args ->
session.reportMessage(
args.output, when (args.category) {
OutputEventArgumentsCategory.STDOUT, OutputEventArgumentsCategory.CONSOLE -> MessageType.INFO
OutputEventArgumentsCategory.STDERR -> MessageType.ERROR
else -> MessageType.WARNING
}
)
}
// debugClient.onOutput.adviseSuspend(Lifetime.Eternal, Dispatchers.IO) { args ->
//
// session.reportMessage(
// args.output, when (args.category) {
// OutputEventArgumentsCategory.STDOUT, OutputEventArgumentsCategory.CONSOLE -> MessageType.INFO
// OutputEventArgumentsCategory.STDERR -> MessageType.ERROR
// else -> MessageType.WARNING
// }
// )
// }

// debugClient.onTerminated.adviseSuspend(Lifetime.Eternal, Dispatchers.IO) {
// session.stop()
Expand Down Expand Up @@ -105,6 +105,7 @@ class RobotCodeDebugProcess(

"exception" -> {
// TODO session.exceptionCaught()
session.positionReached(createRobotCodeSuspendContext(args.threadId))
}

else -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package dev.robotcode.robotcode4ij.execution

import com.intellij.execution.actions.ConfigurationContext
import com.intellij.execution.actions.ConfigurationFromContext
import com.intellij.execution.actions.LazyRunConfigurationProducer
import com.intellij.execution.configurations.ConfigurationFactory
import com.intellij.execution.configurations.runConfigurationType
import com.intellij.openapi.util.Ref
import com.intellij.psi.PsiElement
import dev.robotcode.robotcode4ij.testing.testManger
import java.util.*


class RobotCodeRunConfigurationProducer : LazyRunConfigurationProducer<RobotCodeRunConfiguration>() {
Expand All @@ -21,7 +23,13 @@ class RobotCodeRunConfigurationProducer : LazyRunConfigurationProducer<RobotCode
): Boolean {
val testItem = configuration.project.testManger.findTestItem(sourceElement.get()) ?: return false

configuration.name = testItem.name

configuration.name = "${
testItem.type.replaceFirstChar {
if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it
.toString()
}
} ${testItem.name}"
configuration.includedTestItems = listOf(testItem)

return true
Expand All @@ -37,4 +45,9 @@ class RobotCodeRunConfigurationProducer : LazyRunConfigurationProducer<RobotCode

return configuration.includedTestItems == listOf(testItem)
}

override fun isPreferredConfiguration(self: ConfigurationFromContext?, other: ConfigurationFromContext?): Boolean {
return false
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import kotlinx.coroutines.withTimeout
import org.eclipse.lsp4j.debug.OutputEventArgumentsCategory

class RobotOutputToGeneralTestEventsConverter(
testFrameworkName: String, consoleProperties: RobotRunnerConsoleProperties,
testFrameworkName: String, val consoleProperties: RobotRunnerConsoleProperties,
) : OutputToGeneralTestEventsConverter(testFrameworkName, consoleProperties) {

private var _firstCall = false
Expand Down Expand Up @@ -54,7 +54,6 @@ class RobotOutputToGeneralTestEventsConverter(
else -> ServiceMessageBuilder.testFailed(args.name).apply {
addAttribute("message", args.attributes.message ?: "Error")
}

}

else -> null
Expand Down Expand Up @@ -90,10 +89,6 @@ class RobotOutputToGeneralTestEventsConverter(

private var configurationDone = CompletableDeferred<Unit>()

private fun processConnected() {
configurationDone.complete(Unit)
}

init {
consoleProperties.state?.afterInitialize?.adviseEternal {
runBlocking {
Expand All @@ -108,23 +103,26 @@ class RobotOutputToGeneralTestEventsConverter(
}
consoleProperties.state?.debugClient?.onRobotStarted?.adviseEternal(this::robotStarted)
consoleProperties.state?.debugClient?.onRobotEnded?.adviseEternal(this::robotEnded)
consoleProperties.state?.debugClient?.onRobotLog?.adviseEternal { args -> // TODO: Implement this
// val msg = ServiceMessageBuilder.testStdOut("blah")
//
// msg.addAttribute("nodeId", args.itemId ?: "0").addAttribute(
// "out", "[${args.level}] ${args.message}\n"
// )
// this.processServiceMessageFromRobot(msg)
}

// TODO: Implement this
// consoleProperties.state?.debugClient?.onRobotLog?.adviseEternal { args ->
// val msg = ServiceMessageBuilder.testStdOut("blah")
//
// msg.addAttribute("nodeId", args.itemId ?: "0").addAttribute(
// "out", "[${args.level}] ${args.message}\n"
// )
// this.processServiceMessageFromRobot(msg)
// }

consoleProperties.state?.debugClient?.onOutput?.adviseEternal { args ->
val msg =
if (args.category == OutputEventArgumentsCategory.STDERR) ServiceMessageBuilder.testStdErr(args.category)
else ServiceMessageBuilder.testStdOut(args.category)

msg.addAttribute("nodeId", testItemIdStack.lastOrNull() ?: "0")
msg.addAttribute("out", "${args.output}")
msg.addAttribute("out", "\u001b[38;5;243m${args.output}\u001b[0m")

this.processServiceMessageFromRobot(msg)
processServiceMessageFromRobot(msg)
}

}
Expand All @@ -133,17 +131,18 @@ class RobotOutputToGeneralTestEventsConverter(
ServiceMessage.parse(msg.toString())?.let {
this.processServiceMessage(it, visitor)
}

}

override fun processServiceMessages(text: String, outputType: Key<*>, visitor: ServiceMessageVisitor): Boolean {
if (!_firstCall) {
_firstCall = true
this.visitor = visitor

processConnected()
configurationDone.complete(Unit)
}

// TODO: make this configurable
// TODO: make this configurable or find a way to output this to another console
return true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ class RobotRunnerConsoleProperties(

var state: RobotCodeRunProfileState? = null

init { // isUsePredefinedMessageFilter = false
init {

isUsePredefinedMessageFilter = false
setIfUndefined(HIDE_PASSED_TESTS, false)
setIfUndefined(HIDE_IGNORED_TEST, true)
setIfUndefined(HIDE_IGNORED_TEST, false)
setIfUndefined(SCROLL_TO_SOURCE, true)
setIfUndefined(SELECT_FIRST_DEFECT, true)
setIfUndefined(SHOW_STATISTICS, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiDirectory
import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiElement
import com.intellij.psi.util.elementType
Expand All @@ -30,6 +31,7 @@ import java.net.URI
val id: String,
val name: String,
val longname: String,
val lineno: Int? = null,
val description: String? = null,
val uri: String? = null,
val relSource: String? = null,
Expand Down Expand Up @@ -177,14 +179,17 @@ import java.net.URI


fun findTestItem(element: PsiElement): RobotCodeTestItem? {
val directory = element as? PsiDirectory
if (directory != null) {
return findTestItem(directory.virtualFile.uri)
}
val containingFile = element.containingFile ?: return null
if (containingFile !is RobotSuiteFile) {
return null
}

if (element is RobotSuiteFile) {
val result = findTestItem(containingFile.virtualFile.uri)
return result
return findTestItem(containingFile.virtualFile.uri)
}

if (element.elementType !is IRobotFrameworkElementType) {
Expand Down

0 comments on commit b155bd1

Please sign in to comment.