A test coverage library for Emacs Lisp.
Few important notes about undercover.el:
- it assumes a certain development cycle of your package (using Cask, Travis CI, and Coveralls), Codecov, or compatible;
- it doesn't support test coverage for byte-compiled files;
- it based on
edebugand can have some issues with macros coverage. It doesn't support Circular Objects.
Check out combined usage example and buttercup integration example for more information.
-
Add
undercover.elto your Cask file:(source gnu) (source melpa) (package-file "awesome-package.el") (development (depends-on "undercover"))
-
Before
loadorrequireyour package intest/test-helper.elorfeatures/support/env.el(or analogue), callundercoverwith wildcards that will match package files:(when (require 'undercover nil t) (undercover "*.el" "awesome-extensions/*.el" (:exclude "awesome-examples.el"))) (require 'awesome-package)
-
For coverage services other than Coveralls, add the relevant command to
.travis.yml. For example:
after_success:
# Upload coverage
- bash <(curl -s https://codecov.io/bash)
-
If you don't use Travis CI you need to set
COVERALLS_REPO_TOKENenvironment variable before running tests, for example:$ COVERALLS_REPO_TOKEN=<your-coveralls-repo-token> cask exec ert-runner
-
Set
report-typeif not using Coveralls:(undercover "*.el" (:report-type :codecov))
-
Set
report-fileoption if you want to change report location:(undercover "*.el" (:report-file "/tmp/local-report.json"))
undercover.elwill try to merge new report with existing one. -
Set
send-reportoption tonilif you don't want to send coverage report:(undercover "*.el" (:report-file "/tmp/local-report.json") (:send-report nil))
-
Set
UNDERCOVER_FORCEenvironment variable if you want to do coverage calculation locally:$ UNDERCOVER_FORCE=true cask exec ert-runner -
Set
UNDERCOVER_CONFIGif you want to configureundercover.elvia environment variables:(when (require 'undercover nil t) (undercover))
$ UNDERCOVER_CONFIG='("*.el" (:exclude "awesome-examples.el"))' cask exec ert-runner
-
If you get
"UNDERCOVER: No coverage information [...]", make sure of the following:- remove byte-compiled files (
*.elc) of your project - load and configure undercover before your project files (see above)
- make sure ert-runner does not load your project files (your project's
.ert-runnershould use-Linstead of-lfor files you want to measure coverage of)
- remove byte-compiled files (
-
If you want to measure code coverage locally, you can set
TRAVIS=truein the shell environment or(setq undercover-force-coverage t)in emacs.