summaryrefslogtreecommitdiff
path: root/test/src/lread-tests.el
diff options
context:
space:
mode:
authorPhilipp Stephani <phst@google.com>2015-06-30 22:38:35 +0200
committerPhilipp Stephani <phst@google.com>2017-05-01 20:39:10 +0200
commitc2bbdc3316487e34eba1470dd059c0c290431e00 (patch)
treebed5315e69d89c99c62be4a78e8f26d799643f70 /test/src/lread-tests.el
parentb72e36047c9a5d46b02e12252e0fc640b6839903 (diff)
downloademacs-c2bbdc3316487e34eba1470dd059c0c290431e00.tar.gz
emacs-c2bbdc3316487e34eba1470dd059c0c290431e00.tar.bz2
emacs-c2bbdc3316487e34eba1470dd059c0c290431e00.zip
Warn about missing backslashes during load
* src/lread.c (load_warn_unescaped_character_literals, Fload, read1) (syms_of_lread): Warn if unescaped character literals are found (Bug#20152). * lisp/emacs-lisp/bytecomp.el (byte-compile-from-buffer): Check for unescaped character literals during byte compilation. * test/src/lread-tests.el (lread-tests--unescaped-char-literals): New unit test. (lread-tests--with-temp-file, lread-tests--last-message): Helper functions for unit test. * test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-tests--unescaped-char-literals): New unit test. * test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-tests--with-temp-file): Helper macro for unit test.
Diffstat (limited to 'test/src/lread-tests.el')
-rw-r--r--test/src/lread-tests.el26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/src/lread-tests.el b/test/src/lread-tests.el
index 27f967f045b..84342348d45 100644
--- a/test/src/lread-tests.el
+++ b/test/src/lread-tests.el
@@ -116,4 +116,30 @@
(should (equal '(#s(foo) #s(foo))
(read "(#1=#s(foo) #1#)"))))
+(defmacro lread-tests--with-temp-file (file-name-var &rest body)
+ (declare (indent 1))
+ (cl-check-type file-name-var symbol)
+ `(let ((,file-name-var (make-temp-file "emacs")))
+ (unwind-protect
+ (progn ,@body)
+ (delete-file ,file-name-var))))
+
+(defun lread-tests--last-message ()
+ (with-current-buffer "*Messages*"
+ (save-excursion
+ (goto-char (point-max))
+ (skip-chars-backward "\n")
+ (buffer-substring (line-beginning-position) (point)))))
+
+(ert-deftest lread-tests--unescaped-char-literals ()
+ "Check that loading warns about unescaped character
+literals (Bug#20852)."
+ (lread-tests--with-temp-file file-name
+ (write-region "?) ?( ?; ?\" ?[ ?]" nil file-name)
+ (should (equal (load file-name nil :nomessage :nosuffix) t))
+ (should (equal (lread-tests--last-message)
+ (concat (format-message "Loading `%s': " file-name)
+ "unescaped character literals "
+ "\", (, ), ;, [, ] detected!")))))
+
;;; lread-tests.el ends here