Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Add command: "Go: Benchmark package." #1898

Merged
merged 4 commits into from
Aug 30, 2018
Merged
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
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@
"title": "Go: Test Package",
"description": "Runs all unit tests in the package of the current file."
},
{
"command": "go.benchmark.package",
"title": "Go: Benchmark Package",
"description": "Runs all benchmarks in the package of the current file."
},
{
"command": "go.test.workspace",
"title": "Go: Test All Packages In Workspace",
Expand Down
9 changes: 8 additions & 1 deletion src/goMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,14 @@ export function activate(ctx: vscode.ExtensionContext): void {

ctx.subscriptions.push(vscode.commands.registerCommand('go.test.package', (args) => {
let goConfig = vscode.workspace.getConfiguration('go', vscode.window.activeTextEditor ? vscode.window.activeTextEditor.document.uri : null);
testCurrentPackage(goConfig, args);
let isBenchmark = false;
testCurrentPackage(goConfig, isBenchmark, args);
}));

ctx.subscriptions.push(vscode.commands.registerCommand('go.benchmark.package', (args) => {
let goConfig = vscode.workspace.getConfiguration('go', vscode.window.activeTextEditor ? vscode.window.activeTextEditor.document.uri : null);
let isBenchmark = true;
testCurrentPackage(goConfig, isBenchmark, args);
}));

ctx.subscriptions.push(vscode.commands.registerCommand('go.test.file', (args) => {
Expand Down
3 changes: 2 additions & 1 deletion src/goTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function testAtCursor(goConfig: vscode.WorkspaceConfiguration, isBenchmar
*
* @param goConfig Configuration for the Go extension.
*/
export function testCurrentPackage(goConfig: vscode.WorkspaceConfiguration, args: any) {
export function testCurrentPackage(goConfig: vscode.WorkspaceConfiguration, isBenchmark: boolean, args: any) {
let editor = vscode.window.activeTextEditor;
if (!editor) {
vscode.window.showInformationMessage('No editor is active.');
Expand All @@ -109,6 +109,7 @@ export function testCurrentPackage(goConfig: vscode.WorkspaceConfiguration, args
goConfig: goConfig,
dir: path.dirname(editor.document.fileName),
flags: testFlags,
isBenchmark: isBenchmark,
};
// Remember this config as the last executed test.
lastTestConfig = testConfig;
Expand Down
8 changes: 6 additions & 2 deletions src/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,17 @@ function targetArgs(testconfig: TestConfig): Thenable<Array<string>> {
}
}
return Promise.resolve(params);
} else if (testconfig.includeSubDirectories && !testconfig.isBenchmark) {
}
let params: string[] = [];
if (testconfig.isBenchmark) {
params = ['-bench', '.'];
} else if (testconfig.includeSubDirectories) {
return getGoVersion().then((ver: SemVersion) => {
if (ver && (ver.major > 1 || (ver.major === 1 && ver.minor >= 9))) {
return ['./...'];
}
return getNonVendorPackages(testconfig.dir);
});
}
return Promise.resolve([]);
return Promise.resolve(params);
}