Skip to content

fix(test lenses): Use single instead of double quotes non-Windows environments and escape nested quotes #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,8 @@
"update-vscode": "node ./node_modules/vscode/bin/install",
"test": "node ./out/test/runTest.js",
"lint": "eslint . --ext .js,.ts",
"check-formatting": "prettier --check ./src/**/*.ts .*.js "
"check-formatting": "prettier --check ./src/**/*.ts .*.js ",
"fix-formatting": "prettier --write ./src/**/*.ts .*.js "
},
"devDependencies": {
"@types/glob": "^7.1.3",
Expand Down
17 changes: 16 additions & 1 deletion src/commands/runTestFromCodeLens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,29 @@ export default function runFromCodeLens(args: RunArgs): void {
elixirLsTerminal.sendText(buildTestCommand(args));
}

function escapeSingleQuotes(s: string): string {
return isWindows() ? s : s.replace(/'/g, "'\\''");
}

function quote(s: string): string {
const q = isWindows() ? '"' : `'`;
return [q, s, q].join("");
}

function isWindows(): boolean {
return process.platform.includes("win32");
}

function buildTestCommand(args: RunArgs): string {
const testFilter = buildTestInclude(
args.describe,
args.testName,
args.module
);

return `mix test --exclude test --include "${testFilter}" ${args.filePath}`;
return `mix test --exclude test --include ${quote(
escapeSingleQuotes(testFilter)
)} ${args.filePath}`;
}

function buildTestInclude(
Expand Down