-
Notifications
You must be signed in to change notification settings - Fork 645
Code Coverage for multiple packages #816
Comments
I would personally recommend to keep it simple for now. Also, the go recommended way is to have the tests with the code, what are the scenarios where you'd write tests in other packages that the original one? |
I'm building a simple REST server that reads from a database. Instead of reinventing DB processing for each call, most of the logic is in a "db-helpers" package. To test both packages, I would need to copy-paste tests to both. |
Agreed, this is annoying... it has resulted in writing tests for the sake of coverage even though in reality the code in question is indirectly covered all over the place. Really slows down productivity and is an obstacle towards refactoring when you know you not only have to extract out all the common code, but you have to pull out all the common tests as well. |
We could add support for https://github.com/haya14busa/goverage, but keep it behind a setting, so that this a feature that users opt in to and is not the default one. PRs are welcome |
Go 1.10 supports |
@ramya-rao-a I've added |
I found the reason why coverage isn't shown. The bug is in SetupLet's use this package structure (package is
Package
Bugexport function applyCodeCoverageToAllEditors(coverProfilePath: string, packageDirPath: string): Promise<void> {
return new Promise((resolve, reject) => {
try {
// ...
lines.on('line', function(data: string) {
// go test coverageprofile generates output:
// filename:StartLine.StartColumn,EndLine.EndColumn Hits CoverCount
// The first line will be "mode: set" which will be ignored
const fileRange = data.match(/([^:]+)\:([\d]+)\.([\d]+)\,([\d]+)\.([\d]+)\s([\d]+)\s([\d]+)/);
if (!fileRange) {
return;
}
// => HERE
const filePath = path.join(packageDirPath, path.basename(fileRange[1]));
// ...
}
}
}
} Tests were run Let's examine processing of the cover profile file:
SolutionI think, the best solution is to pass the path of a project root instead of the path of tested package: Then we should trim module path ( Updated processing of the cover profile file:
I tried to realize this, but I am not sure how to define Module Path (and I couldn't find any function for that). Also because of lack of experience with working on VS Code Extensions I am not sure how to pass project root (can we just use workspace root?) I hope my little investigation will help to fix this bug :) |
@ramya-rao-a hello. What do you think about this "investigation"? I can fix this bug myself, but I have some questions:
Also I would like to hear someone else's thoughts about the solution I suggested. |
I believe that for go the workspace root makes more sense. Looking at the Standard Go Project Layout suggests that projects are organised this way. But that is just my opinion. |
Your investigation is right on the spot @ajackson-cpi
You can use the utility function getWorkspaceFolderPath() to get the workspace root.
An option that applies only if you are using GOPATH and not modules is to use the getCurrentGoWorkspaceFromGOPATH(). One can join this with the the relative path in the cover profile to get the absolute path. |
Hello all, We are in the midst of a repo move, see We are moving section in our readme for more details. Closing this issue in favor of golang/vscode-go#108. Please subscribe to it for further updates. Thanks for all the support & Happy Coding! |
'go test cover' doesn't consider coverage via other packages' tests.
Please make it possible to use coverage tools that do, like:
https://github.com/haya14busa/goverage
The text was updated successfully, but these errors were encountered: