From 421494602dd2303b7974369838e9c7a38eeb6a8d Mon Sep 17 00:00:00 2001 From: Friedrich von Never Date: Sat, 31 Aug 2024 17:53:57 +0200 Subject: [PATCH] (#319) Debug Previewer: add test for configuration creation --- .../previewer/AvaloniaPreviewerProcess.kt | 4 +-- .../rider/RunConfigurationUtils.kt | 3 +- .../test/cases/RunConfigurationUtilsTests.kt | 28 +++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 src/test/kotlin/me/fornever/avaloniarider/test/cases/RunConfigurationUtilsTests.kt diff --git a/src/rider/main/kotlin/me/fornever/avaloniarider/previewer/AvaloniaPreviewerProcess.kt b/src/rider/main/kotlin/me/fornever/avaloniarider/previewer/AvaloniaPreviewerProcess.kt index 49a040af..807d6c90 100644 --- a/src/rider/main/kotlin/me/fornever/avaloniarider/previewer/AvaloniaPreviewerProcess.kt +++ b/src/rider/main/kotlin/me/fornever/avaloniarider/previewer/AvaloniaPreviewerProcess.kt @@ -19,7 +19,7 @@ import com.jetbrains.rider.runtime.dotNetCore.DotNetCoreRuntime import kotlinx.coroutines.CompletableDeferred import me.fornever.avaloniarider.AvaloniaRiderBundle import me.fornever.avaloniarider.rider.createExeConfiguration -import me.fornever.avaloniarider.rider.launchConfiguration +import me.fornever.avaloniarider.rider.launchDebugger import java.nio.file.Path data class AvaloniaPreviewerParameters( @@ -126,7 +126,7 @@ class AvaloniaPreviewerProcess( ConsoleViewContentType.SYSTEM_OUTPUT ) val configuration = createExeConfiguration(project, commandLine) - val contentDescriptor = launchConfiguration(lifetime, configuration) + val contentDescriptor = launchDebugger(lifetime, configuration) return contentDescriptor.processHandler ?: error("Process handler is not available") } diff --git a/src/rider/main/kotlin/me/fornever/avaloniarider/rider/RunConfigurationUtils.kt b/src/rider/main/kotlin/me/fornever/avaloniarider/rider/RunConfigurationUtils.kt index 947bb2a6..27641876 100644 --- a/src/rider/main/kotlin/me/fornever/avaloniarider/rider/RunConfigurationUtils.kt +++ b/src/rider/main/kotlin/me/fornever/avaloniarider/rider/RunConfigurationUtils.kt @@ -3,6 +3,7 @@ package me.fornever.avaloniarider.rider import com.intellij.execution.ProgramRunnerUtil import com.intellij.execution.configurations.ConfigurationTypeUtil import com.intellij.execution.configurations.GeneralCommandLine +import com.intellij.execution.configurations.RunConfiguration import com.intellij.execution.executors.DefaultDebugExecutor import com.intellij.execution.runners.ExecutionEnvironmentBuilder import com.intellij.execution.runners.ProgramRunner @@ -43,7 +44,7 @@ fun createExeConfiguration(project: Project, commandLine: GeneralCommandLine): D ) } -suspend fun launchConfiguration(lifetime: Lifetime, configuration: DotNetExeConfiguration): RunContentDescriptor { +suspend fun launchDebugger(lifetime: Lifetime, configuration: RunConfiguration): RunContentDescriptor { val environment = ExecutionEnvironmentBuilder.create( DefaultDebugExecutor.getDebugExecutorInstance(), configuration diff --git a/src/test/kotlin/me/fornever/avaloniarider/test/cases/RunConfigurationUtilsTests.kt b/src/test/kotlin/me/fornever/avaloniarider/test/cases/RunConfigurationUtilsTests.kt new file mode 100644 index 00000000..711b91eb --- /dev/null +++ b/src/test/kotlin/me/fornever/avaloniarider/test/cases/RunConfigurationUtilsTests.kt @@ -0,0 +1,28 @@ +package me.fornever.avaloniarider.test.cases + +import com.intellij.execution.configurations.GeneralCommandLine +import com.intellij.openapi.project.ProjectManager +import com.jetbrains.rider.test.asserts.shouldBe +import me.fornever.avaloniarider.rider.createExeConfiguration +import me.fornever.avaloniarider.test.framework.AvaloniaIntegrationTest +import org.testng.annotations.Test + +class RunConfigurationUtilsTests : AvaloniaIntegrationTest() { + + override fun getSolutionDirectoryName() = "MSBuildParameters" + + @Test + fun testCreateExeConfiguration() { + val project = ProjectManager.getInstance().defaultProject + val commandLine = GeneralCommandLine("dotnet", "AvaloniaPreviewer") + .withEnvironment("TEST", "123") + val configuration = createExeConfiguration(project, commandLine) + configuration.project.shouldBe(project) + configuration.parameters.apply { + exePath.shouldBe("dotnet") + programParameters.shouldBe("AvaloniaPreviewer") + envs.shouldBe(mapOf("TEST" to "123")) + isPassParentEnvs.shouldBe(true) + } + } +}