Skip to content

Commit

Permalink
Fixes microsoft#303 Dont run test if current file is not test file
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a authored and Sam Herrmann committed Jan 13, 2017
1 parent 99c0398 commit 0101191
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ The following Visual Studio Code settings are available for the Go extension. T
"go.formatFlags": [],
"go.goroot": "/usr/local/go",
"go.gopath": "/Users/lukeh/go",
"go.toolsGopath": "/Users/lukeh/gotools",
"go.gocodeAutoBuild": false
}
```
Expand Down Expand Up @@ -209,7 +210,7 @@ The extension uses the following tools, installed in the current GOPATH. If any
- guru: `go get -u -v golang.org/x/tools/cmd/guru`
- gotests: `go get -u -v github.com/cweill/gotests/...`

If you wish to have the extension use a separate GOPATH for its tools, set the VSCODE_GOTOOLS environment variable to the desired path.
If you wish to have the extension use a separate GOPATH for its tools, set `go.toolsGopath` to the desired path in the Visual Studio Code settings.

To install the tools manually in the current GOPATH, just paste and run:
```bash
Expand Down
8 changes: 8 additions & 0 deletions src/goTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export function testAtCursor(goConfig: vscode.WorkspaceConfiguration) {
vscode.window.showInformationMessage('No editor is active.');
return;
}
if (!editor.document.fileName.endsWith('_test.go')) {
vscode.window.showInformationMessage('No tests found. Current file is not a test file.');
return;
}
getTestFunctions(editor.document).then(testFunctions => {
let testFunction: vscode.SymbolInformation;
// Find any test function containing the cursor.
Expand Down Expand Up @@ -105,6 +109,10 @@ export function testCurrentFile(goConfig: vscode.WorkspaceConfiguration): Thenab
vscode.window.showInformationMessage('No editor is active.');
return;
}
if (!editor.document.fileName.endsWith('_test.go')) {
vscode.window.showInformationMessage('No tests found. Current file is not a test file.');
return;
}
return getTestFunctions(editor.document).then(testFunctions => {
return goTest({
goConfig: goConfig,
Expand Down

0 comments on commit 0101191

Please sign in to comment.