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

Add a command to execute the previous test #478

Merged
merged 1 commit into from
Sep 28, 2016
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
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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you intend to pass testTimeout here as in other test commands? Or to not use goConfig?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually - looks like you are intentionally not passing testTimeout - so should drop the goConfig line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I intentionally disregard any settings as the intent of the command is to repeat the last test exactly as it was previously executed. I can imagine how you might want your timeout setting to override whatever's stored, but I wanted to keep it simple. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the config lookup for now.

}));

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 @@ -31,6 +31,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 @@ -111,13 +115,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