Fix ert ability to peek inside structures when comparing unequal values

* lisp/emacs-lisp/ert.el (ert--explain-equal-rec): Treat records
as arrays (bug#40562).  Also add support for cl-structs.
This commit is contained in:
Clément Pit-Claudel 2020-08-18 16:06:29 +02:00 committed by Lars Ingebrigtsen
parent 21c580566e
commit 82893e9e8e

View file

@ -515,7 +515,14 @@ Returns nil if they are."
`(cdr ,cdr-x)
(cl-assert (equal a b) t)
nil))))))))
((pred arrayp)
((pred cl-struct-p)
(cl-loop for slot in (cl-struct-slot-info (type-of a))
for ai across a
for bi across b
for xf = (ert--explain-equal-rec ai bi)
do (when xf (cl-return `(struct-field ,(car slot) ,xf)))
finally (cl-assert (equal a b) t)))
((or (pred arrayp) (pred recordp))
;; For mixed unibyte/multibyte string comparisons, make both multibyte.
(when (and (stringp a)
(xor (multibyte-string-p a) (multibyte-string-p b)))