ryanluker / vscode-coverage-gutters

Display test coverage generated by lcov and xml - works with many languages
https://marketplace.visualstudio.com/items?itemName=ryanluker.vscode-coverage-gutters
MIT License
460 stars 88 forks source link

Cannot load coverage file #161

Closed Gorthog closed 5 years ago

Gorthog commented 6 years ago

Using VS code 1.26 and coverage gutters 2.1.1

Coverage file is not loaded automatically, even though it resides in root and names Icov.info. When I execute preview coverage report - no files are shown.

image

Not sure if that's important but I'm using C# and generating the icov file using coverlet.

mullim commented 6 years ago

I'm also running into this issue. I use istanbul & nyc so my icov file is in a coverage directory. I've also tried moving it into the root directory and still get the same error.

ryanluker commented 6 years ago

@sinapis Thanks for submitting an issue. I havent looked lately into the preview report functionality so I will have to take a look at that for the next bugfix release (2.1.2). In the meantime can you install [0] and see if version 2.0.x allows you to still use the preview functionality?

[0] https://code.visualstudio.com/docs/editor/extension-gallery#_install-from-a-vsix

nverinaud commented 6 years ago

Same here ! How can I help to resolve this ?

Version 1.3.0 works as a workaround.

Gorthog commented 6 years ago

for me neither 1.3.0 or 2.0.1 worked. any suggestions to make this work would be very welcome...

mullim commented 6 years ago

I found that 2.2.0 works fine on Mac, I couldn't get it to pick up the lcov file on Windows. I'm assuming it has something to do with the path to the lcov file.

Gorthog commented 6 years ago

I'm on windows so we get a consistent behavior

ryanluker commented 6 years ago

Thanks for the extra info everyone. @nverinaud @sinapis and @mulligan121 can you try a few things for me and paste the resulting logs here? 1) checkout this repo and open the examples folder in vscode 2) turn on the coverage watch 3) open a source file or two from each of the language folders

You should all get something similar to this:

[1537324127343][coverageservice]: INITIALIZING
[1537324133723][coverageservice]: LOADING
[1537324133773][coverageservice]: Loading 5 file(s)
[1537324133857][lcovparser][convertPartialPathsToAbsolute]: Error: Found too many files with partial path __init__.py
[1537324133996][coverageservice]: Caching 13 coverage(s)
[1537324133997][coverageservice]: READY
[1537324139781][coverageservice]: RENDERING
[1537324139783][renderer][section file path]: c:\dev\vscode-coverage-gutters\example\python\python\foobar\tests\foo\a.py
[1537324139784][coverageservice]: READY
[1537324145722][coverageservice]: RENDERING
[1537324145723][coverageservice]: READY
[1537324145785][coverageservice]: RENDERING
[1537324145786][renderer][section file path]: /home/ryan/dev/vscode-coverage-gutters/example/php/src/testCoverage/testMain2/main2.php
[1537324145791][coverageservice]: READY
[1537324155317][coverageservice]: RENDERING
[1537324155317][coverageservice]: READY
[1537324155353][coverageservice]: RENDERING
[1537324155354][renderer][section file path]: c:\dev\vscode-coverage-gutters\example\java\my-app\src\main\java\com\mycompany\app\App.java
[1537324155359][coverageservice]: READY
[1537324158623][coverageservice]: RENDERING
[1537324158624][coverageservice]: READY
[1537324159037][coverageservice]: RENDERING
[1537324159037][renderer][section file path]: /mnt/c/dev/vscode-coverage-gutters/example/node/test-coverage.js
[1537324159051][coverageservice]: READY

Hopefully we can get this worked out!

mcauto commented 6 years ago

Same here... on Mac version 1.3.1

ryanluker commented 6 years ago

@mcauto version 1.3.1 is quite old can you try the latest version (2.2.0)?

mcauto commented 6 years ago

@ryanluker I installed it from vscode marketplace.

Before download image

After download

after download
mullim commented 6 years ago

I finally found some free time to debug the issue I was having on my Windows machine. If you have symlinks in any directory when coverage gutters looks for the lcov file it will throw an EPERM error.

glob error Error: EPERM: operation not permitted, scandir `<DIRECTORY>`

This is a really common issue when file walking on Windows and I've ran into it with multiple node modules in the past. If I have time in the next few days I'll see if I can find a fix for this.

