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

Commit

Permalink
Merge pull request #478 from ironcladlou/test-previous
Browse files Browse the repository at this point in the history
Add a command to execute the previous test
  • Loading branch information
ramya-rao-a authored Sep 28, 2016
2 parents 63fb16e + 0677cf6 commit 02d05be
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"onCommand:go.test.cursor",
"onCommand:go.test.package",
"onCommand:go.test.file",
"onCommand:go.test.previous",
"onCommand:go.test.coverage"
],
"main": "./out/src/goMain",
Expand Down Expand Up @@ -96,6 +97,11 @@
"title": "Go: Test File",
"description": "Runs all unit tests in the current file."
},
{
"command": "go.test.previous",
"title": "Go: Test Previous",
"description": "Re-runs the last executed test."
},
{
"command": "go.test.coverage",
"title": "Go: Test coverage in current package",
Expand Down
6 changes: 5 additions & 1 deletion src/goMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { updateGoPathGoRootFromConfig, setupGoPathAndOfferToInstallTools } from
import { GO_MODE } from './goMode';
import { showHideStatus } from './goStatus';
import { coverageCurrentPackage, getCodeCoverage, removeCodeCoverage } from './goCover';
import { testAtCursor, testCurrentPackage, testCurrentFile } from './goTest';
import { testAtCursor, testCurrentPackage, testCurrentFile, testPrevious } from './goTest';
import { addImport } from './goImport';
import { installAllTools } from './goInstallTools';

Expand Down Expand Up @@ -72,6 +72,10 @@ export function activate(ctx: vscode.ExtensionContext): void {
testCurrentFile(goConfig['testTimeout']);
}));

ctx.subscriptions.push(vscode.commands.registerCommand('go.test.previous', () => {
testPrevious();
}));

ctx.subscriptions.push(vscode.commands.registerCommand('go.test.coverage', () => {
coverageCurrentPackage();
}));
Expand Down
20 changes: 20 additions & 0 deletions src/goTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ interface TestConfig {
functions?: string[];
}

// lastTestConfig holds a reference to the last executed TestConfig which allows
// the last test to be easily re-executed.
let lastTestConfig: TestConfig;

/**
* Executes the unit test at the primary cursor using `go test`. Output
* is sent to the 'Go' channel.
Expand Down Expand Up @@ -112,13 +116,29 @@ export function testCurrentFile(timeout: string) {
});
}

/**
* Runs the previously executed test.
*/
export function testPrevious() {
let editor = vscode.window.activeTextEditor;
if (!lastTestConfig) {
vscode.window.showInformationMessage('No test has been recently executed.');
return;
}
goTest(lastTestConfig).then(null, err => {
console.error(err);
});
}

/**
* Runs go test and presents the output in the 'Go' channel.
*
* @param config the test execution configuration.
*/
function goTest(config: TestConfig): Thenable<boolean> {
return new Promise<boolean>((resolve, reject) => {
// Remember this config as the last executed test.
lastTestConfig = config;
outputChannel.clear();
outputChannel.show(2);
let buildFlags: string[] = vscode.workspace.getConfiguration('go')['buildFlags'];
Expand Down

0 comments on commit 02d05be

Please sign in to comment.