aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorPhilipp Stephani2015-06-30 22:38:35 +0200
committerPhilipp Stephani2017-05-01 20:39:10 +0200
commitc2bbdc3316487e34eba1470dd059c0c290431e00 (patch)
treebed5315e69d89c99c62be4a78e8f26d799643f70 /test
parentb72e36047c9a5d46b02e12252e0fc640b6839903 (diff)
downloademacs-c2bbdc3316487e34eba1470dd059c0c290431e00.tar.gz
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')
-rw-r--r--test/lisp/emacs-lisp/bytecomp-tests.el23
-rw-r--r--test/src/lread-tests.el26
2 files changed, 49 insertions, 0 deletions
diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el
index e8feec31d26..3624904753c 100644
--- a/test/lisp/emacs-lisp/bytecomp-tests.el
+++ b/test/lisp/emacs-lisp/bytecomp-tests.el
@@ -506,6 +506,29 @@ bytecompiled code, and their results compared.")
506 (dolist (pat bytecomp-lexbind-tests) 506 (dolist (pat bytecomp-lexbind-tests)
507 (should (bytecomp-lexbind-check-1 pat)))) 507 (should (bytecomp-lexbind-check-1 pat))))
508 508
509(defmacro bytecomp-tests--with-temp-file (file-name-var &rest body)
510 (declare (indent 1))
511 (cl-check-type file-name-var symbol)
512 `(let ((,file-name-var (make-temp-file "emacs")))
513 (unwind-protect
514 (progn ,@body)
515 (delete-file ,file-name-var))))
516
517(ert-deftest bytecomp-tests--unescaped-char-literals ()
518 "Check that byte compiling warns about unescaped character
519literals (Bug#20852)."
520 (should (boundp 'lread--unescaped-character-literals))
521 (bytecomp-tests--with-temp-file source
522 (write-region "(list ?) ?( ?; ?\" ?[ ?])" nil source)
523 (bytecomp-tests--with-temp-file destination
524 (let* ((byte-compile-dest-file-function (lambda (_) destination))
525 (byte-compile-error-on-warn t)
526 (byte-compile-debug t)
527 (err (should-error (byte-compile-file source))))
528 (should (equal (cdr err)
529 (list (concat "unescaped character literals "
530 "\", (, ), ;, [, ] detected!"))))))))
531
509;; Local Variables: 532;; Local Variables:
510;; no-byte-compile: t 533;; no-byte-compile: t
511;; End: 534;; End:
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 @@
116 (should (equal '(#s(foo) #s(foo)) 116 (should (equal '(#s(foo) #s(foo))
117 (read "(#1=#s(foo) #1#)")))) 117 (read "(#1=#s(foo) #1#)"))))
118 118
119(defmacro lread-tests--with-temp-file (file-name-var &rest body)
120 (declare (indent 1))
121 (cl-check-type file-name-var symbol)
122 `(let ((,file-name-var (make-temp-file "emacs")))
123 (unwind-protect
124 (progn ,@body)
125 (delete-file ,file-name-var))))
126
127(defun lread-tests--last-message ()
128 (with-current-buffer "*Messages*"
129 (save-excursion
130 (goto-char (point-max))
131 (skip-chars-backward "\n")
132 (buffer-substring (line-beginning-position) (point)))))
133
134(ert-deftest lread-tests--unescaped-char-literals ()
135 "Check that loading warns about unescaped character
136literals (Bug#20852)."
137 (lread-tests--with-temp-file file-name
138 (write-region "?) ?( ?; ?\" ?[ ?]" nil file-name)
139 (should (equal (load file-name nil :nomessage :nosuffix) t))
140 (should (equal (lread-tests--last-message)
141 (concat (format-message "Loading `%s': " file-name)
142 "unescaped character literals "
143 "\", (, ), ;, [, ] detected!")))))
144
119;;; lread-tests.el ends here 145;;; lread-tests.el ends here