Skip to content

Commit

Permalink
First attempt to support test coverage using the testcover package (#494
Browse files Browse the repository at this point in the history
)
  • Loading branch information
matsl committed Apr 1, 2024
1 parent 32f6c69 commit cf3d17b
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@

2024-03-31 Mats Lidell <matsl@gnu.org>

* Makefile (coverage): Make target to use the coverage function from the
command line.

* test/hy-test-coverage.el: New test file for producing test coverage
data. Uses the testcover package.
(hy-test--count-coverage): Count the test splotches.
(hy-test-coverage-file): Run tests and produce coverage date.

* .github/workflows/main.yml (jobs): Add Emacs 29.3 to versions used for
the CI builds.

Expand Down
21 changes: 20 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Author: Bob Weiner
#
# Orig-Date: 15-Jun-94 at 03:42:38
# Last-Mod: 29-Mar-24 at 23:29:53 by Mats Lidell
# Last-Mod: 31-Mar-24 at 23:05:09 by Mats Lidell
#
# Copyright (C) 1994-2023 Free Software Foundation, Inc.
# See the file HY-COPY for license information.
Expand Down Expand Up @@ -562,3 +562,22 @@ endif

dockerized:
docker run -v $$(pwd):/hyperbole -it silex/emacs:${DOCKER_VERSION} bash -c cd hyperbole && make ${DOCKER_TARGETS}

# Run with coverage. Run tests given by testspec and monitor the
# coverage for the specified file.
#
# Usage:
# make coverage file=<file> testspec=<testspec>

# Specify file to inspect for coverage while running tests given by testspec
COVERAGE_FILE = ${file}
ifeq ($(origin testspec), command line)
COVERAGE_TESTSPEC = ${testspec}
else
COVERAGE_TESTSPEC = t
endif
coverage:
$(EMACS) --quick $(PRELOADS) \
--eval "(load-file \"test/hy-test-dependencies.el\")" \
--eval "(load-file \"test/hy-test-coverage.el\")" \
--eval "(hy-test-coverage-file \"${file}\" \"${COVERAGE_TESTSPEC}\")"
1 change: 1 addition & 0 deletions test/MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ hsys-org-tests.el - hsys-org tests
hui-register-tests.el - test for hui-register
hui-select-tests.el - hui-select tests
hui-tests.el - tests for hui.el Hyperbole UI
hy-test-coverage.el - provide test coverage information
hy-test-dependencies.el - Hyperbole test dependencies
hy-test-helpers.el - unit test helpers
hypb-tests.el - tests for hypb.el utility functions
Expand Down
57 changes: 57 additions & 0 deletions test/hy-test-coverage.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
;;; hy-test-coverage.el --- support for test coverage -*- lexical-binding: t; -*-
;;
;; Author: Mats Lidell
;;
;; Orig-Date: 21-Mar-24 at 13:22:27
;; Last-Mod: 31-Mar-24 at 23:00:30 by Mats Lidell
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
;; Copyright (C) 2024 Free Software Foundation, Inc.
;; See the "HY-COPY" file for license information.
;;
;; This file is part of GNU Hyperbole.

;;; Commentary:
;;
;; Uses the testcover functionality and runs the a specified test
;; suite for a file that is monitored for coverage. See
;; "testcover.el" for how to interpret the "splotches", the color code
;; characters in the monitored filed.
;;
;; See also "../Makefile#coverage", a make target for running from the
;; command line.

;;; Code:

(require 'hypb-ert)
(require 'testcover)

(defun hy-test--count-coverage ()
"Count coverage splotches."
(cl-count-if
(lambda (x)
(string-prefix-p "testcover-" (symbol-name (overlay-get x 'face))))
(car (overlay-lists))))

(defun hy-test-coverage-file (filename &optional testspec)
"Run TESTSPEC and produce coverage data for FILENAME.
With no TESTSPEC all tests are used."
(interactive "fFilename: \nsTestspec: ")
(unless (file-exists-p filename)
(error "(hy-test-coverage-file) - File %s does not exist" filename))
(unless testspec
(setq testspec t))
(let ((buff (find-file filename)))
(testcover-unmark-all buff)
(hypb-ert-require-libraries)
(testcover-start filename)
(bury-buffer)
(ert testspec)
(testcover-mark-all buff)
(message "Number of splotches %d." (hy-test--count-coverage))
(switch-to-buffer buff)
(point-min)))

(provide 'hy-test-coverage)
;;; hy-test-coverage.el ends here

0 comments on commit cf3d17b

Please sign in to comment.