diff options
| author | Mattias EngdegÄrd | 2025-09-10 14:35:48 +0200 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2025-09-10 14:35:48 +0200 |
| commit | d859ac4183cb511e4d781e963cc47bf3636cc763 (patch) | |
| tree | 0780705fdeb3eb75bdfe7ac090696959ff457535 | |
| parent | f4d0a2560af6bff9793f53c2e06d4fcd3480be9a (diff) | |
| download | emacs-d859ac4183cb511e4d781e963cc47bf3636cc763.tar.gz emacs-d859ac4183cb511e4d781e963cc47bf3636cc763.zip | |
Make bytecomp-tests cease warn and error to stdout
They were caused by compilation errors going to 'display-warning'
which prints a duplicate of the message to stdout when running
noninteractively.
* test/lisp/emacs-lisp/bytecomp-tests.el
(bytecomp-tests--log-warning-for-byte-compile)
(bytecomp-tests--with-warnings): New. Wrap around compilation calls in
this file.
| -rw-r--r-- | test/lisp/emacs-lisp/bytecomp-tests.el | 65 |
1 files changed, 50 insertions, 15 deletions
diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el index 5d95e9b0ee7..7cbfd97d653 100644 --- a/test/lisp/emacs-lisp/bytecomp-tests.el +++ b/test/lisp/emacs-lisp/bytecomp-tests.el | |||
| @@ -32,6 +32,28 @@ | |||
| 32 | (require 'bytecomp) | 32 | (require 'bytecomp) |
| 33 | 33 | ||
| 34 | ;;; Code: | 34 | ;;; Code: |
| 35 | |||
| 36 | ;; Replacement for `byte-compile--log-warning-for-byte-compile' | ||
| 37 | ;; that doesn't call `display-warning' to avoid warnings being printed | ||
| 38 | ;; to the test log when running noninteractively. | ||
| 39 | (defun bytecomp-tests--log-warning-for-byte-compile (string _pos _fill level) | ||
| 40 | (with-current-buffer (get-buffer-create byte-compile-log-buffer) | ||
| 41 | (save-excursion | ||
| 42 | (goto-char (point-max)) | ||
| 43 | (let ((inhibit-read-only t)) | ||
| 44 | (byte-compile-warning-prefix level nil) | ||
| 45 | (insert | ||
| 46 | (format "%s%s\n" | ||
| 47 | (cond ((eq level :warning) "Warning: ") | ||
| 48 | ((eq level :error) "Error: ")) | ||
| 49 | string)))))) | ||
| 50 | |||
| 51 | (defmacro bytecomp-tests--with-warnings (&rest body) | ||
| 52 | "Run BODY, compiler warnings going to `byte-compile-log-buffer' only." | ||
| 53 | `(cl-letf (((symbol-function 'byte-compile--log-warning-for-byte-compile) | ||
| 54 | #'bytecomp-tests--log-warning-for-byte-compile)) | ||
| 55 | ,@body)) | ||
| 56 | |||
| 35 | (defvar bytecomp-test-var nil) | 57 | (defvar bytecomp-test-var nil) |
| 36 | 58 | ||
| 37 | (defun bytecomp-test-get-var () | 59 | (defun bytecomp-test-get-var () |
| @@ -820,7 +842,8 @@ These are only tested with lexical binding.") | |||
| 820 | "Evaluate FORM using the Lisp interpreter, returning errors as a | 842 | "Evaluate FORM using the Lisp interpreter, returning errors as a |
| 821 | special value." | 843 | special value." |
| 822 | (condition-case err | 844 | (condition-case err |
| 823 | (eval form lexical-binding) | 845 | (let ((inhibit-message t)) |
| 846 | (eval form lexical-binding)) | ||
| 824 | (error (list 'bytecomp-check-error (car err))))) | 847 | (error (list 'bytecomp-check-error (car err))))) |
| 825 | 848 | ||
| 826 | (defun bytecomp-tests--eval-compiled (form) | 849 | (defun bytecomp-tests--eval-compiled (form) |
| @@ -828,9 +851,10 @@ special value." | |||
| 828 | special value." | 851 | special value." |
| 829 | (let ((warning-minimum-log-level :emergency) | 852 | (let ((warning-minimum-log-level :emergency) |
| 830 | (byte-compile-warnings nil)) | 853 | (byte-compile-warnings nil)) |
| 831 | (condition-case err | 854 | (condition-case err |
| 832 | (funcall (byte-compile (list 'lambda nil form))) | 855 | (funcall (bytecomp-tests--with-warnings |
| 833 | (error (list 'bytecomp-check-error (car err)))))) | 856 | (byte-compile (list 'lambda nil form)))) |
| 857 | (error (list 'bytecomp-check-error (car err)))))) | ||
| 834 | 858 | ||
| 835 | (ert-deftest bytecomp-tests-lexbind () | 859 | (ert-deftest bytecomp-tests-lexbind () |
| 836 | "Check that various expressions behave the same when interpreted and | 860 | "Check that various expressions behave the same when interpreted and |
| @@ -861,7 +885,8 @@ byte-compiled. Run with dynamic binding." | |||
| 861 | (s-comp (byte-compile s-int)) | 885 | (s-comp (byte-compile s-int)) |
| 862 | (v-int (lambda (x) (1+ x))) | 886 | (v-int (lambda (x) (1+ x))) |
| 863 | (v-comp (byte-compile v-int)) | 887 | (v-comp (byte-compile v-int)) |
| 864 | (comp (lambda (f) (funcall (byte-compile `(lambda () (,f 3))))))) | 888 | (bc (lambda (f) (bytecomp-tests--with-warnings (byte-compile f)))) |
| 889 | (comp (lambda (f) (funcall (funcall bc `(lambda () (,f 3))))))) | ||
| 865 | (should (equal (funcall comp s-int) 4)) | 890 | (should (equal (funcall comp s-int) 4)) |
| 866 | (should (equal (funcall comp s-comp) 4)) | 891 | (should (equal (funcall comp s-comp) 4)) |
| 867 | (should (equal (funcall comp v-int) 4)) | 892 | (should (equal (funcall comp v-int) 4)) |
| @@ -870,7 +895,8 @@ byte-compiled. Run with dynamic binding." | |||
| 870 | (defmacro bytecomp-tests--with-fresh-warnings (&rest body) | 895 | (defmacro bytecomp-tests--with-fresh-warnings (&rest body) |
| 871 | `(let ((macroexp--warned ; oh dear | 896 | `(let ((macroexp--warned ; oh dear |
| 872 | (make-hash-table :test #'equal :weakness 'key))) | 897 | (make-hash-table :test #'equal :weakness 'key))) |
| 873 | ,@body)) | 898 | (bytecomp-tests--with-warnings |
| 899 | ,@body))) | ||
| 874 | 900 | ||
| 875 | (defun test-byte-comp-compile-and-load (compile &rest forms) | 901 | (defun test-byte-comp-compile-and-load (compile &rest forms) |
| 876 | (declare (indent 1)) | 902 | (declare (indent 1)) |
| @@ -1093,7 +1119,8 @@ byte-compiled. Run with dynamic binding." | |||
| 1093 | `(ert-deftest ,(intern (format "bytecomp/%s" file)) () | 1119 | `(ert-deftest ,(intern (format "bytecomp/%s" file)) () |
| 1094 | (with-current-buffer (get-buffer-create "*Compile-Log*") | 1120 | (with-current-buffer (get-buffer-create "*Compile-Log*") |
| 1095 | (let ((inhibit-read-only t)) (erase-buffer)) | 1121 | (let ((inhibit-read-only t)) (erase-buffer)) |
| 1096 | (byte-compile-file ,(ert-resource-file file)) | 1122 | (bytecomp-tests--with-warnings |
| 1123 | (byte-compile-file ,(ert-resource-file file))) | ||
| 1097 | (ert-info ((buffer-string) :prefix "buffer: ") | 1124 | (ert-info ((buffer-string) :prefix "buffer: ") |
| 1098 | (,(if reverse 'should-not 'should) | 1125 | (,(if reverse 'should-not 'should) |
| 1099 | (re-search-forward ,re-warning nil t)))))) | 1126 | (re-search-forward ,re-warning nil t)))))) |
| @@ -1342,7 +1369,8 @@ byte-compiled. Run with dynamic binding." | |||
| 1342 | nil elfile) | 1369 | nil elfile) |
| 1343 | (let* ((byte-compile-debug t) | 1370 | (let* ((byte-compile-debug t) |
| 1344 | (byte-compile-dest-file-function #'ignore)) | 1371 | (byte-compile-dest-file-function #'ignore)) |
| 1345 | (byte-compile-file elfile) | 1372 | (bytecomp-tests--with-warnings |
| 1373 | (byte-compile-file elfile)) | ||
| 1346 | (should (equal (funcall 'def) 5))))) | 1374 | (should (equal (funcall 'def) 5))))) |
| 1347 | 1375 | ||
| 1348 | (defmacro bytecomp-tests--with-temp-file (file-name-var &rest body) | 1376 | (defmacro bytecomp-tests--with-temp-file (file-name-var &rest body) |
| @@ -1362,7 +1390,8 @@ byte-compiled. Run with dynamic binding." | |||
| 1362 | (let ((inhibit-read-only t)) (erase-buffer))) | 1390 | (let ((inhibit-read-only t)) (erase-buffer))) |
| 1363 | (bytecomp-tests--with-temp-file el-file | 1391 | (bytecomp-tests--with-temp-file el-file |
| 1364 | (write-region source nil el-file) | 1392 | (write-region source nil el-file) |
| 1365 | (byte-compile-file el-file)) | 1393 | (bytecomp-tests--with-warnings |
| 1394 | (byte-compile-file el-file))) | ||
| 1366 | (with-current-buffer byte-compile-log-buffer | 1395 | (with-current-buffer byte-compile-log-buffer |
| 1367 | (buffer-string)))) | 1396 | (buffer-string)))) |
| 1368 | 1397 | ||
| @@ -1476,7 +1505,8 @@ literals (Bug#20852)." | |||
| 1476 | (or (featurep 'emacs) | 1505 | (or (featurep 'emacs) |
| 1477 | (some-undefined-function-or))) | 1506 | (some-undefined-function-or))) |
| 1478 | ") | 1507 | ") |
| 1479 | (byte-compile-from-buffer (current-buffer))) | 1508 | (bytecomp-tests--with-warnings |
| 1509 | (byte-compile-from-buffer (current-buffer)))) | ||
| 1480 | (with-current-buffer byte-compile-log-buffer | 1510 | (with-current-buffer byte-compile-log-buffer |
| 1481 | (should (search-forward "an-undefined-function" nil t)) | 1511 | (should (search-forward "an-undefined-function" nil t)) |
| 1482 | (should-not (search-forward "some-undefined-function" nil t)))) | 1512 | (should-not (search-forward "some-undefined-function" nil t)))) |
| @@ -1549,9 +1579,10 @@ literals (Bug#20852)." | |||
| 1549 | (goto-char (point-min)) | 1579 | (goto-char (point-min)) |
| 1550 | (should-not (string-match match (buffer-string)))) | 1580 | (should-not (string-match match (buffer-string)))) |
| 1551 | ;; Also check that byte compiled forms are identical. | 1581 | ;; Also check that byte compiled forms are identical. |
| 1552 | (should (equal (byte-compile form) | 1582 | (let ((normal (bytecomp-tests--with-warnings (byte-compile form))) |
| 1553 | (byte-compile | 1583 | (nowarn (bytecomp-tests--with-warnings |
| 1554 | `(with-suppressed-warnings ,suppress ,form)))))) | 1584 | (byte-compile `(with-suppressed-warnings ,suppress ,form))))) |
| 1585 | (should (equal normal nowarn))))) | ||
| 1555 | 1586 | ||
| 1556 | (ert-deftest bytecomp-test--with-suppressed-warnings () | 1587 | (ert-deftest bytecomp-test--with-suppressed-warnings () |
| 1557 | (test-suppression | 1588 | (test-suppression |
| @@ -1869,7 +1900,10 @@ compiled correctly." | |||
| 1869 | (ert-deftest bytecomp-string-vs-docstring () | 1900 | (ert-deftest bytecomp-string-vs-docstring () |
| 1870 | ;; Don't confuse a string return value for a docstring. | 1901 | ;; Don't confuse a string return value for a docstring. |
| 1871 | (let ((lexical-binding t)) | 1902 | (let ((lexical-binding t)) |
| 1872 | (should (equal (funcall (byte-compile '(lambda (x) "foo")) 'dummy) "foo")))) | 1903 | (should (equal (funcall (bytecomp-tests--with-warnings |
| 1904 | (byte-compile '(lambda (x) "foo"))) | ||
| 1905 | 'dummy) | ||
| 1906 | "foo")))) | ||
| 1873 | 1907 | ||
| 1874 | (ert-deftest bytecomp-condition-case-success () | 1908 | (ert-deftest bytecomp-condition-case-success () |
| 1875 | ;; No error, no success handler. | 1909 | ;; No error, no success handler. |
| @@ -2100,7 +2134,8 @@ EXPECTED-POINT BINDINGS (MODES \\='\\='(ruby-mode js-mode python-mode)) \ | |||
| 2100 | (with-current-buffer (get-buffer-create "*Compile-Log*") | 2134 | (with-current-buffer (get-buffer-create "*Compile-Log*") |
| 2101 | (let ((inhibit-read-only t)) | 2135 | (let ((inhibit-read-only t)) |
| 2102 | (erase-buffer)) | 2136 | (erase-buffer)) |
| 2103 | (byte-compile-file el) | 2137 | (bytecomp-tests--with-warnings |
| 2138 | (byte-compile-file el)) | ||
| 2104 | (let ((expected | 2139 | (let ((expected |
| 2105 | '("70:4: Warning: `declare' after `interactive'" | 2140 | '("70:4: Warning: `declare' after `interactive'" |
| 2106 | "74:4: Warning: Doc string after `interactive'" | 2141 | "74:4: Warning: Doc string after `interactive'" |