Skip to content

Commit

Permalink
update:provider no target gotest
Browse files Browse the repository at this point in the history
  • Loading branch information
luoliwoshang committed May 10, 2024
1 parent dc065c1 commit b9d68ee
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 30 deletions.
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

0 comments on commit b9d68ee

Please sign in to comment.