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

section could not be matched when `sectionFileName="/xxx/../xx"` #351

Open agfn opened 2 years ago

agfn commented 2 years ago

Describe the bug

When sectionFileName inlcov.info file contains .., function checkSectionAbsolute (used to match coverage section and source file) does not work correctly.

To Reproduce Steps to reproduce the behaviour:

  1. lcov.info contains the follow content:
SF:/home/lt/projects/libfuzz/json-c/build/../arraylist.c
FN:40,array_list_new
FN:45,array_list_new2
FN:65,array_list_free
FN:75,array_list_get_idx
FN:107,array_list_shrink
FN:130,array_list_put_idx
...
end_of_record
  1. Then, you will found json-c/arraylist.c file will be marked as "No Coverage". Because checkSectionAbsolute only check suffix, and sectionFileName is not simplified absolute path.

Expected behaviour

Screenshots

image

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

agfn commented 2 years ago

can be fixed by the following patch:

--- a/src/helpers.ts
+++ b/src/helpers.ts
@@ -1,3 +1,4 @@
+import {normalize} from "path";

 /**
  * Finds the matching suffixes of the string, stripping off the non-matching starting characters.
@@ -28,7 +29,7 @@ export function findIntersect(base: string, comparee: string): string {
  * @param fileName File name to remove OS specific features
  */
 export function normalizeFileName(fileName: string): string {
-    let name = fileName;
+    let name = normalize(fileName);
     // make file path relative and OS independent
     name = name.toLocaleLowerCase();
     // remove all file slashes
ryanluker commented 2 years ago

@agfn Thanks for the ticket and the fix! This will go out in 2.9.0 and I will try to get a PR up today for you to review (the fix is pretty much what you added above but I am trying to add some test coverage to prevent regressions in the future).

ryanluker commented 2 years ago

@agfn I have a first try here at the fix you mentioned https://github.com/ryanluker/vscode-coverage-gutters/pull/352 there might be a bit of cleanup left over as normalizing the file name causes some other tests to fail 🤔.

The failing tests are just unit level ones though, so most likely just a simple cleanup 😁.