unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#35018: 26.1; Use diff as en ert-explainer for string=
@ 2019-03-27 10:19 Pierre Neidhardt
  2019-04-02  1:05 ` Noam Postavsky
  2021-06-23 13:42 ` Lars Ingebrigtsen
  0 siblings, 2 replies; 10+ messages in thread
From: Pierre Neidhardt @ 2019-03-27 10:19 UTC (permalink / raw)
  To: 35018

[-- Attachment #1: Type: text/plain, Size: 1456 bytes --]


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)
      (unwind-protect
          (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
                  (with-temp-buffer
                    ;; 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 (current-buffer))
                    (buffer-string)))
            result)
        (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 :)

[-- Attachment #2.1: Type: text/plain, Size: 48 bytes --]


-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #2.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-10-13 11:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-27 10:19 bug#35018: 26.1; Use diff as en ert-explainer for string= Pierre Neidhardt
2019-04-02  1:05 ` Noam Postavsky
2019-04-02  7:59   ` Pierre Neidhardt
2021-06-23 13:42 ` Lars Ingebrigtsen
2021-06-24  7:06   ` Pierre Neidhardt
2021-06-24 14:52     ` Lars Ingebrigtsen
2021-06-24 15:59       ` Pierre Neidhardt
2021-10-12 15:33         ` Lars Ingebrigtsen
2021-10-12 17:23           ` Pierre Neidhardt
2021-10-13 11:21             ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).