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

Add command: "Go: Benchmark File" #1899

Merged
merged 8 commits into from
Aug 31, 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 @@ -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 @@ -513,7 +513,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