Skip to content

Commit 4007481

Browse files
committed
fix(vscode,intellij): escape glob patterns in --suite and --parse-include arguments for discover and executing tests
fix #386
1 parent 79d14e4 commit 4007481

File tree

6 files changed

+23
-9
lines changed

6 files changed

+23
-9
lines changed

intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/execution/RobotCodeRunProfileState.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class RobotCodeRunProfileState(private val config: RobotCodeRunConfiguration, en
103103
*connection.toTypedArray(),
104104
*(if (!debug) arrayOf("--no-debug") else arrayOf()),
105105
*(included.toTypedArray())
106-
), noColor = false // extraArgs = arrayOf("-v", "--log", "--log-level", "TRACE")
106+
), noColor = false ,extraArgs = arrayOf("-v", "--log", "--log-level", "TRACE")
107107

108108
)
109109

intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/testing/RobotCodeTestManager.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import dev.robotcode.robotcode4ij.RobotSuiteFileType
2929
import dev.robotcode.robotcode4ij.buildRobotCodeCommandLine
3030
import dev.robotcode.robotcode4ij.psi.IRobotFrameworkElementType
3131
import dev.robotcode.robotcode4ij.psi.RobotSuiteFile
32+
import dev.robotcode.robotcode4ij.utils.escapeRobotGlob
3233
import kotlinx.coroutines.CoroutineScope
3334
import kotlinx.coroutines.Dispatchers
3435
import kotlinx.coroutines.Job
@@ -173,11 +174,11 @@ import java.util.*
173174
"--read-from-stdin",
174175
"tests",
175176
*(if (testItem.needsParseInclude == true && testItem.relSource != null) arrayOf(
176-
"--needs-parse-include", testItem.relSource
177+
"--needs-parse-include", escapeRobotGlob(testItem.relSource)
177178
)
178179
else arrayOf<String>()),
179180
"--suite",
180-
testItem.longname
181+
escapeRobotGlob(testItem.longname)
181182
), format = "json"
182183
).withCharset(Charsets.UTF_8).withWorkDirectory(project.basePath)
183184

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package dev.robotcode.robotcode4ij.utils
2+
3+
fun escapeRobotGlob(input: String): String {
4+
val globRegex = Regex("([*?\\[\\]])")
5+
return globRegex.replace(input) { matchResult ->
6+
"[" + matchResult.value + "]"
7+
}
8+
}

vscode-client/extension/debugmanager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as vscode from "vscode";
33
import { PythonManager } from "./pythonmanger";
44
import { CONFIG_SECTION } from "./config";
55
import { LanguageClientsManager, SUPPORTED_LANGUAGES, toVsCodeRange } from "./languageclientsmanger";
6-
import { WeakValueSet, waitForFile, sleep } from "./utils";
6+
import { WeakValueSet, waitForFile, sleep, escapeRobotGlobPatterns } from "./utils";
77
import * as cp from "child_process";
88
import { tmpdir } from "os";
99
import { join } from "path";
@@ -496,7 +496,7 @@ export class DebugManager {
496496
if (needs_parse_include) {
497497
for (const s of rel_sources) {
498498
args.push("--parse-include");
499-
args.push(s);
499+
args.push(escapeRobotGlobPatterns(s));
500500
}
501501
}
502502

@@ -507,7 +507,7 @@ export class DebugManager {
507507

508508
for (const s of suites) {
509509
args.push("--suite");
510-
args.push(s);
510+
args.push(escapeRobotGlobPatterns(s));
511511
}
512512

513513
if (included.length > 0) {

vscode-client/extension/testcontrollermanager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { DebugManager } from "./debugmanager";
44
import * as fs from "fs";
55

66
import { ClientState, LanguageClientsManager, toVsCodeRange } from "./languageclientsmanger";
7-
import { filterAsync, Mutex, sleep, truncateAndReplaceNewlines, WeakValueMap } from "./utils";
7+
import { escapeRobotGlobPatterns, filterAsync, Mutex, sleep, truncateAndReplaceNewlines, WeakValueMap } from "./utils";
88
import { CONFIG_SECTION } from "./config";
99
import { Range, Diagnostic, DiagnosticSeverity } from "vscode-languageclient/node";
1010

@@ -819,10 +819,10 @@ export class TestControllerManager {
819819
["discover", "--read-from-stdin", "tests"],
820820
[
821821
...(robotWorkspaceItem?.needsParseInclude && testItem.relSource
822-
? ["--parse-include", testItem.relSource]
822+
? ["--parse-include", escapeRobotGlobPatterns(testItem.relSource)]
823823
: []),
824824
"--suite",
825-
testItem?.longname,
825+
escapeRobotGlobPatterns(testItem.longname),
826826
],
827827
JSON.stringify(o),
828828
false,

vscode-client/extension/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,8 @@ export function withTimeout<T>(promise: Thenable<T>, ms: number): Promise<T> {
229229
const timeout = new Promise<never>((_, reject) => setTimeout(() => reject(new Error("Timeout exceeded")), ms));
230230
return Promise.race([promise, timeout]);
231231
}
232+
233+
export function escapeRobotGlobPatterns(str: string): string {
234+
// Ersetze Zeichen, die in Globs speziell interpretiert werden, durch ihre escaped-Variante
235+
return str.replace(/([*?[\]])/g, "[$1]");
236+
}

0 commit comments

Comments
 (0)