diff --git a/package.json b/package.json index 4e5b5c31e..b4623a1e2 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/goMain.ts b/src/goMain.ts index f0aedf9d0..3aacc2109 100644 --- a/src/goMain.ts +++ b/src/goMain.ts @@ -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) => { diff --git a/src/goTest.ts b/src/goTest.ts index eeb4b77f7..c4b54520a 100644 --- a/src/goTest.ts +++ b/src/goTest.ts @@ -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.'); @@ -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; diff --git a/src/testUtils.ts b/src/testUtils.ts index e7d745dad..3b811b8b5 100644 --- a/src/testUtils.ts +++ b/src/testUtils.ts @@ -339,7 +339,11 @@ function targetArgs(testconfig: TestConfig): Thenable> { } } 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 ['./...']; @@ -347,5 +351,5 @@ function targetArgs(testconfig: TestConfig): Thenable> { return getNonVendorPackages(testconfig.dir); }); } - return Promise.resolve([]); + return Promise.resolve(params); }