AdamNiederer / cov

An emacs extension for displaying coverage data on your code
GNU General Public License v3.0
76 stars 16 forks source link

Alist key mismatch leads to "No coverage data found" message. #23

Closed FinnG closed 2 years ago

FinnG commented 5 years ago

I installed cov through MELPA today; I have a repository with a structure resembling the following:

<repo>/subdir/source_file.c
<repo>/coverage/source_file.c.gcov

As such, I've set my cov-coverage-file-paths variable to the following:

("../coverage" "coverage")

When I open subdir/source_file.c and enable cov-mode I get an error No coverage data found for <repo>/subdir/source_file.c., despite there being a *.gcov file available. Some cursory inspection with edebug shows that the alist in the relevant cov-data-coverage slot has key source_file.c, but the lookup in cov--get-buffer-coverage is looking for subdir/source_file.c.

This causes the key lookup to fail and cov-set-overlays prints the above error message.

FinnG commented 5 years ago
diff --git a/cov.el b/cov.el
index 38d4aff..2ec6f6c 100644
--- a/cov.el
+++ b/cov.el
@@ -418,9 +418,9 @@ it if necessary, or reloading if the file has changed."

         (add-hook 'kill-buffer-hook 'cov-kill-buffer-hook)
         ;; Find file coverage.
-        (let ((common (f-common-parent (list file (buffer-file-name)))))
-          (cdr (assoc (string-remove-prefix common (buffer-file-name))
-                      (cov-data-coverage stored-data))))))))
+        (cdr (assoc (file-name-nondirectory (buffer-file-name))
+                    (cov-data-coverage stored-data)))))))

 (defun cov--load-coverage (coverage file &rest ignore-current)
   "Load coverage data into COVERAGE from FILE.

This patch appears to fix the issue for me. I ran this through the test suite and it seems there's a failing test that appears to be unrelated to this issue (#24). I'd be happy to submit this as a pull request, but will await advice depending on the outcome of #24!