Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion cov.el
Original file line number Diff line number Diff line change
Expand Up @@ -768,12 +768,51 @@ even if part of the line is outside any narrrowing."
;;;###autoload
(define-minor-mode cov-mode
"Minor mode for cov."
:lighter " cov"
:lighter (:eval (format " cov(%s)" (cov--lighter-indicator)))
(progn
(if cov-mode
(cov-turn-on)
(cov-turn-off))))

;;;###autoload
(defun cov-next-uncovered ()
"Go to next uncovered line."
(interactive)
(let ((next-uncovered (cl-find-if (lambda (line) (> line (line-number-at-pos)))
(sort (cov--buffer-uncovered)))))
(if next-uncovered
(progn (goto-char (point-min))
(forward-line (1- next-uncovered)))
(message "No more uncovered sections."))))

;;;###autoload
(defun cov-prev-uncovered ()
"Go to previous unvocered line."
(interactive)
(let ((prev-uncovered (cl-find-if (lambda (line) (< line (line-number-at-pos)))
(sort (cov--buffer-uncovered) :reverse t))))
(if prev-uncovered
(progn (goto-char (point-min))
(forward-line (1- prev-uncovered)))
(message "No more uncovered sections."))))

(defun cov--buffer-uncovered ()
"Compile list of line numbers of statements that have a zero coverage."
(mapcar #'car (seq-filter (lambda (line) (eql (cadr line) 0)) (cov--get-buffer-coverage))))

(defun cov-number-uncovered ()
"Caclulate number of uncovered statements in current buffer."
(when (cov--get-buffer-coverage)
(length (cov--buffer-uncovered))))

(defun cov--lighter-indicator ()
"Setup string to show how many statements are uncovered in current buffer."
(let ((uncovered (cov-number-uncovered))
(total (length (cov--get-buffer-coverage))))
(if uncovered
(format "%s/%s" uncovered total)
"?")))

(provide 'cov)
;;; cov.el ends here

Expand Down
10 changes: 10 additions & 0 deletions test/clover/uncovered/all-covered
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
comment line

a line executed 100%
a line executed 86%
a line executed 85%
a line executed 84%
a line executed 46%
a line executed 45%
a line executed 44%
a line executed 1%
38 changes: 38 additions & 0 deletions test/clover/uncovered/clover.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1523033009">
<project timestamp="1523033009">
<package name="cov-test">
<file name="one-uncovered">
<line num="3" type="stmt" count="100"/>
<line num="4" type="stmt" count="86"/>
<line num="5" type="stmt" count="85"/>
<line num="6" type="stmt" count="84"/>
<line num="7" type="stmt" count="46"/>
<line num="8" type="stmt" count="45"/>
<line num="9" type="stmt" count="44"/>
<line num="10" type="stmt" count="1"/>
<line num="11" type="stmt" count="0"/>
</file>
<file name="all-covered">
<line num="3" type="stmt" count="100"/>
<line num="4" type="stmt" count="86"/>
<line num="5" type="stmt" count="85"/>
<line num="6" type="stmt" count="84"/>
<line num="7" type="stmt" count="46"/>
<line num="8" type="stmt" count="45"/>
<line num="9" type="stmt" count="44"/>
<line num="10" type="stmt" count="1"/>
</file>
<file name="multiple-uncovered-unsorted">
<line num="3" type="stmt" count="100"/>
<line num="9" type="stmt" count="0"/>
<line num="4" type="stmt" count="86"/>
<line num="8" type="stmt" count="45"/>
<line num="5" type="stmt" count="85"/>
<line num="6" type="stmt" count="0"/>
<line num="7" type="stmt" count="46"/>
<line num="10" type="stmt" count="1"/>
</file>
</package>
</project>
</coverage>
10 changes: 10 additions & 0 deletions test/clover/uncovered/multiple-uncovered-unsorted
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
comment line

a line executed 100%
a line executed 86%
a line executed 85%
first line never executed
a line executed 46%
a line executed 45%
second line never executed
a line executed 1%
9 changes: 9 additions & 0 deletions test/clover/uncovered/no-coverage-data
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
comment line

a line with unknown coverage
a line with unknown coverage
a line with unknown coverage
a line with unknown coverage
a line with unknown coverage
a line with unknown coverage
a line with unknown coverage
11 changes: 11 additions & 0 deletions test/clover/uncovered/one-uncovered
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
comment line

a line executed 100%
a line executed 86%
a line executed 85%
a line executed 84%
a line executed 46%
a line executed 45%
a line executed 44%
a line executed 1%
a line never executed
116 changes: 116 additions & 0 deletions test/cov-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,122 @@ text properties with list values."
(dolist (overlay cov-overlays)
(should (equal (overlay-get overlay 'help-echo) (pop expected)))))))

(ert-deftest cov-mode--next-uncovered-no-uncovered ()
(cov--with-test-buffer "clover/uncovered/all-covered"
(cov-mode 0)
(cov-mode 1)
(mocker-let ((message (msg) ((:input '("No more uncovered sections.")))))
(cov-next-uncovered))))

(ert-deftest cov-mode--next-uncovered-one-uncovered ()
(cov--with-test-buffer "clover/uncovered/one-uncovered"
(cov-mode 0)
(cov-mode 1)
(mocker-let ((message (msg) ((:input '("No more uncovered sections.") :occur 0))))
(cov-next-uncovered))
(should (eql (point) 183))
(mocker-let ((message (msg) ((:input '("No more uncovered sections.") :occur 1))))
(cov-next-uncovered))
(should (eql (point) 183))))

(ert-deftest cov-mode--next-uncovered-two-uncovered ()
(cov--with-test-buffer "clover/uncovered/multiple-uncovered-unsorted"
(cov-mode 0)
(cov-mode 1)
(mocker-let ((message (msg) ((:input '("No more uncovered sections.") :occur 0))))
(cov-next-uncovered))
(should (eql (point) 78))
(mocker-let ((message (msg) ((:input '("No more uncovered sections.") :occur 0))))
(cov-next-uncovered))
(should (eql (point) 146))
(mocker-let ((message (msg) ((:input '("No more uncovered sections.") :occur 1))))
(cov-next-uncovered))
(should (eql (point) 146))))

(ert-deftest cov-mode--prev-uncovered-no-uncovered ()
(cov--with-test-buffer "clover/uncovered/all-covered"
(cov-mode 0)
(cov-mode 1)
(goto-char (point-max))
(mocker-let ((message (msg) ((:input '("No more uncovered sections.")))))
(cov-prev-uncovered))))

(ert-deftest cov-mode--prev-uncovered-one-uncovered ()
(cov--with-test-buffer "clover/uncovered/one-uncovered"
(cov-mode 0)
(cov-mode 1)
(goto-char (point-max))
(mocker-let ((message (msg) ((:input '("No more uncovered sections.") :occur 0))))
(cov-prev-uncovered))
(should (eql (point) 183))
(mocker-let ((message (msg) ((:input '("No more uncovered sections.") :occur 1))))
(cov-prev-uncovered))
(should (eql (point) 183))))

(ert-deftest cov-mode--prev-uncovered-two-uncovered ()
(cov--with-test-buffer "clover/uncovered/multiple-uncovered-unsorted"
(cov-mode 0)
(cov-mode 1)
(goto-char (point-max))
(mocker-let ((message (msg) ((:input '("No more uncovered sections.") :occur 0))))
(cov-prev-uncovered))
(should (eql (point) 146))
(mocker-let ((message (msg) ((:input '("No more uncovered sections.") :occur 0))))
(cov-prev-uncovered))
(should (eql (point) 78))
(mocker-let ((message (msg) ((:input '("No more uncovered sections.") :occur 1))))
(cov-prev-uncovered))
(should (eql (point) 78))))

(ert-deftest cov-mode--number-uncovered-allcovered ()
(cov--with-test-buffer "clover/uncovered/all-covered"
(cov-mode 0)
(cov-mode 1)
(should (eq (cov-number-uncovered) 0))))

(ert-deftest cov-mode--number-uncovered-one-uncovered ()
(cov--with-test-buffer "clover/uncovered/one-uncovered"
(cov-mode 0)
(cov-mode 1)
(should (eq (cov-number-uncovered) 1))))

(ert-deftest cov-mode--number-uncovered-two-uncovered ()
(cov--with-test-buffer "clover/uncovered/multiple-uncovered-unsorted"
(cov-mode 0)
(cov-mode 1)
(should (eq (cov-number-uncovered) 2))))

(ert-deftest cov-mode--number-uncovered-no-coverage-data ()
(cov--with-test-buffer "clover/uncovered/no-coverage-data"
(cov-mode 0)
(cov-mode 1)
(should (eq (cov-number-uncovered) nil))))


(ert-deftest cov-mode--lighter-allcovered ()
(cov--with-test-buffer "clover/uncovered/all-covered"
(cov-mode 0)
(cov-mode 1)
(should (equal (cov--lighter-indicator) "0/8"))))

(ert-deftest cov-mode--lighter-one-uncovered ()
(cov--with-test-buffer "clover/uncovered/one-uncovered"
(cov-mode 0)
(cov-mode 1)
(should (equal (cov--lighter-indicator) "1/9"))))

(ert-deftest cov-mode--lighter-two-uncovered ()
(cov--with-test-buffer "clover/uncovered/multiple-uncovered-unsorted"
(cov-mode 0)
(cov-mode 1)
(should (equal (cov--lighter-indicator) "2/8"))))

(ert-deftest cov-mode--lighter-no-coverage-data ()
(cov--with-test-buffer "clover/uncovered/no-coverage-data"
(cov-mode 0)
(cov-mode 1)
(should (equal (cov--lighter-indicator) "?"))))

;; Local Variables:
;; indent-tabs-mode: nil
;; End: