aboutsummaryrefslogtreecommitdiff
path: root/tests/test-coverage-core--command.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-04-23 01:11:54 -0500
committerCraig Jennings <c@cjennings.net>2026-04-23 01:11:54 -0500
commitfe142a8d9268c36b6b8fd363e60cb587dded1602 (patch)
tree254b06931402efe3111992ccb0322b46e528c5e9 /tests/test-coverage-core--command.el
parent3fa47b1a3b7dd8d3a4f00f117e6f97caf55a3c5d (diff)
downloaddotemacs-fe142a8d9268c36b6b8fd363e60cb587dded1602.tar.gz
dotemacs-fe142a8d9268c36b6b8fd363e60cb587dded1602.zip
feat(coverage): add cj/coverage-report command and F7 binding
Completes the coverage v1 user-facing path. cj/coverage-report is the interactive entry point: 1. Resolves the backend for the current project (honoring cj/coverage-backend from .dir-locals.el). 2. Prompts for a git-diff scope via completing-read (Working tree, Staged, Branch vs parent, Branch vs main). 3. Reads the cached simplecov report, intersects with the diff, renders records into a *Coverage Report* buffer. 4. If the report doesn't exist, prompts to run coverage first. With a prefix argument, re-runs regardless. The report buffer uses cj/coverage-report-mode, a compilation-mode derivative. Uncovered-line entries are formatted as path:line: uncovered so the standard gnu compilation-error-regexp-alist picks them up for next-error navigation. That means M-g n, M-g p, and C-x backtick walk through uncovered lines from any buffer without switching focus. F7 is bound to the command globally, matching the F-key layout ticket's design (F4 compile+run, F5 debug, F6 test, F7 coverage). Added to init.el: (require 'coverage-core) + (require 'coverage-elisp). Tests cover the pure scope-label helpers (label to symbol, symbol to label, roundtrip) plus a smoke test that exercises the full command with stubbed backend, stubbed completing-read, stubbed shell-command-to-string, and a prepared simplecov fixture. Coverage v1 is now functionally complete: make coverage produces the report, F7 drives the interactive flow.
Diffstat (limited to 'tests/test-coverage-core--command.el')
-rw-r--r--tests/test-coverage-core--command.el90
1 files changed, 90 insertions, 0 deletions
diff --git a/tests/test-coverage-core--command.el b/tests/test-coverage-core--command.el
new file mode 100644
index 00000000..d7b2c1cc
--- /dev/null
+++ b/tests/test-coverage-core--command.el
@@ -0,0 +1,90 @@
+;;; test-coverage-core--command.el --- Tests for cj/coverage-report and scope helpers -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Unit tests for:
+;; `cj/--coverage-scope-from-label' (pure label → symbol lookup)
+;; `cj/--coverage-label-from-scope' (pure symbol → label lookup)
+;; `cj/coverage-report' (one smoke test with stubbed git + prepared report)
+
+;;; Code:
+
+(require 'ert)
+(require 'cl-lib)
+
+(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
+(require 'coverage-core)
+
+;;; Scope label <-> symbol (pure lookups)
+
+(ert-deftest test-coverage-scope-from-label-known ()
+ "Normal: each registered label maps to its scope symbol."
+ (should (eq 'working-tree
+ (cj/--coverage-scope-from-label
+ "Working tree — all uncommitted changes")))
+ (should (eq 'staged
+ (cj/--coverage-scope-from-label "Staged — about to commit")))
+ (should (eq 'branch-vs-parent
+ (cj/--coverage-scope-from-label "Branch vs parent")))
+ (should (eq 'branch-vs-main
+ (cj/--coverage-scope-from-label "Branch vs main"))))
+
+(ert-deftest test-coverage-scope-from-label-unknown ()
+ "Boundary: unknown label returns nil."
+ (should-not (cj/--coverage-scope-from-label "bogus label"))
+ (should-not (cj/--coverage-scope-from-label "")))
+
+(ert-deftest test-coverage-label-from-scope-roundtrip ()
+ "Normal: symbol → label → symbol is an identity."
+ (dolist (sym '(working-tree staged branch-vs-parent branch-vs-main))
+ (should (eq sym (cj/--coverage-scope-from-label
+ (cj/--coverage-label-from-scope sym))))))
+
+;;; Smoke test for the interactive command
+
+(ert-deftest test-coverage-report-smoke-happy-path ()
+ "Smoke: cj/coverage-report with stubbed backend, scope, and git-diff
+populates the *Coverage Report* buffer with the expected summary and
+uncovered-line markers."
+ (let* ((tmp-root (make-temp-file "test-coverage-smoke-" t))
+ (report-file (expand-file-name "simplecov.json" tmp-root))
+ (simplecov (concat "{\"run\":{\"timestamp\":1,\"coverage\":"
+ "{\"modules/foo.el\":[null,1,0,1,0]}}}"))
+ (diff-output (concat "diff --git a/modules/foo.el b/modules/foo.el\n"
+ "--- a/modules/foo.el\n"
+ "+++ b/modules/foo.el\n"
+ "@@ -1,0 +2,4 @@\n"
+ "+added 1\n+added 2\n+added 3\n+added 4\n"))
+ (test-backend
+ (list :name 'test-backend
+ :detect (lambda (_) t)
+ :run (lambda (cb) (funcall cb report-file))
+ :report-path (lambda (&rest _) report-file)))
+ (cj/coverage-backends nil))
+ (unwind-protect
+ (progn
+ (with-temp-file report-file (insert simplecov))
+ (cj/coverage-register-backend test-backend)
+ (cl-letf (((symbol-function 'completing-read)
+ (lambda (&rest _) "Staged — about to commit"))
+ ((symbol-function 'shell-command-to-string)
+ (lambda (_) diff-output))
+ ((symbol-function 'cj/--coverage-project-root)
+ (lambda () tmp-root))
+ ((symbol-function 'display-buffer) #'identity))
+ (call-interactively #'cj/coverage-report))
+ (with-current-buffer "*Coverage Report*"
+ (let ((text (buffer-substring-no-properties (point-min) (point-max))))
+ ;; Scope label appears
+ (should (string-match-p "Staged" text))
+ ;; Lines 2 and 4 hit, lines 3 and 5 uncovered (per simplecov)
+ ;; Diff covers lines 2-5
+ ;; So the summary should show 2 of 4 covered
+ (should (string-match-p "2 of 4" text))
+ ;; Uncovered line markers use compilation-friendly format
+ (should (string-match-p "modules/foo\\.el:[35]: uncovered" text)))))
+ (when (get-buffer "*Coverage Report*")
+ (kill-buffer "*Coverage Report*"))
+ (delete-directory tmp-root t))))
+
+(provide 'test-coverage-core--command)
+;;; test-coverage-core--command.el ends here