mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
KTIJ-20360 [Gradle]: command line split fix
GitOrigin-RevId: f305da5e4b5e7efcf4982f67ebc0e63e855ec885
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ebb5db7a65
commit
4727c201f6
+18
-1
@@ -107,17 +107,34 @@ fun <T> 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) {
|
||||
|
||||
+43
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user