aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMattias EngdegÄrd2023-10-15 22:01:06 +0200
committerMattias EngdegÄrd2023-10-21 15:12:55 +0200
commita3db503351e9a8720cdea2f1ca42d55d2de684e2 (patch)
tree299791970977df508b580a64040e86f7e1f30782 /test
parent12c8cdb60cc41fb17a85c7e3f75f91cca2d60483 (diff)
downloademacs-a3db503351e9a8720cdea2f1ca42d55d2de684e2.tar.gz
emacs-a3db503351e9a8720cdea2f1ca42d55d2de684e2.zip
Move lexical-binding warning from checkdoc to byte-compiler
This warning is much more appropriate for the compiler, since lexical binding affects what it can reason and warn about, than for checkdoc as the warning has no bearing to documentation at all. The move also improves the reach of the warning. * etc/NEWS: Update. * lisp/emacs-lisp/checkdoc.el (checkdoc-lexical-binding-flag) (checkdoc-file-comments-engine): Move warning from here.... * lisp/emacs-lisp/bytecomp.el (byte-compile-file): ...to here. * test/lisp/emacs-lisp/bytecomp-resources/no-byte-compile.el: * test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-tests--unescaped-char-literals) (bytecomp-tests-function-put, bytecomp-tests--not-writable-directory) (bytecomp-tests--target-file-no-directory): Update tests. (bytecomp-tests--log-from-compilation) (bytecomp-tests--lexical-binding-cookie): New test.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/emacs-lisp/bytecomp-resources/no-byte-compile.el2
-rw-r--r--test/lisp/emacs-lisp/bytecomp-tests.el39
2 files changed, 36 insertions, 5 deletions
diff --git a/test/lisp/emacs-lisp/bytecomp-resources/no-byte-compile.el b/test/lisp/emacs-lisp/bytecomp-resources/no-byte-compile.el
index 00ad1947507..1de5cf66b66 100644
--- a/test/lisp/emacs-lisp/bytecomp-resources/no-byte-compile.el
+++ b/test/lisp/emacs-lisp/bytecomp-resources/no-byte-compile.el
@@ -1 +1 @@
;; -*- no-byte-compile: t; -*- ;; -*- no-byte-compile: t; lexical-binding: t; -*-
diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el
index e644417c3d4..4aa555f1e92 100644
--- a/test/lisp/emacs-lisp/bytecomp-tests.el
+++ b/test/lisp/emacs-lisp/bytecomp-tests.el
@@ -1302,6 +1302,30 @@ byte-compiled. Run with dynamic binding."
1302 (let ((elc (concat ,file-name-var ".elc"))) 1302 (let ((elc (concat ,file-name-var ".elc")))
1303 (if (file-exists-p elc) (delete-file elc)))))) 1303 (if (file-exists-p elc) (delete-file elc))))))
1304 1304
1305(defun bytecomp-tests--log-from-compilation (source)
1306 "Compile the string SOURCE and return the compilation log output."
1307 (let ((text-quoting-style 'grave)
1308 (byte-compile-log-buffer (generate-new-buffer " *Compile-Log*")))
1309 (with-current-buffer byte-compile-log-buffer
1310 (let ((inhibit-read-only t)) (erase-buffer)))
1311 (bytecomp-tests--with-temp-file el-file
1312 (write-region source nil el-file)
1313 (byte-compile-file el-file))
1314 (with-current-buffer byte-compile-log-buffer
1315 (buffer-string))))
1316
1317(ert-deftest bytecomp-tests--lexical-binding-cookie ()
1318 (cl-flet ((cookie-warning (source)
1319 (string-search
1320 "file has no `lexical-binding' directive on its first line"
1321 (bytecomp-tests--log-from-compilation source))))
1322 (let ((some-code "(defun my-fun () 12)\n"))
1323 (should-not (cookie-warning
1324 (concat ";;; -*-lexical-binding:t-*-\n" some-code)))
1325 (should-not (cookie-warning
1326 (concat ";;; -*-lexical-binding:nil-*-\n" some-code)))
1327 (should (cookie-warning some-code)))))
1328
1305(ert-deftest bytecomp-tests--unescaped-char-literals () 1329(ert-deftest bytecomp-tests--unescaped-char-literals ()
1306 "Check that byte compiling warns about unescaped character 1330 "Check that byte compiling warns about unescaped character
1307literals (Bug#20852)." 1331literals (Bug#20852)."
@@ -1310,7 +1334,9 @@ literals (Bug#20852)."
1310 (byte-compile-debug t) 1334 (byte-compile-debug t)
1311 (text-quoting-style 'grave)) 1335 (text-quoting-style 'grave))
1312 (bytecomp-tests--with-temp-file source 1336 (bytecomp-tests--with-temp-file source
1313 (write-region "(list ?) ?( ?; ?\" ?[ ?])" nil source) 1337 (write-region (concat ";;; -*-lexical-binding:t-*-\n"
1338 "(list ?) ?( ?; ?\" ?[ ?])")
1339 nil source)
1314 (bytecomp-tests--with-temp-file destination 1340 (bytecomp-tests--with-temp-file destination
1315 (let* ((byte-compile-dest-file-function (lambda (_) destination)) 1341 (let* ((byte-compile-dest-file-function (lambda (_) destination))
1316 (err (should-error (byte-compile-file source)))) 1342 (err (should-error (byte-compile-file source))))
@@ -1322,7 +1348,9 @@ literals (Bug#20852)."
1322 "`?\\]' expected!"))))))) 1348 "`?\\]' expected!")))))))
1323 ;; But don't warn in subsequent compilations (Bug#36068). 1349 ;; But don't warn in subsequent compilations (Bug#36068).
1324 (bytecomp-tests--with-temp-file source 1350 (bytecomp-tests--with-temp-file source
1325 (write-region "(list 1 2 3)" nil source) 1351 (write-region (concat ";;; -*-lexical-binding:t-*-\n"
1352 "(list 1 2 3)")
1353 nil source)
1326 (bytecomp-tests--with-temp-file destination 1354 (bytecomp-tests--with-temp-file destination
1327 (let ((byte-compile-dest-file-function (lambda (_) destination))) 1355 (let ((byte-compile-dest-file-function (lambda (_) destination)))
1328 (should (byte-compile-file source))))))) 1356 (should (byte-compile-file source)))))))
@@ -1330,6 +1358,7 @@ literals (Bug#20852)."
1330(ert-deftest bytecomp-tests-function-put () 1358(ert-deftest bytecomp-tests-function-put ()
1331 "Check `function-put' operates during compilation." 1359 "Check `function-put' operates during compilation."
1332 (bytecomp-tests--with-temp-file source 1360 (bytecomp-tests--with-temp-file source
1361 (insert ";;; -*-lexical-binding:t-*-\n")
1333 (dolist (form '((function-put 'bytecomp-tests--foo 'foo 1) 1362 (dolist (form '((function-put 'bytecomp-tests--foo 'foo 1)
1334 (function-put 'bytecomp-tests--foo 'bar 2) 1363 (function-put 'bytecomp-tests--foo 'bar 2)
1335 (defmacro bytecomp-tests--foobar () 1364 (defmacro bytecomp-tests--foobar ()
@@ -1636,7 +1665,8 @@ writable (Bug#44631)."
1636 (byte-compile-error-on-warn t)) 1665 (byte-compile-error-on-warn t))
1637 (unwind-protect 1666 (unwind-protect
1638 (progn 1667 (progn
1639 (write-region "" nil input-file nil nil nil 'excl) 1668 (write-region ";;; -*-lexical-binding:t-*-\n"
1669 nil input-file nil nil nil 'excl)
1640 (write-region "" nil output-file nil nil nil 'excl) 1670 (write-region "" nil output-file nil nil nil 'excl)
1641 (set-file-modes input-file #o400) 1671 (set-file-modes input-file #o400)
1642 (set-file-modes output-file #o200) 1672 (set-file-modes output-file #o200)
@@ -1700,7 +1730,8 @@ mountpoint (Bug#44631)."
1700 (let* ((default-directory directory) 1730 (let* ((default-directory directory)
1701 (byte-compile-dest-file-function (lambda (_) "test.elc")) 1731 (byte-compile-dest-file-function (lambda (_) "test.elc"))
1702 (byte-compile-error-on-warn t)) 1732 (byte-compile-error-on-warn t))
1703 (write-region "" nil "test.el" nil nil nil 'excl) 1733 (write-region ";;; -*-lexical-binding:t-*-\n"
1734 nil "test.el" nil nil nil 'excl)
1704 (should (byte-compile-file "test.el")) 1735 (should (byte-compile-file "test.el"))
1705 (should (file-regular-p "test.elc")) 1736 (should (file-regular-p "test.elc"))
1706 (should (cl-plusp (file-attribute-size 1737 (should (cl-plusp (file-attribute-size