Skip to content

Commit 155db28

Browse files
Étienne Lévesqueaxelson
Étienne Lévesque
andauthored
fix(test lenses): Use single instead of double quotes non-Windows environments and escape nested quotes (#175)
* fix: Use single instead of double quotes and escape nested quotes * Fix formatting Co-authored-by: Jason Axelson <[email protected]>
1 parent 9eca95d commit 155db28

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,8 @@
411411
"update-vscode": "node ./node_modules/vscode/bin/install",
412412
"test": "node ./out/test/runTest.js",
413413
"lint": "eslint . --ext .js,.ts",
414-
"check-formatting": "prettier --check ./src/**/*.ts .*.js "
414+
"check-formatting": "prettier --check ./src/**/*.ts .*.js ",
415+
"fix-formatting": "prettier --write ./src/**/*.ts .*.js "
415416
},
416417
"devDependencies": {
417418
"@types/glob": "^7.1.3",

src/commands/runTestFromCodeLens.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,29 @@ export default function runFromCodeLens(args: RunArgs): void {
1919
elixirLsTerminal.sendText(buildTestCommand(args));
2020
}
2121

22+
function escapeSingleQuotes(s: string): string {
23+
return isWindows() ? s : s.replace(/'/g, "'\\''");
24+
}
25+
26+
function quote(s: string): string {
27+
const q = isWindows() ? '"' : `'`;
28+
return [q, s, q].join("");
29+
}
30+
31+
function isWindows(): boolean {
32+
return process.platform.includes("win32");
33+
}
34+
2235
function buildTestCommand(args: RunArgs): string {
2336
const testFilter = buildTestInclude(
2437
args.describe,
2538
args.testName,
2639
args.module
2740
);
2841

29-
return `mix test --exclude test --include "${testFilter}" ${args.filePath}`;
42+
return `mix test --exclude test --include ${quote(
43+
escapeSingleQuotes(testFilter)
44+
)} ${args.filePath}`;
3045
}
3146

3247
function buildTestInclude(

0 commit comments

Comments
 (0)