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

update:provider no target gotest command #65

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
3 changes: 2 additions & 1 deletion src/goMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<ExtensionA
registerCommand('gop.benchmark.package', commands.testCurrentPackage(true));
registerCommand('gop.test.file', commands.testCurrentFile(false));
registerCommand('gop.benchmark.file', commands.testCurrentFile(true));
registerCommand('gop.test.workspace', commands.testWorkspace);
registerCommand('gop.test.workspace', commands.testWorkspace(false));
registerCommand('gop.test', commands.testWorkspace(true));
registerCommand('gop.test.previous', commands.testPrevious);
registerCommand('gop.debug.previous', commands.debugPrevious);

Expand Down
57 changes: 30 additions & 27 deletions src/goTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,36 +339,39 @@ export function testCurrentPackage(isBenchmark: boolean): CommandFactory {
*
* @param goConfig Configuration for the Go extension.
*/
export const testWorkspace: CommandFactory = () => (args: any) => {
const goConfig = getGoConfig();
if (!vscode.workspace.workspaceFolders?.length) {
vscode.window.showInformationMessage('No workspace is open to run tests.');
return;
}
let workspaceUri: vscode.Uri | undefined = vscode.workspace.workspaceFolders[0].uri;
if (
vscode.window.activeTextEditor &&
vscode.workspace.getWorkspaceFolder(vscode.window.activeTextEditor.document.uri)
) {
workspaceUri = vscode.workspace.getWorkspaceFolder(vscode.window.activeTextEditor.document.uri)!.uri;
}
export function testWorkspace(ignoreTarget: boolean): CommandFactory {
return () => (args: any) => {
const goConfig = getGoConfig();
if (!vscode.workspace.workspaceFolders?.length) {
vscode.window.showInformationMessage('No workspace is open to run tests.');
return;
}
let workspaceUri: vscode.Uri | undefined = vscode.workspace.workspaceFolders[0].uri;
if (
vscode.window.activeTextEditor &&
vscode.workspace.getWorkspaceFolder(vscode.window.activeTextEditor.document.uri)
) {
workspaceUri = vscode.workspace.getWorkspaceFolder(vscode.window.activeTextEditor.document.uri)!.uri;
}

const testConfig: TestConfig = {
goConfig,
dir: workspaceUri.fsPath,
flags: getTestFlags(goConfig, args),
includeSubDirectories: true
};
// Remember this config as the last executed test.
lastTestConfig = testConfig;
const testConfig: TestConfig = {
goConfig,
dir: workspaceUri.fsPath,
flags: getTestFlags(goConfig, args),
includeSubDirectories: true,
ignoreTarget
};
// Remember this config as the last executed test.
lastTestConfig = testConfig;

isModSupported(workspaceUri, true).then((isMod) => {
testConfig.isMod = isMod;
goTest(testConfig).then(null, (err) => {
console.error(err);
isModSupported(workspaceUri, true).then((isMod) => {
testConfig.isMod = isMod;
goTest(testConfig).then(null, (err) => {
console.error(err);
});
});
});
};
};
}

/**
* Runs all tests in the source of the active editor.
Expand Down
8 changes: 6 additions & 2 deletions src/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ export interface TestConfig {
isMod?: boolean;
//goxls: Whether this is _test.gop
isGop?: boolean;
// goxls: provider a no target go test
ignoreTarget?: boolean;
/**
* Whether code coverage should be generated and applied.
*/
Expand Down Expand Up @@ -308,9 +310,11 @@ export async function goTest(testconfig: TestConfig): Promise<boolean> {

// compute test target package
const { targets, pkgMap, currentGoWorkspace } = await getTestTargetPackages(testconfig, outputChannel);

// generate full test args.
const { args, outArgs, tmpCoverPath, addJSONFlag } = computeTestCommand(testconfig, targets);
const { args, outArgs, tmpCoverPath, addJSONFlag } = computeTestCommand(
testconfig,
testconfig.ignoreTarget ? [] : targets
);

outputChannel.appendLine(['Running tool:', goRuntimePath, ...outArgs].join(' '));
outputChannel.appendLine('');
Expand Down
Loading