GNU bug report logs - #40562
[patch] Treat records as arrays in ert object comparisons and add support for cl-structs

Previous Next

Package: emacs;

Reported by: Clément Pit-Claudel <cpitclaudel <at> gmail.com>

Date: Sat, 11 Apr 2020 20:36:01 UTC

Severity: normal

Tags: fixed, patch

Fixed in version 28.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


Message #8 received at 40562 <at> debbugs.gnu.org (full text, mbox):

From: Štěpán Němec <stepnem <at> gmail.com>
To: Clément Pit-Claudel <cpitclaudel <at> gmail.com>
Cc: lars <lars <at> nocrew.org>, 40562 <at> debbugs.gnu.org
Subject: Re: bug#40562: [patch] Treat records as arrays in ert object
 comparisons and add support for cl-structs
Date: Sun, 12 Apr 2020 01:26:41 +0200
On Sat, 11 Apr 2020 16:34:57 -0400
Clément Pit-Claudel wrote:

[...]

> (defvar xyz123 (make-xyz :a 1 :b 2 :c 3))
> (defvar xyz143 (make-xyz :a 1 :b 4 :c 3))

[...]

> The first attached patch fixes this for all records.

Seems like a nice addition.

> Test failed: ((should (equal xyz123 xyz143)) 
>   :form (equal #s(xyz 1 2 3) #s(xyz 1 4 3))
>   :value nil
>   :explanation (struct-field c (different-atoms (2 "#x2" "?") (4 "#x4" "?"))))
                               ^gotcha

>  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..e3666a84c0 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 (cdr (cl-struct-slot-info (type-of a)))
> +                for ai across a
                   ^^^^^^^^^^^^^^^

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.

> +                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)

Thanks,

  Štěpán




This bug report was last modified 4 years and 278 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.