Zachary K
Zachary K

Reputation: 3335

Displaying EUnit code coverage in Emacs

I am using Rebar to build my erlang project and want to integrate it more tightly with Emacs. I found that if I add {cover_print_enabled, true}. to my rebar config file I get code coverage in the build output.

However there is also an option cover_export_enabled which outputs a binary file of some form. Is there an emacs plugin to parse that file and color code my code to show what code is covered by tests?

I really don't like having to switch to a browser to see code coverage.

Upvotes: 2

Views: 560

Answers (2)

Leo
Leo

Reputation: 121

Just added this feature to rebar.el in commit https://github.com/leoliu/rebar.el/commit/9ba8699ff6310721226b93341e62491ebfd0ee99

Leo

Upvotes: 0

legoscia
legoscia

Reputation: 41568

As far as I know, there is no such plugin.

The exported cover data file can be read as follows:

  1. Read one byte, giving the length of the next term; let's call it N.
  2. Read N bytes in Erlang binary term format. This can be decoded with binary_to_term/1.
  3. If the term from step 2 is of the form {'$size',X}, then read X bytes and decode as a term. (This happens when the binary representation of the term is longer than 255 bytes.)
  4. Continue from step 1, until end of file.

Distel has an Emacs Lisp implementation of binary_to_term called erlext-read-obj in erlext.el.

I haven't looked into what to do with the terms in the file, once decoded, but hopefully this is enough to get someone started. Read lib/tools/src/cover.erl if in doubt.

Upvotes: 2

Related Questions