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

Fix #656 "gotests" when generates test for current function #657

Merged

Conversation

clamoriniere
Copy link
Contributor

Issue:
"Generate unit tests for current function" fails with recent
vscode-go version. This due to the fact that the GoDocumentSymbolProvider
returns now also the receiverType in the name function.
example: before "DecodeJSON", after (*Volume).DecodeJSON
gotests bin is not able to understand this string with the option -only
since it is not a valid regular expression.

Fixes: #656
check is the function name contains a ".", if yes: returns only the
second part of the name that is corresponding to the function name
without the receiverType.

@clamoriniere clamoriniere force-pushed the bugfix/GotestsGenerateFunction branch 4 times, most recently from ecc9613 to da19d3d Compare November 28, 2016 22:35
if (funcName.includes('.')) {
funcName = funcName.split('.')[1];
}
generateTests({ dir: file, func: funcName }).then((success: boolean) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need a new promise at line 92. The below will do

return getFunctions(editor.document).then(functions => {
...
...
      return generateTests({dir: file, fun: funcName});
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, thanks

import { getBinPath } from '../src/goPath';

suite('Go Extension Tests', () => {
let gopath = process.env['GOPATH'];
let repoPath = path.join(gopath, 'src', 'test');
let fixturePath = path.join(repoPath, 'testfixture');
let fixtureSourcePath = path.join(__dirname, '..', '..', 'test', 'fixtures');
let generateTestsSourcePath = path.join(repoPath, 'generatetests');
Copy link
Contributor

Choose a reason for hiding this comment

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

why not just re-use fixturePath ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if the tests use the same file, 2 tests will failed, since the all tests will be already generated by the "generate test in current package"

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, thanks!

let selection = new vscode.Selection(5, 0, 6, 0);
editor.selection = selection;
return generateTestCurrentFunction().then((result: boolean) => {
assert.equal(result, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally, I'd like to check whether the test file was created with the test function. You don't have do it now, but if you have some time, I'd appreciate it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea and done.

@@ -9,4 +9,4 @@ func print(txt string) {
}
func main() {
print("Hello")
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Removal of this line at the end is breaking one of the tests which tries to add some text there

Copy link
Contributor Author

Choose a reason for hiding this comment

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

test updated

@clamoriniere clamoriniere force-pushed the bugfix/GotestsGenerateFunction branch 2 times, most recently from 83825f2 to 6f2cfb4 Compare November 29, 2016 00:16
Issue:
"Generate unit tests for current function" fails with recent
vscode-go version. This due to the fact that the GoDocumentSymbolProvider
returns now also the receiverType in the name function.
example: before "DecodeJSON", after (*Volume).DecodeJSON
gotests bin is not able to understand this string with the option -only
since it is not a valid regular expression.

Fixes: microsoft#656
check is the function name contains a ".", if yes: returns only the
second part of the name that is corresponding to the function name
without the receiverType.
@clamoriniere
Copy link
Contributor Author

@ramya-rao-a thanks for your quick review !

@ramya-rao-a ramya-rao-a merged commit 053dd86 into microsoft:master Nov 29, 2016
@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Nov 29, 2016

My pleasure @cedriclam. Thanks for your contributions. Looking forward for more in areas other than generate tests as well :)

mattetti added a commit to mattetti/vscode-go that referenced this pull request Jan 11, 2017
* 'master' of github.com:mattetti/vscode-go: (128 commits)
  Add telemetry support for the Go extension
  Add dlv path to error msg when dlv not found
  Fixes microsoft#465 outline offset problem in No-English language (microsoft#699)
  fix coverage display when editor changes to undefined (microsoft#693)
  Add support for reading http.proxy setting (microsoft#639)
  Fixing flaky unit tests
  Refactor for corner cases
  Reduce noise in console log due to errors from hover
  Changelog for next update 0.6.51
  Remove space after brackets in snippet as per microsoft#628
  Fixes microsoft#647 Strip version from autocompleted pkgs from gopkg.in (microsoft#659)
  Fixes microsoft#647 Support vendor pkgs from root of GOPATH/src (microsoft#660)
  Fixes microsoft#640 Use spawn to handle big data from gocode (microsoft#661)
  Fixed wrong workspace when one gopath is the substring of another. (microsoft#658)
  Fix "gotests" when generates test for current function for type methods (microsoft#657)
  Add benchmark function snippet (microsoft#648)
  Fix "Go to Definition" when running Go HEAD (microsoft#655)
  Fixes microsoft#642 Only add -d once to formatflags (microsoft#644)
  Updating Changelog and package.json for 0.6.50 update
  Log errors to console
  ...
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants