Skip to content
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

Support go.testBinary to allow use of wrappers for testing #3404

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 4 additions & 0 deletions docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ Alternate tools or alternate paths for the same tools used by the Go extension.
### `go.buildFlags`

Flags to `go build`/`go test` used during build-on-save or running tests. (e.g. ["-ldflags='-s'"]) This is propagated to the language server if `gopls.build.buildFlags` is not specified.
### `go.testBinary`
Alternative binary to use in place of `go` when calling `<bin> test`, in case you need have some additonal wrapper script needed for testing. Will be called instead of `go` so must support normal test args.


### `go.buildOnSave (deprecated)`

Enable the Go language server (`#go.useLanguageServer#`) to diagnose compile errors.
Expand Down
6 changes: 6 additions & 0 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,12 @@
"description": "Feature level setting to enable/disable code lens for references and run/debug tests",
"scope": "resource"
},
"go.testBinary": {
"type": "string",
"default": "",
"description": "The path to the test binary to use for running tests. If empty, the extension will use the default test binary.",
"scope": "resource"
},
"go.addTags": {
"type": "object",
"properties": {
Expand Down
9 changes: 8 additions & 1 deletion extension/src/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ export function getTestTags(goConfig: vscode.WorkspaceConfiguration): string {
return goConfig['testTags'] !== null ? goConfig['testTags'] : goConfig['buildTags'];
}

export function getTestGoBin(goConfig: vscode.WorkspaceConfiguration): string {
return goConfig['testBinary'];
}

/**
* Returns all Go unit test functions in the given source file.
*
Expand Down Expand Up @@ -425,10 +429,13 @@ export async function goTest(testconfig: TestConfig): Promise<boolean> {
outputChannel.appendLine('');

let testResult = false;

const testCmdBin = getTestGoBin(testconfig.goConfig);

try {
testResult = await new Promise<boolean>(async (resolve, reject) => {
const testEnvVars = getTestEnvVars(testconfig.goConfig);
const tp = cp.spawn(goRuntimePath, args, { env: testEnvVars, cwd: testconfig.dir });
const tp = cp.spawn(testCmdBin || goRuntimePath, args, { env: testEnvVars, cwd: testconfig.dir });
const outBuf = new LineBuffer();
const errBuf = new LineBuffer();

Expand Down