From 03c5a6690d943e48ac5b5464c2ac2fd054ea6251 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 27 Jun 2020 17:53:50 +0200 Subject: Add light-weight snapshot testing library with editor integration --- editors/code/src/run.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'editors/code/src/run.ts') diff --git a/editors/code/src/run.ts b/editors/code/src/run.ts index 766b05112..e1430e31f 100644 --- a/editors/code/src/run.ts +++ b/editors/code/src/run.ts @@ -108,12 +108,16 @@ export async function createTask(runnable: ra.Runnable, config: Config): Promise if (runnable.args.executableArgs.length > 0) { args.push('--', ...runnable.args.executableArgs); } + const env: { [key: string]: string } = { "RUST_BACKTRACE": "short" }; + if (runnable.args.expectTest) { + env["UPDATE_EXPECT"] = "1"; + } const definition: tasks.CargoTaskDefinition = { type: tasks.TASK_TYPE, command: args[0], // run, test, etc... args: args.slice(1), cwd: runnable.args.workspaceRoot, - env: Object.assign({}, process.env as { [key: string]: string }, { "RUST_BACKTRACE": "short" }), + env: Object.assign({}, process.env as { [key: string]: string }, env), }; const target = vscode.workspace.workspaceFolders![0]; // safe, see main activate() -- cgit v1.2.3 From 7b79d24ad5b251c0806a07aa7769e824f3c37fec Mon Sep 17 00:00:00 2001 From: vsrs Date: Thu, 2 Jul 2020 19:47:40 +0300 Subject: Add runnable env support. --- editors/code/src/run.ts | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'editors/code/src/run.ts') diff --git a/editors/code/src/run.ts b/editors/code/src/run.ts index e1430e31f..d7c7c489c 100644 --- a/editors/code/src/run.ts +++ b/editors/code/src/run.ts @@ -96,6 +96,28 @@ export class RunnableQuickPick implements vscode.QuickPickItem { } } +export function prepareEnv(runnable: ra.Runnable, config: Config): Record { + const env: Record = { "RUST_BACKTRACE": "short" }; + + if (runnable.args.expectTest) { + env["UPDATE_EXPECT"] = "1"; + } + + if (config.runnableEnv) { + if (Array.isArray(config.runnableEnv)) { + for (const it of config.runnableEnv) { + if (!it.mask || new RegExp(it.mask).test(runnable.label)) { + Object.assign(env, it.env); + } + } + } else { + Object.assign(env, config.runnableEnv as Record); + } + } + + return env; +} + export async function createTask(runnable: ra.Runnable, config: Config): Promise { if (runnable.kind !== "cargo") { // rust-analyzer supports only one kind, "cargo" @@ -108,16 +130,13 @@ export async function createTask(runnable: ra.Runnable, config: Config): Promise if (runnable.args.executableArgs.length > 0) { args.push('--', ...runnable.args.executableArgs); } - const env: { [key: string]: string } = { "RUST_BACKTRACE": "short" }; - if (runnable.args.expectTest) { - env["UPDATE_EXPECT"] = "1"; - } + const definition: tasks.CargoTaskDefinition = { type: tasks.TASK_TYPE, command: args[0], // run, test, etc... args: args.slice(1), cwd: runnable.args.workspaceRoot, - env: Object.assign({}, process.env as { [key: string]: string }, env), + env: prepareEnv(runnable, config), }; const target = vscode.workspace.workspaceFolders![0]; // safe, see main activate() -- cgit v1.2.3 From 271abb7bc43f11c9b9e9c1353b162d9d267b1d21 Mon Sep 17 00:00:00 2001 From: vsrs Date: Thu, 2 Jul 2020 21:33:26 +0300 Subject: Add tests --- editors/code/src/run.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'editors/code/src/run.ts') diff --git a/editors/code/src/run.ts b/editors/code/src/run.ts index d7c7c489c..4a5c6ad41 100644 --- a/editors/code/src/run.ts +++ b/editors/code/src/run.ts @@ -5,7 +5,7 @@ import * as tasks from './tasks'; import { Ctx } from './ctx'; import { makeDebugConfig } from './debug'; -import { Config } from './config'; +import { Config, RunnableEnvCfg } from './config'; const quickPickButtons = [{ iconPath: new vscode.ThemeIcon("save"), tooltip: "Save as a launch.json configurtation." }]; @@ -96,22 +96,22 @@ export class RunnableQuickPick implements vscode.QuickPickItem { } } -export function prepareEnv(runnable: ra.Runnable, config: Config): Record { +export function prepareEnv(runnable: ra.Runnable, runnableEnvCfg: RunnableEnvCfg): Record { const env: Record = { "RUST_BACKTRACE": "short" }; if (runnable.args.expectTest) { env["UPDATE_EXPECT"] = "1"; } - if (config.runnableEnv) { - if (Array.isArray(config.runnableEnv)) { - for (const it of config.runnableEnv) { + if (runnableEnvCfg) { + if (Array.isArray(runnableEnvCfg)) { + for (const it of runnableEnvCfg) { if (!it.mask || new RegExp(it.mask).test(runnable.label)) { Object.assign(env, it.env); } } } else { - Object.assign(env, config.runnableEnv as Record); + Object.assign(env, runnableEnvCfg as Record); } } @@ -136,7 +136,7 @@ export async function createTask(runnable: ra.Runnable, config: Config): Promise command: args[0], // run, test, etc... args: args.slice(1), cwd: runnable.args.workspaceRoot, - env: prepareEnv(runnable, config), + env: prepareEnv(runnable, config.runnableEnv), }; const target = vscode.workspace.workspaceFolders![0]; // safe, see main activate() -- cgit v1.2.3 From 611fad275fb7f3c2ec018b5539444b6649285228 Mon Sep 17 00:00:00 2001 From: vsrs Date: Thu, 2 Jul 2020 22:08:33 +0300 Subject: code linting --- editors/code/src/run.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'editors/code/src/run.ts') diff --git a/editors/code/src/run.ts b/editors/code/src/run.ts index 4a5c6ad41..c09954614 100644 --- a/editors/code/src/run.ts +++ b/editors/code/src/run.ts @@ -111,7 +111,7 @@ export function prepareEnv(runnable: ra.Runnable, runnableEnvCfg: RunnableEnvCfg } } } else { - Object.assign(env, runnableEnvCfg as Record); + Object.assign(env, runnableEnvCfg); } } -- cgit v1.2.3 From bebbfa1a29062a3e9304c80080316d8c4937e5bc Mon Sep 17 00:00:00 2001 From: vsrs Date: Fri, 3 Jul 2020 14:56:30 +0300 Subject: Fix workspaceRoot --- editors/code/src/run.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'editors/code/src/run.ts') diff --git a/editors/code/src/run.ts b/editors/code/src/run.ts index c09954614..de68f27ae 100644 --- a/editors/code/src/run.ts +++ b/editors/code/src/run.ts @@ -103,6 +103,8 @@ export function prepareEnv(runnable: ra.Runnable, runnableEnvCfg: RunnableEnvCfg env["UPDATE_EXPECT"] = "1"; } + Object.assign(env, process.env as { [key: string]: string }); + if (runnableEnvCfg) { if (Array.isArray(runnableEnvCfg)) { for (const it of runnableEnvCfg) { @@ -135,7 +137,7 @@ export async function createTask(runnable: ra.Runnable, config: Config): Promise type: tasks.TASK_TYPE, command: args[0], // run, test, etc... args: args.slice(1), - cwd: runnable.args.workspaceRoot, + cwd: runnable.args.workspaceRoot || ".", env: prepareEnv(runnable, config.runnableEnv), }; -- cgit v1.2.3