-
Notifications
You must be signed in to change notification settings - Fork 646
Add support for gotests "https://github.com/cweill/gotests" #489
Conversation
Hi @cedriclam, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution! TTYL, MSBOT; |
@cedriclam, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR. |
69ebb69
to
74ee635
Compare
}); | ||
} | ||
|
||
function testEditor() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add return type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
symbols.filter(sym => | ||
sym.kind === vscode.SymbolKind.Function) | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Newline at EOF
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
let editor = testEditor(); | ||
let file = editor.document.uri.fsPath; | ||
generateTests({dir: file}); | ||
vscode.window.showInformationMessage('gotests: unit-tests generated properly for file:' + path.basename(file)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps "gotests: Unit tests generated for file: "?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right.
@@ -102,6 +102,21 @@ | |||
"description": "Displays test coverage in the current package." | |||
}, | |||
{ | |||
"command": "go.test.generate.package", | |||
"title": "Go: Generates unit-tests (package)", | |||
"description": "Generates unit-tests for the current package" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no hyphen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change done in all files
@@ -19,6 +19,7 @@ This extension adds rich language support for the Go language to VS Code, includ | |||
- Build-on-save (using `go build` and `go test`) | |||
- Lint-on-save (using `golint` or `gometalinter`) | |||
- Format (using `goreturns` or `goimports` or `gofmt`) | |||
- Generate unit-test squeleton (using `gotests`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Generate unit tests"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change done.
342c98d
to
2eed87c
Compare
@lukehoban thanks for your code review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice feature. I have added a few comments to get a clean end-to-end experience.
} | ||
|
||
export function generateTestCurrentFile() { | ||
let editor = testEditor(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When no active editor is found, then return. Don't call generateTests(). Else you will end up with 1 info box for "no editor" and 1 error box for "running the command ... failed". Same applies to the other 2 generate.. methods as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right. I will add a check on the editor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
@@ -0,0 +1,113 @@ | |||
/*--------------------------------------------------------- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name this file "goGenerateTests" maybe? Because we already have a file goTest.ts and another go.test.ts. We can it keep the intent of the file clear this way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
absolutly
let editor = testEditor(); | ||
let file = editor.document.uri.fsPath; | ||
generateTests({dir: file}); | ||
vscode.window.showInformationMessage('gotests: Unit tests generated for file:' + path.basename(file)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Show this message only after the promise returned from generateTests() is completed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same applies to the other 2 methods as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -24,7 +24,8 @@ let tools: { [key: string]: string } = { | |||
'go-symbols': 'github.com/newhook/go-symbols', | |||
'guru': 'golang.org/x/tools/cmd/guru', | |||
'gorename': 'golang.org/x/tools/cmd/gorename', | |||
'goimports': 'golang.org/x/tools/cmd/goimports' | |||
'goimports': 'golang.org/x/tools/cmd/goimports', | |||
'gotests': 'github.com/cweill/gotests' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This didn't work for me. The source code gets downloaded but the tool doesn't get dropped in the $GOPATH/bin. After looking at the source code structure, looks like there is another "gotests" folder.
This needs to be updated to 'github.com/cweill/gotests/gotests'
Make the change in the README as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will modify by: github.com/cweill/gotests/gotests/...
since it is what they are saying in the doc.
return resolve(null); | ||
} | ||
if (err) { | ||
return reject('Cannot generate test due to errors: ' + stderr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error doesn't bubble up to the user
@@ -102,6 +102,21 @@ | |||
"description": "Displays test coverage in the current package." | |||
}, | |||
{ | |||
"command": "go.test.generate.package", | |||
"title": "Go: Generates unit tests (package)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having parenthesis/brackets breaks autocomplete while typing commands in the command pallete.
#495 fixed this for the test commands
Can you update the title for your commands as well?
example: Go: Generate unit tests for package/file/function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
@@ -31,6 +31,7 @@ install: | |||
- go get -u -v github.com/newhook/go-symbols | |||
- go get -u -v golang.org/x/tools/cmd/guru | |||
- go get -u -v github.com/alecthomas/gometalinter | |||
- go get -u -v github.com/cweill/gotests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need to add this to travis unless you have some unit tests. Could you add some unit tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added unit tests
func?: string; | ||
} | ||
|
||
function generateTests(conf: Config): Thenable<vscode.WorkspaceEdit> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why return WorkspaceEdits?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know much about the vscode internals... I done a copy/past on the gotest plugin. I will check what it is better in my case.
2eed87c
to
4ecc64c
Compare
@ramya-rao-a, thanks for you code review. I done your proposed changes. about I haven't a windows environment yet but I will try next week. Thanks again for your help. |
Hello @ramya-rao-a, I was able to test on a windows environment my last pull request version and it works fine. |
ff397c2
to
8ce7301
Compare
travis jobs failed due to an issue with the command "go get -u -v github.com/golang/lint/golint" and the environment go1.5 error: "../../golang/lint/lint.go:250: undefined: types.ImportMode" PR #510 should fix this issue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just 2 more things left, otherwise things look great!
export function generateTestCurrentPackage(): Thenable<boolean> { | ||
let editor = testEditor(); | ||
if (!editor) { | ||
vscode.window.showInformationMessage('gotests: No editor selected'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You already have a message being shown in line 116. You don't need this message again. I'd actually suggest to remove the function testEditor
altogether and replace
let editor = testEditor()
with
let editor = vscode.window.activeTextEditor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will do this change.
return resolve(false); | ||
} | ||
if (err) { | ||
return reject('Cannot generate test due to errors: ' + stderr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out, this was failing for me in Windows because I had Go 1.5 on my Windows machine. The error message in such cases is not helpful. We should probably check for the Go version first and not run gotests
at all if it is not supported and show a meaningful message like Generating tests using gotests is not supported in Go 1.5
.
#509 adds a function for checking the Go version. You can either wait for that PR to get merged or copy over the getGoVersion
function from there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I will wait your PR integration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cedriclam my PR has been merged. Get latest from master, and you should have my changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ramya-rao-a: rebase done; travis builds look fine now.
86d9d2c
to
e4b0460
Compare
Implements three new commands that use gotests: - go.test.generate.package: generates all unit-test squeletons for the current package. - go.test.generate.file: generates all unit-test squeletons for the current file. - go.test.generate.function: generates unit-test squeleton for the selected function in the current file.
e4b0460
to
241c2df
Compare
Add support for gotests "https://github.com/cweill/gotests"
Implements three new commands that use gotests:
the current package.
the current file.
selected function in the current file.