Function: bazel--branch-coverage-string

bazel--branch-coverage-string is a natively compiled function defined in bazel.el.

Signature

(bazel--branch-coverage-string BLOCK-TABLE)

Documentation

Return a branch coverage information string for BLOCK-TABLE.

BLOCK-TABLE must be a hashtable mapping block indices to hashtables mapping branch indices to branch hit counts (or nil, for unevaluated blocks). The returned string is suitable for display in the buffer margins. Return nil if there’s no branch coverage data in BLOCK-TABLE. See Info node (elisp) Display Margins.

Source Code

;; Defined in /nix/store/ws8pkszjvcad1rgzqw6wja7qxacylfhn-emacs-packages-deps/share/emacs/site-lisp/elpa/bazel-20261002.1510/bazel.el
(defun bazel--branch-coverage-string (block-table)
  "Return a branch coverage information string for BLOCK-TABLE.
BLOCK-TABLE must be a hashtable mapping block indices to
hashtables mapping branch indices to branch hit counts (or nil,
for unevaluated blocks).  The returned string is suitable for
display in the buffer margins.  Return nil if there’s no branch
coverage data in BLOCK-TABLE.
See Info node ‘(elisp) Display Margins’."
  (declare (ftype (function (hashtable) (or string null))))
  (cl-check-type block-table hash-table)
  ;; Extract block and branch information into association lists, and sort them
  ;; for stability.
  (let ((block-list ())
        (plus (propertize "+" 'face 'bazel-covered-line))
        (minus (propertize "−" 'face 'bazel-uncovered-line)))
    (maphash
     (lambda (block-index branch-table)
       (cl-check-type block-index natnum)
       (cl-check-type branch-table hash-table)
       (let ((branch-list ())
             (executedp nil))
         (maphash
          (lambda (branch-index hits)
            (cl-check-type branch-index natnum)
            (cl-check-type hits (or null natnum))
            (push (cons branch-index hits) branch-list)
            (when hits (setq executedp t)))
          branch-table)
         ;; Ignore blocks that weren’t executed at all.
         (when executedp
           ;; Sort by branch index, then drop the arbitrary branch indices.  We
           ;; display branch coverage similar to the output of ‘geninfo’: a plus
           ;; sign for a covered branch, a minus sign for an uncovered branch,
           ;; and a question mark for a branch in a basic block that was never
           ;; executed.  The latter case shouldn’t really happen in practice
           ;; since we drop unexecuted blocks in ‘bazel--parse-coverage’.
           (let ((string (cl-loop for (_ . hits) in (sort branch-list
                                                          #'car-less-than-car)
                                  concat (cl-case hits
                                           ((nil) "?")
                                           (0 minus)
                                           (otherwise plus)))))
             (push (cons block-index string) block-list)))))
     block-table)
    (when block-list
      ;; Sort by block index, then drop the arbitrary block indices.
      (mapconcat #'cdr (sort block-list #'car-less-than-car) " "))))