To reproduce the bug:
1. Save the above code as bug.el
2. emacs -Q
3. C-x C-f bug.el RET
4. M-: (require 'testcover) RET
5. M-x testcover-start RET bug.el RET
Result: "Wrong type argument: consp, nil" and foo does not get defined.
(symbol-function #'my-defun) reveals that there is a call to
edebug-after in the definition that did not get replaced by testcover-after.
In GNU Emacs 184.108.40.206 (x86_64-apple-darwin15.6.0, NS appkit-1404.47 Version 10.11.6 (Build 15G1004))
of 2016-10-19 built on rainbow.local
Repository revision: 911ade134058c633ab9bec75f664d44aa1faaac3
Windowing system distributor 'Apple', version 10.3.1404
For information about GNU Emacs and the GNU system, type C-h C-a.
Eager macro-expansion failure: (wrong-type-argument consp nil) [2 times]
cons: Wrong type argument: consp, nil
'configure --with-ns --disable-ns-self-contained'
value of $LANG: en_US.UTF-8
Major mode: Emacs-Lisp
Minor modes in effect:
bug#24743: 26.0.50; Testcover does not correctly instrument a macro that uses defun
I've found several other macros in Emacs that cause the "Wrong type
argument: consp, nil" error after you use testcover-start on the files
they are defined in, because testcover is leaving edebug-before and
edebug-after in the definition: