diff options
| author | Mattias Engdegård | 2019-10-10 21:20:20 +0200 |
|---|---|---|
| committer | Mattias Engdegård | 2019-10-13 20:29:27 +0200 |
| commit | 67ed6ee7337d66dc1101e41bc2e67bde5ab0ecd4 (patch) | |
| tree | 2ab9cbaee0cd98bd3a01d496c91e6ca4fda041dd | |
| parent | 556ae6674c600e19453a43de51817aa8b4df52fa (diff) | |
| download | emacs-67ed6ee7337d66dc1101e41bc2e67bde5ab0ecd4.tar.gz emacs-67ed6ee7337d66dc1101e41bc2e67bde5ab0ecd4.zip | |
Correctly explain test failures with mixed uni/multibyte strings
* lisp/emacs-lisp/ert.el (ert--explain-equal-rec):
* test/lisp/emacs-lisp/ert-tests.el (ert-test-explain-equal):
When explaining a difference between a unibyte and a multibyte string,
first convert both to multibyte. Otherwise, we might end up comparing
unibyte char C to multibyte char C, 127<C<256, and not detect the
difference (bug#30219).
| -rw-r--r-- | lisp/emacs-lisp/ert.el | 5 | ||||
| -rw-r--r-- | test/lisp/emacs-lisp/ert-tests.el | 23 |
2 files changed, 28 insertions, 0 deletions
diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el index 68762b0752c..47d20cb69e8 100644 --- a/lisp/emacs-lisp/ert.el +++ b/lisp/emacs-lisp/ert.el | |||
| @@ -516,6 +516,11 @@ Returns nil if they are." | |||
| 516 | (cl-assert (equal a b) t) | 516 | (cl-assert (equal a b) t) |
| 517 | nil)))))))) | 517 | nil)))))))) |
| 518 | ((pred arrayp) | 518 | ((pred arrayp) |
| 519 | ;; For mixed unibyte/multibyte string comparisons, make both multibyte. | ||
| 520 | (when (and (stringp a) | ||
| 521 | (xor (multibyte-string-p a) (multibyte-string-p b))) | ||
| 522 | (setq a (string-to-multibyte a)) | ||
| 523 | (setq b (string-to-multibyte b))) | ||
| 519 | (if (/= (length a) (length b)) | 524 | (if (/= (length a) (length b)) |
| 520 | `(arrays-of-different-length ,(length a) ,(length b) | 525 | `(arrays-of-different-length ,(length a) ,(length b) |
| 521 | ,a ,b | 526 | ,a ,b |
diff --git a/test/lisp/emacs-lisp/ert-tests.el b/test/lisp/emacs-lisp/ert-tests.el index 36db1eeb425..3a9e81595b1 100644 --- a/test/lisp/emacs-lisp/ert-tests.el +++ b/test/lisp/emacs-lisp/ert-tests.el | |||
| @@ -627,6 +627,29 @@ This macro is used to test if macroexpansion in `should' works." | |||
| 627 | (should (equal (ert--explain-equal 'a sym) | 627 | (should (equal (ert--explain-equal 'a sym) |
| 628 | `(different-symbols-with-the-same-name a ,sym))))) | 628 | `(different-symbols-with-the-same-name a ,sym))))) |
| 629 | 629 | ||
| 630 | (ert-deftest ert-test-explain-equal-strings () | ||
| 631 | (should (equal (ert--explain-equal "abc" "axc") | ||
| 632 | '(array-elt 1 (different-atoms | ||
| 633 | (?b "#x62" "?b") | ||
| 634 | (?x "#x78" "?x"))))) | ||
| 635 | (should (equal (ert--explain-equal "abc" "abxc") | ||
| 636 | '(arrays-of-different-length | ||
| 637 | 3 4 "abc" "abxc" first-mismatch-at 2))) | ||
| 638 | (should (equal (ert--explain-equal "xyA" "xyÅ") | ||
| 639 | '(array-elt 2 (different-atoms | ||
| 640 | (?A "#x41" "?A") | ||
| 641 | (?Å "#xc5" "?Å"))))) | ||
| 642 | (should (equal (ert--explain-equal "m\xff" "m\u00ff") | ||
| 643 | `(array-elt | ||
| 644 | 1 (different-atoms | ||
| 645 | (#x3fffff "#x3fffff" ,(string-to-multibyte "?\xff")) | ||
| 646 | (#xff "#xff" "?ÿ"))))) | ||
| 647 | (should (equal (ert--explain-equal (string-to-multibyte "m\xff") "m\u00ff") | ||
| 648 | `(array-elt | ||
| 649 | 1 (different-atoms | ||
| 650 | (#x3fffff "#x3fffff" ,(string-to-multibyte "?\xff")) | ||
| 651 | (#xff "#xff" "?ÿ")))))) | ||
| 652 | |||
| 630 | (ert-deftest ert-test-explain-equal-improper-list () | 653 | (ert-deftest ert-test-explain-equal-improper-list () |
| 631 | (should (equal (ert--explain-equal '(a . b) '(a . c)) | 654 | (should (equal (ert--explain-equal '(a . b) '(a . c)) |
| 632 | '(cdr (different-atoms b c))))) | 655 | '(cdr (different-atoms b c))))) |