ryanluker commented 6 years ago

@mulligan121 thanks for the extra info! I do integration testing via appveyor (for the windows users) but I dont include symlinks in the example projects... (they would have to be setup each CI build inorder to test for something like that). Looking forward to hearing about what you find out if you get time to check this out.

ryanluker commented 6 years ago

@mcauto I think microsoft keeps old builds of my extension and then gives you the one that best matches your vscode version (2.2.0 requires 1.27.x and up for example). Do you have the latest vscode version?

mcauto commented 6 years ago

@ryanluker My vscode version is 1.19.2 so I updated vscode 1.27.x version. but occur same error.. could not find a Coverage file.

ryanluker commented 6 years ago

@mcauto depending on the positioning of the coverage file (needs to be in the folder / workspace you have open) it can cause you to get this error. Can you look at the example project(s) and see if you can get the coverage to be picked up by using a similar structure for your code? https://github.com/ryanluker/vscode-coverage-gutters/tree/master/example

mcauto commented 6 years ago

@ryanluker I want to use coverage-gutters on this project positioning of coverage file is this project root path. What should I do? help me..

mullim commented 5 years ago

@ryanluker I did some more debugging on this and there really isn't a great fix

glob has an option strict: false - When an unusual error is encountered when attempting to read a directory, the process will just continue on in search of other matches. Set the strict option to raise an error in these cases.

This will still output glob error Error: EPERM: operation not permitted, scandir <directory> in the console when debugging but instead of stopping the process and saying the coverage file cannot be found it will continue to walk the rest of the directories and eventually find the lcov file. If you want I can throw up a quick PR adding this option (it will allow coverage gutters to at least work on Windows if symlinks are present). If not I can look into other alternatives such as a different file walker like klaw and see if it produces the same result as glob without diminishing performance.

ryanluker commented 5 years ago

@mcauto the next release (2.2.1) will have some improvements to the relative path detection and the conversion to absolute paths, once that is out let me know if the issue still exists.

@mulligan121 I am thinking a way to fix this would be to allow a manual coverage file(s) settings.json attribute that people could set instead of the automatic one (which would prevent the glob errors). I created a new feature ticket here for that #178 .

tomchavakis commented 5 years ago

Doesn't work at Windows, but works perfectly at Linux-Kubuntu 18.04. The error is the same, can't load the lcov file. I guess that it's something with the absolute paths of the lcov file.

Language: C# .Net Core OS: Windows 10 x64 VSCode : Latest Testing Framework: coverlet - https://github.com/tonerdo/coverlet Coverage Gutters: 2.2.1

mullim commented 5 years ago

@ryanluker turns out it was an issue with the generated symlinks with the framework I was using. Windows classifies symlinks as either files, directories, or junctions (unlike unix based systems). The symlinks were being treated as files when they were actually directories, causing the issue with glob. We switched over to junctions instead and coverage gutters works fine on Windows for me now.

ryanluker commented 5 years ago

@mulligan121 thanks for the update! @tomchavakis do any of the example projects work for you if you check this repository out? Also the 2.3.0 release has a planned feature to allow developers to specify the path to their coverage files as an alternate to the current automatic approach https://github.com/ryanluker/vscode-coverage-gutters/issues/178 .

tomchavakis commented 5 years ago

@ryanluker all the example projects worked. I use coverlet and dotnet core for this project. I can produce a sample of lcov.info in case that helps.

ryanluker commented 5 years ago

@tomchavakis yes a sample lcov.info would assist in the debugging thanks.

Shelim commented 5 years ago

I've run into the same issue; Windows, no symlink in directories (except for .git maybe..?). The project is too large (~4 gb) to produce a meaningful sample. Console output provided:

[1541481176072][coverageservice]: INITIALIZING
[1541481194194][coverageservice]: LOADING
[1541481240226][gutters]: Error Could not find a Coverage file!
[1541481240226][gutters]: Stacktrace Error: Could not find a Coverage file!
    at FilesLoader.<anonymous> (C:\_faerie\dependency\other\visual_studio_code\windows\extensions\ryanluker.vscode-coverage-gutters-2.2.1\out\src\files\filesloader.js:26:23)
    at Generator.next (<anonymous>)
    at fulfilled (C:\_faerie\dependency\other\visual_studio_code\windows\extensions\ryanluker.vscode-coverage-gutters-2.2.1\out\src\files\filesloader.js:4:58)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
