Subject: Re: bug#40562: [patch] Treat records as arrays in ert object comparisons and add support for cl-structs

From: Clément Pit-Claudel <[email-masked]>
Date: Sat, 11 Apr 2020 23:06:47 -0400

On 11/04/2020 19.26, Štěpán Němec wrote:
> This is incorrect, as witnessed by your very example (`c' instead of
> `b'). Records are accessible with `aref', but the first slot is the type
> descriptor, so you're making an off-by-one error here.

Of course, it should be `for slot in (cl-struct-slot-info (type-of a))` not `for slot in (cdr (cl-struct-slot-info (type-of a)))`.  Updated patch attached.

Thanks for the review!
>From 129ba8aeaa91b6ea44a325ec237f3df7e9400c9f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Pit-Claudel?= <[email-masked]>
Date: Sat, 11 Apr 2020 16:23:47 -0400
Subject: [PATCH 2/2] * lisp/emacs-lisp/ert.el (ert--explain-equal-rec): Add
 support for cl-structs

---
 lisp/emacs-lisp/ert.el | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el
index 74202183cc..241eece05b 100644
--- a/lisp/emacs-lisp/ert.el
+++ b/lisp/emacs-lisp/ert.el
@@ -515,6 +515,13 @@ ert--explain-equal-rec
                        `(cdr ,cdr-x)
                      (cl-assert (equal a b) t)
                      nil))))))))
+      ((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)
-- 
2.17.1