diff --git a/plugins/gradle/java/src/execution/test/runner/TestGradleConfigurationProducerUtil.kt b/plugins/gradle/java/src/execution/test/runner/TestGradleConfigurationProducerUtil.kt index 857a0f14433f..7dab1a0cd35c 100644 --- a/plugins/gradle/java/src/execution/test/runner/TestGradleConfigurationProducerUtil.kt +++ b/plugins/gradle/java/src/execution/test/runner/TestGradleConfigurationProducerUtil.kt @@ -107,17 +107,34 @@ fun ExternalSystemTaskExecutionSettings.applyTestConfiguration( } externalProjectPath = projectPath - taskNames = testRunConfigurations.entries.flatMap { it.key.split(" ") + it.value } + + val taskNameRegex = Regex("('[\\S\\s]+?'|\\S+)") // either escaped (contains space) or not + taskNames = testRunConfigurations.entries.flatMap { + val commandLine = it.key + val tasks = taskNameRegex.findAll(commandLine) + .map { match -> match.groupValues[1] } + .map(::restoreEscaped) + .toList() + + tasks + it.value + } + scriptParameters = if (testRunConfigurations.size > 1) "--continue" else "" return true } +////////////////////////////////////////////// fun String.escapeIfNeeded() = when { contains(' ') -> "'$this'" else -> this } +fun restoreEscaped(taskName: String): String { + return taskName.removeSurrounding("'") +} +////////////////////////////////////////////// + fun getSourceFile(sourceElement: PsiElement?): VirtualFile? { if (sourceElement == null) return null if (sourceElement is PsiFileSystemItem) { diff --git a/plugins/gradle/java/testSources/execution/test/runner/TestGradleConfigurationProducerUtilTest.kt b/plugins/gradle/java/testSources/execution/test/runner/TestGradleConfigurationProducerUtilTest.kt new file mode 100644 index 000000000000..b2032c124fff --- /dev/null +++ b/plugins/gradle/java/testSources/execution/test/runner/TestGradleConfigurationProducerUtilTest.kt @@ -0,0 +1,43 @@ +// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package org.jetbrains.plugins.gradle.execution.test.runner + +import com.intellij.mock.MockVirtualFile +import com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings +import org.junit.Test +import org.junit.jupiter.api.Assertions.assertIterableEquals +import org.junit.jupiter.api.Assertions.assertTrue + +class TestGradleConfigurationProducerUtilTest { + + @Test + fun testThatSettingsGetProperTaskNames() { + val settingsUnderTest = ExternalSystemTaskExecutionSettings() + + val fileWithTestsA = MockVirtualFile("FileNameA.kt") + val fileWithTestsB = MockVirtualFile("FileNameB.kt") + + val applied = settingsUnderTest.applyTestConfiguration( + "whatever-project-path", + listOf("TestA", "TestB"), + { + when(it) { + "TestA" -> fileWithTestsA + "TestB" -> fileWithTestsB + else -> null + } + }, + { "FILTER" }, + { + when(it) { + fileWithTestsA -> listOf(listOf("task A", "task B")) + fileWithTestsB -> listOf(listOf(":module1:module2:taskC", "taskD")) + else -> emptyList() + } + + } + ) + + assertTrue(applied) { "Test configuration was not applied" } + assertIterableEquals(listOf("task A", "task B", "FILTER", ":module1:module2:taskC", "taskD", "FILTER"), settingsUnderTest.taskNames) + } +} \ No newline at end of file