1

I'm writing some tests for my first emacs package but am running into an issue to do with asserting that two text properties are the same - one that's created with # and another with propertize:

;; this fails
(ert-deftest equal-properties ()
  (should
   (equal-including-properties
    #("Utils" 0 5 (:annotation nil :candidate "type" :meta nil))
    (propertize "Utils" :annotation nil :candidate "type" :meta nil))))

In the ert runner, the forms look the same as well:

F equal-properties
    (ert-test-failed
     ((should
       (equal-including-properties
        #("Utils" 0 5
          (:meta nil :candidate "type" :annotation nil))
        (propertize "Utils" :annotation nil :candidate "type" :meta nil)))
      :form
      (equal-including-properties
       #("Utils" 0 5
         (:meta nil :candidate "type" :annotation nil))
       #("Utils" 0 5
         (:meta nil :candidate "type" :annotation nil)))
      :value nil))

Any pointers would be much appreciated, I'm sure (/I hope) I've missed something simple!

xdl
  • 125
  • 3
  • 1
    It's probably related to [Bug#6581 - `equal-including-properties` uses `eq` to compare property values](https://debbugs.gnu.org/cgi/bugreport.cgi?bug=6581) – npostavs Jun 28 '18 at 12:27
  • Thanks for pointing this out! Will get around it for now with custom function then. – xdl Jun 28 '18 at 14:23
  • @npostavs or OP: Please consider posting that as an answer. If correct, OP: please consider accepting the answer. Thx. – Drew Jun 28 '18 at 15:58
  • @npostavs Happy for you to post that link in an answer and I'll accept – xdl Jun 28 '18 at 16:52

1 Answers1

2

This is due to Bug#6581 - equal-including-properties uses eq to compare property values, hence your :candidate "type" property string values may compare non-eq. If you byte compile the test code, you might find it works because the compiler coalesces string literals (e.g., Bug#31688).

You could consider using a symbol instead of a string, if that makes sense for your purposes:

#("Utils" 0 5 (:meta nil :candidate type :annotation nil))
npostavs
  • 9,033
  • 1
  • 21
  • 53
  • Thanks for the link and the suggestion for using a symbol - I'll look into that. Right now I am getting around this for just my use case with `(defun text-property-equal (t1 t2) (and (equal (text-properties-at 0 t1) (text-properties-at 0 t2)) (string= t1 t2)))` – xdl Jun 29 '18 at 00:36