[1541481240226][coverageservice]: RENDERING
[1541481240226][coverageservice]: READY
[1541481366007][coverageservice]: RENDERING
[1541481366060][coverageservice]: READY
[1541481457861][coverageservice]: RENDERING
[1541481457864][coverageservice]: READY

Maybe the solution would be the possibility to add option to point to cov.xml directory directly into settings? There is no need to scour through entire project...

tomchavakis commented 5 years ago

navigate to the test folder and generate the coverage file dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=lcov /p:CoverletOutput=./lcov.info Example.csproj

After running again the command it is possible to view the coverage-gutters.

rvanmaanen commented 5 years ago

@tomchavakis that will create a single lcov.info for each test project and coverage gutters won't merge coverage results when there are multiple test projects. I think it shows the results of the last file it finds, so merging needs to be done beforehand with coverlet.

The way this is done is by supplying these arguments: "dotnet-test-explorer.testArguments": "--filter Category!=Integration /p:CollectCoverage=true \"/p:CoverletOutputFormat=\\\"json,lcov\\\"\" /p:CoverletOutput=..\\lcov /p:MergeWith=..\\lcov.json" (yes including all the escaping and extra quotes)

This will create a lcov.json and lcov.info in the root of the workspace and it'll merge the lcov.json each run and then generate a lcov.info based on that merged file. So the endresult is 1 big lcov.info file with coverage from all test projects. It's not in the project directory, so it won't be detected by coveragegutters.

There is another issue here, because it'll merge with any existing lcov.json file, also one from a previous run. So there's still some work to do at the coverlet plugin. Other issues are that it'll not update the merged file properly when removing tests (it seems only to add coverage and not remove lines that aren't covered anymore) and last but not least, it'll crash if there isn't a file to merge with (which is troublesome with the first project you'll run tests on).

For now I did 2 things:

"dotnet-test-explorer.testArguments": "--filter Category!=Integration /p:CollectCoverage=true \"/p:CoverletOutputFormat=\\\"json,lcov\\\"\" /p:CoverletOutput=..\\Project\\lcov /p:MergeWith=..\\Project\\lcov.json",

  <Target Name="ResetCoverageFile" AfterTargets="Build">
    <Copy SourceFiles="..\Project\lcov.empty" DestinationFiles="..\Project\lcov.json" />
  </Target>

lcov.empty is an empty json file, so that will result in a clean slate each time coveragegutters runs, builds all projects and executes all tests, resulting in up-to-date coverage and fixing the problem with the first test run. Issue: Coverage won't be updated when executing single test, but that's fine for us.

Sorry for a long and maybe difficult to follow answer, but thought I'd share what resulted in a workable solution for me. Not really sure if the answer even belongs here, but whatever. Maybe @ryanluker can use it when someone else is asking questions :-)

tomchavakis commented 5 years ago

@rvanmaanen thank you very much for the detailed answer. It is very useful to merge the lcov from different projects and the explanation was great !!!

Shelim commented 5 years ago

I can't produce lcov file, my project is C++ and I use OpenCppCoverage which is able to produce cov.xml only...

ryanluker commented 5 years ago

@tomchavakis were you able to get the coverage to show after using @rvanmaanen 's detailed example?

@Shelim the extension will look for a few default coverage file names and should be able to pick up cov.xml, you can change the names it looks for by setting a different array string here https://github.com/ryanluker/vscode-coverage-gutters/blob/master/package.json#L127.

Shelim commented 5 years ago

@ryanluker I've already tried that... It would be better if I could specify the path inside project to the directory containing cov.xml ; If this matter, I have multi-root workspace in VS Code

tomchavakis commented 5 years ago

@ryanluker the @rvanmaanen answer was really helpful. When I ran again the coverlet command in order to generate the lcov file I get the coverage display from VS Code. So the issue has been resolved from my end.

ryanluker commented 5 years ago

@Shelim that makes sense I have a ticket open to track that feature https://github.com/ryanluker/vscode-coverage-gutters/issues/178 already so I will close this ticket in the meantime as most of the other issues have been solved in here.

If anyone has more issues around not finding coverage files, opening another ticket is probably the best course of action.