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

Commit

Permalink
Add command: "Go: Benchmark File" (#1899)
Browse files Browse the repository at this point in the history
* ✅ creates Go: Benchmark Package function (#1522)

* ➕ adds the possibility of running all benchmarks for a package

* remove tab on empty line

* 📝 updates description

* ➕ add command to run all benchmarks in a file

* Fix test failure
  • Loading branch information
biancarosa authored and ramya-rao-a committed Aug 31, 2018
1 parent a3e6a8d commit 85646a7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@
"title": "Go: Benchmark Package",
"description": "Runs all benchmarks in the package of the current file."
},
{
"command": "go.benchmark.file",
"title": "Go: Benchmark File",
"description": "Runs all benchmarks in 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 @@ -254,7 +254,14 @@ export function activate(ctx: vscode.ExtensionContext): void {

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

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

ctx.subscriptions.push(vscode.commands.registerCommand('go.test.workspace', (args) => {
Expand Down
8 changes: 6 additions & 2 deletions src/goTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ export function testWorkspace(goConfig: vscode.WorkspaceConfiguration, args: any
* Runs all tests in the source of the active editor.
*
* @param goConfig Configuration for the Go extension.
* @param isBenchmark Boolean flag indicating if these are benchmark tests or not.
*/
export function testCurrentFile(goConfig: vscode.WorkspaceConfiguration, args: string[]): Thenable<boolean> {
export function testCurrentFile(goConfig: vscode.WorkspaceConfiguration, isBenchmark: boolean, args: string[]): Thenable<boolean> {
let editor = vscode.window.activeTextEditor;
if (!editor) {
vscode.window.showInformationMessage('No editor is active.');
Expand All @@ -167,13 +168,16 @@ export function testCurrentFile(goConfig: vscode.WorkspaceConfiguration, args: s
return;
}

const getFunctions = isBenchmark ? getBenchmarkFunctions : getTestFunctions;

return editor.document.save().then(() => {
return getTestFunctions(editor.document, null).then(testFunctions => {
return getFunctions(editor.document, null).then(testFunctions => {
const testConfig: TestConfig = {
goConfig: goConfig,
dir: path.dirname(editor.document.fileName),
flags: getTestFlags(goConfig, args),
functions: testFunctions.map(sym => sym.name),
isBenchmark: isBenchmark,
};
// Remember this config as the last executed test.
lastTestConfig = testConfig;
Expand Down
2 changes: 1 addition & 1 deletion test/go.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ It returns the number of bytes written and any write error encountered.
let uri = vscode.Uri.file(path.join(fixturePath, 'sample_test.go'));
vscode.workspace.openTextDocument(uri).then(document => {
return vscode.window.showTextDocument(document).then(editor => {
return testCurrentFile(config, []).then((result: boolean) => {
return testCurrentFile(config, false, []).then((result: boolean) => {
assert.equal(result, true);
return Promise.resolve();
});
Expand Down

0 comments on commit 85646a7

Please sign in to comment.