[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#35018: 26.1; Use diff as en ert-explainer for string=

From: Pierre Neidhardt
Subject: bug#35018: 26.1; Use diff as en ert-explainer for string=
Date: Wed, 27 Mar 2019 11:19:07 +0100

I've just committed webfeeder.el to ELPA.  In his review, Stefan Monnier
suggested we merged the following code snippet upstream:

--8<---------------cut here---------------start------------->8---
(defun webfeeder--string=-explainer (string-a string-b)
  "Return the diff output of STRING-A and STRING-B"
  (unless (string= string-a string-b)
    (let (file-a file-b)
          (let (result)
            (setq file-a (make-temp-file "webfeeder")
                  file-b (make-temp-file "webfeeder"))
            (with-temp-file file-a
              (insert string-a))
            (with-temp-file file-b
              (insert string-b))
            (setq result
                    ;; The following generates a *Diff* buffer which is
                    ;; convenient for coloration.
                    (diff file-a file-b nil 'no-async)
                    (diff-no-select file-a file-b nil 'no-async 
        (delete-file file-a)
        (delete-file file-b)))))

;; FIXME: Add this to ERT!
(put 'string= 'ert-explainer #'webfeeder--string=-explainer)
--8<---------------cut here---------------end--------------->8---

I've used this feature extensively in my ERT tests: it displays a "diff"
of string A and string B, which is a pretty nice default when the
strings are longer than a single line.

Food for thoughts :)
Pierre Neidhardt

Attachment: signature.asc
Description: PGP signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]