Skip to content

Commit db14a21

Browse files
luehmannVexu
authored andcommitted
Add configuration debugTestArgs
This adds the `debugTestArgs` option, which allows users to override the arguments used to build a test binary, similar to `testArgs`. It also changes the working directory to the workspace folder to allow running `zig build`.
1 parent b9ecf3c commit db14a21

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,21 @@
150150
],
151151
"description": "Arguments to pass to 'zig' for running tests. Supported variables: ${filter}, ${path}."
152152
},
153+
"zig.debugTestArgs": {
154+
"type": "array",
155+
"items": {
156+
"type": "string"
157+
},
158+
"default": [
159+
"test",
160+
"${path}",
161+
"--test-filter",
162+
"${filter}",
163+
"--test-no-exec",
164+
"-femit-bin=${binaryPath}"
165+
],
166+
"description": "Arguments to pass to 'zig' for debugging tests. Supported variables: ${filter}, ${path}, ${binaryPath}."
167+
},
153168
"zig.debugAdapter": {
154169
"scope": "resource",
155170
"type": "string",

src/zigTestRunnerProvider.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ export default class ZigTestRunnerProvider {
212212
}
213213

214214
private async buildTestBinary(run: vscode.TestRun, testFilePath: string, testDesc: string): Promise<string> {
215+
const config = vscode.workspace.getConfiguration("zig");
215216
const zigPath = zigProvider.getZigPath();
216217
if (!zigPath) {
217218
throw new Error("Unable to build test binary without Zig");
@@ -223,14 +224,12 @@ export default class ZigTestRunnerProvider {
223224
const binaryPath = path.join(outputDir, binaryName);
224225
await vscode.workspace.fs.createDirectory(vscode.Uri.file(outputDir));
225226

226-
const { stdout, stderr } = await execFile(zigPath, [
227-
"test",
228-
testFilePath,
229-
"--test-filter",
230-
testDesc,
231-
"--test-no-exec",
232-
`-femit-bin=${binaryPath}`,
233-
]);
227+
const debugTestArgsConf = config.get<string[]>("debugTestArgs") ?? [];
228+
const args = debugTestArgsConf.map((arg) =>
229+
arg.replace("${filter}", testDesc).replace("${path}", testFilePath).replace("${binaryPath}", binaryPath),
230+
);
231+
232+
const { stdout, stderr } = await execFile(zigPath, args, { cwd: wsFolder });
234233
if (stderr) {
235234
run.appendOutput(stderr.replaceAll("\n", "\r\n"));
236235
throw new Error(`Failed to build test binary: ${stderr}`);

0 commit comments

Comments
 (0)