diff options
| author | Stefan Monnier | 2021-11-27 10:10:26 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2021-11-27 10:10:43 -0500 |
| commit | 8d67a70e97a7002682f641c05b10e1a9d4586e8b (patch) | |
| tree | ea0343958a34b9f2585a9aff1c458bbe148f1c38 /test/src/comp-tests.el | |
| parent | a89731a78c8cb019a18d2e70fe43d21286d88ab1 (diff) | |
| download | emacs-8d67a70e97a7002682f641c05b10e1a9d4586e8b.tar.gz emacs-8d67a70e97a7002682f641c05b10e1a9d4586e8b.zip | |
* test/src/comp-tests.el: Rework last patch
Move `require`s out of `eval-when-compile` if the functions are called
at run-time.
Don't use #' to quote symbols (i.e. at those places where a lambda
expression couldn't be used).
Don't pre-load comp-test-45603.el and comp-test-pure.el any more.
(comp-deftest pure): Use `declare-function` after loading `comp-test-pure.el`
to silence the byte-compiler.
Diffstat (limited to 'test/src/comp-tests.el')
| -rw-r--r-- | test/src/comp-tests.el | 57 |
1 files changed, 28 insertions, 29 deletions
diff --git a/test/src/comp-tests.el b/test/src/comp-tests.el index f66a1932058..5b20cf38ec6 100644 --- a/test/src/comp-tests.el +++ b/test/src/comp-tests.el | |||
| @@ -27,27 +27,24 @@ | |||
| 27 | 27 | ||
| 28 | (require 'ert) | 28 | (require 'ert) |
| 29 | (require 'ert-x) | 29 | (require 'ert-x) |
| 30 | (eval-when-compile | 30 | (require 'cl-lib) |
| 31 | (require 'cl-lib) | 31 | (require 'comp) |
| 32 | (require 'comp)) | 32 | (require 'comp-cstr) |
| 33 | |||
| 33 | (eval-and-compile | 34 | (eval-and-compile |
| 34 | (require 'comp-cstr) ;in eval-and-compile for its defstruct | ||
| 35 | (defconst comp-test-src (ert-resource-file "comp-test-funcs.el")) | 35 | (defconst comp-test-src (ert-resource-file "comp-test-funcs.el")) |
| 36 | (defconst comp-test-dyn-src (ert-resource-file "comp-test-funcs-dyn.el")) | 36 | (defconst comp-test-dyn-src (ert-resource-file "comp-test-funcs-dyn.el"))) |
| 37 | (defconst comp-test-pure-src (ert-resource-file "comp-test-pure.el")) | ||
| 38 | (defconst comp-test-45603-src (ert-resource-file "comp-test-45603.el")) | ||
| 39 | ;; Load the test code here so the compiler can check the function | ||
| 40 | ;; names used in this file. | ||
| 41 | (load comp-test-src nil t) | ||
| 42 | (load comp-test-dyn-src nil t) | ||
| 43 | (load comp-test-pure-src nil t) | ||
| 44 | (load comp-test-45603-src nil t)) | ||
| 45 | 37 | ||
| 46 | (when (native-comp-available-p) | 38 | (when (native-comp-available-p) |
| 47 | (message "Compiling tests...") | 39 | (message "Compiling tests...") |
| 48 | (load (native-compile comp-test-src)) | 40 | (load (native-compile comp-test-src)) |
| 49 | (load (native-compile comp-test-dyn-src))) | 41 | (load (native-compile comp-test-dyn-src))) |
| 50 | 42 | ||
| 43 | ;; Load the test code here so the compiler can check the function | ||
| 44 | ;; names used in this file. | ||
| 45 | (require 'comp-test-funcs comp-test-src) | ||
| 46 | (require 'comp-test-dyn-funcs comp-test-dyn-src) ;Non-standard feature name! | ||
| 47 | |||
| 51 | (defmacro comp-deftest (name args &rest docstring-and-body) | 48 | (defmacro comp-deftest (name args &rest docstring-and-body) |
| 52 | "Define a test for the native compiler tagging it as :nativecomp." | 49 | "Define a test for the native compiler tagging it as :nativecomp." |
| 53 | (declare (indent defun) | 50 | (declare (indent defun) |
| @@ -75,7 +72,7 @@ Check that the resulting binaries do not differ." | |||
| 75 | (copy-file comp-src comp2-src t) | 72 | (copy-file comp-src comp2-src t) |
| 76 | (let ((load-no-native t)) | 73 | (let ((load-no-native t)) |
| 77 | (load (concat comp-src "c") nil nil t t)) | 74 | (load (concat comp-src "c") nil nil t t)) |
| 78 | (should-not (subr-native-elisp-p (symbol-function #'native-compile))) | 75 | (should-not (subr-native-elisp-p (symbol-function 'native-compile))) |
| 79 | (message "Compiling stage1...") | 76 | (message "Compiling stage1...") |
| 80 | (let* ((t0 (current-time)) | 77 | (let* ((t0 (current-time)) |
| 81 | (comp1-eln (native-compile comp1-src))) | 78 | (comp1-eln (native-compile comp1-src))) |
| @@ -372,7 +369,7 @@ Check that the resulting binaries do not differ." | |||
| 372 | t) | 369 | t) |
| 373 | (native-compile #'comp-tests-free-fun-f) | 370 | (native-compile #'comp-tests-free-fun-f) |
| 374 | 371 | ||
| 375 | (should (subr-native-elisp-p (symbol-function #'comp-tests-free-fun-f))) | 372 | (should (subr-native-elisp-p (symbol-function 'comp-tests-free-fun-f))) |
| 376 | (should (= (comp-tests-free-fun-f) 3)) | 373 | (should (= (comp-tests-free-fun-f) 3)) |
| 377 | (should (string= (documentation #'comp-tests-free-fun-f) | 374 | (should (string= (documentation #'comp-tests-free-fun-f) |
| 378 | "Some doc.")) | 375 | "Some doc.")) |
| @@ -386,7 +383,7 @@ Check that the resulting binaries do not differ." | |||
| 386 | "Check we are able to compile a single function." | 383 | "Check we are able to compile a single function." |
| 387 | (eval '(defun comp-tests/free\fun-f ()) t) | 384 | (eval '(defun comp-tests/free\fun-f ()) t) |
| 388 | (native-compile #'comp-tests/free\fun-f) | 385 | (native-compile #'comp-tests/free\fun-f) |
| 389 | (should (subr-native-elisp-p (symbol-function #'comp-tests/free\fun-f)))) | 386 | (should (subr-native-elisp-p (symbol-function 'comp-tests/free\fun-f)))) |
| 390 | 387 | ||
| 391 | (comp-deftest bug-40187 () | 388 | (comp-deftest bug-40187 () |
| 392 | "Check function name shadowing. | 389 | "Check function name shadowing. |
| @@ -397,7 +394,7 @@ https://lists.gnu.org/archive/html/bug-gnu-emacs/2020-03/msg00914.html." | |||
| 397 | (comp-deftest speed--1 () | 394 | (comp-deftest speed--1 () |
| 398 | "Check that at speed -1 we do not native compile." | 395 | "Check that at speed -1 we do not native compile." |
| 399 | (should (= (comp-test-speed--1-f) 3)) | 396 | (should (= (comp-test-speed--1-f) 3)) |
| 400 | (should-not (subr-native-elisp-p (symbol-function #'comp-test-speed--1-f)))) | 397 | (should-not (subr-native-elisp-p (symbol-function 'comp-test-speed--1-f)))) |
| 401 | 398 | ||
| 402 | (comp-deftest bug-42360 () | 399 | (comp-deftest bug-42360 () |
| 403 | "<https://lists.gnu.org/archive/html/bug-gnu-emacs/2020-07/msg00418.html>." | 400 | "<https://lists.gnu.org/archive/html/bug-gnu-emacs/2020-07/msg00418.html>." |
| @@ -446,7 +443,7 @@ https://lists.gnu.org/archive/html/bug-gnu-emacs/2020-03/msg00914.html." | |||
| 446 | (comp-deftest primitive-redefine () | 443 | (comp-deftest primitive-redefine () |
| 447 | "Test effectiveness of primitive redefinition." | 444 | "Test effectiveness of primitive redefinition." |
| 448 | (cl-letf ((comp-test-primitive-redefine-args nil) | 445 | (cl-letf ((comp-test-primitive-redefine-args nil) |
| 449 | ((symbol-function #'-) | 446 | ((symbol-function '-) |
| 450 | (lambda (&rest args) | 447 | (lambda (&rest args) |
| 451 | (setq comp-test-primitive-redefine-args args) | 448 | (setq comp-test-primitive-redefine-args args) |
| 452 | 'xxx))) | 449 | 'xxx))) |
| @@ -467,11 +464,11 @@ https://lists.gnu.org/archive/html/bug-gnu-emacs/2020-03/msg00914.html." | |||
| 467 | 464 | ||
| 468 | (comp-deftest comp-test-defsubst () | 465 | (comp-deftest comp-test-defsubst () |
| 469 | ;; Bug#42664, Bug#43280, Bug#44209. | 466 | ;; Bug#42664, Bug#43280, Bug#44209. |
| 470 | (should-not (subr-native-elisp-p (symbol-function #'comp-test-defsubst-f)))) | 467 | (should-not (subr-native-elisp-p (symbol-function 'comp-test-defsubst-f)))) |
| 471 | 468 | ||
| 472 | (comp-deftest primitive-redefine-compile-44221 () | 469 | (comp-deftest primitive-redefine-compile-44221 () |
| 473 | "Test the compiler still works while primitives are redefined (bug#44221)." | 470 | "Test the compiler still works while primitives are redefined (bug#44221)." |
| 474 | (cl-letf (((symbol-function #'delete-region) | 471 | (cl-letf (((symbol-function 'delete-region) |
| 475 | (lambda (_ _)))) | 472 | (lambda (_ _)))) |
| 476 | (should (subr-native-elisp-p | 473 | (should (subr-native-elisp-p |
| 477 | (native-compile | 474 | (native-compile |
| @@ -506,13 +503,13 @@ https://lists.gnu.org/archive/html/bug-gnu-emacs/2020-03/msg00914.html." | |||
| 506 | 503 | ||
| 507 | (comp-deftest 45603-1 () | 504 | (comp-deftest 45603-1 () |
| 508 | "<https://lists.gnu.org/archive/html/bug-gnu-emacs/2020-12/msg01994.html>" | 505 | "<https://lists.gnu.org/archive/html/bug-gnu-emacs/2020-12/msg01994.html>" |
| 509 | (load (native-compile comp-test-45603-src)) | 506 | (load (native-compile (ert-resource-file "comp-test-45603.el"))) |
| 510 | (should (fboundp #'comp-test-45603--file-local-name))) | 507 | (should (fboundp 'comp-test-45603--file-local-name))) |
| 511 | 508 | ||
| 512 | (comp-deftest 46670-1 () | 509 | (comp-deftest 46670-1 () |
| 513 | "<https://lists.gnu.org/archive/html/bug-gnu-emacs/2021-02/msg01413.html>" | 510 | "<https://lists.gnu.org/archive/html/bug-gnu-emacs/2021-02/msg01413.html>" |
| 514 | (should (string= (comp-test-46670-2-f "foo") "foo")) | 511 | (should (string= (comp-test-46670-2-f "foo") "foo")) |
| 515 | (should (equal (subr-type (symbol-function #'comp-test-46670-2-f)) | 512 | (should (equal (subr-type (symbol-function 'comp-test-46670-2-f)) |
| 516 | '(function (t) t)))) | 513 | '(function (t) t)))) |
| 517 | 514 | ||
| 518 | (comp-deftest 46824-1 () | 515 | (comp-deftest 46824-1 () |
| @@ -742,7 +739,7 @@ https://lists.gnu.org/archive/html/bug-gnu-emacs/2020-03/msg00914.html." | |||
| 742 | (comp-deftest dynamic-help-arglist () | 739 | (comp-deftest dynamic-help-arglist () |
| 743 | "Test `help-function-arglist' works on lisp/d (bug#42572)." | 740 | "Test `help-function-arglist' works on lisp/d (bug#42572)." |
| 744 | (should (equal (help-function-arglist | 741 | (should (equal (help-function-arglist |
| 745 | (symbol-function #'comp-tests-ffuncall-callee-opt-rest-dyn-f) | 742 | (symbol-function 'comp-tests-ffuncall-callee-opt-rest-dyn-f) |
| 746 | t) | 743 | t) |
| 747 | '(a b &optional c &rest d)))) | 744 | '(a b &optional c &rest d)))) |
| 748 | 745 | ||
| @@ -815,7 +812,7 @@ Return a list of results." | |||
| 815 | (comp-tests-tco-f (+ a b) a (- count 1)))) | 812 | (comp-tests-tco-f (+ a b) a (- count 1)))) |
| 816 | t) | 813 | t) |
| 817 | (native-compile #'comp-tests-tco-f) | 814 | (native-compile #'comp-tests-tco-f) |
| 818 | (should (subr-native-elisp-p (symbol-function #'comp-tests-tco-f))) | 815 | (should (subr-native-elisp-p (symbol-function 'comp-tests-tco-f))) |
| 819 | (should (= (comp-tests-tco-f 1 0 10) 55)))) | 816 | (should (= (comp-tests-tco-f 1 0 10) 55)))) |
| 820 | 817 | ||
| 821 | (defun comp-tests-fw-prop-checker-1 (_) | 818 | (defun comp-tests-fw-prop-checker-1 (_) |
| @@ -842,7 +839,7 @@ Return a list of results." | |||
| 842 | (length c))) ; <= has to optimize | 839 | (length c))) ; <= has to optimize |
| 843 | t) | 840 | t) |
| 844 | (native-compile #'comp-tests-fw-prop-1-f) | 841 | (native-compile #'comp-tests-fw-prop-1-f) |
| 845 | (should (subr-native-elisp-p (symbol-function #'comp-tests-fw-prop-1-f))) | 842 | (should (subr-native-elisp-p (symbol-function 'comp-tests-fw-prop-1-f))) |
| 846 | (should (= (comp-tests-fw-prop-1-f) 6)))) | 843 | (should (= (comp-tests-fw-prop-1-f) 6)))) |
| 847 | 844 | ||
| 848 | (defun comp-tests-check-ret-type-spec (func-form ret-type) | 845 | (defun comp-tests-check-ret-type-spec (func-form ret-type) |
| @@ -1421,12 +1418,14 @@ folded." | |||
| 1421 | (let ((native-comp-speed 3) | 1418 | (let ((native-comp-speed 3) |
| 1422 | (comp-post-pass-hooks '((comp-final comp-tests-pure-checker-1 | 1419 | (comp-post-pass-hooks '((comp-final comp-tests-pure-checker-1 |
| 1423 | comp-tests-pure-checker-2)))) | 1420 | comp-tests-pure-checker-2)))) |
| 1424 | (load (native-compile comp-test-pure-src)) | 1421 | (load (native-compile (ert-resource-file "comp-test-pure.el"))) |
| 1422 | (declare-function comp-tests-pure-caller-f nil) | ||
| 1423 | (declare-function comp-tests-pure-fibn-entry-f nil) | ||
| 1425 | 1424 | ||
| 1426 | (should (subr-native-elisp-p (symbol-function #'comp-tests-pure-caller-f))) | 1425 | (should (subr-native-elisp-p (symbol-function 'comp-tests-pure-caller-f))) |
| 1427 | (should (= (comp-tests-pure-caller-f) 4)) | 1426 | (should (= (comp-tests-pure-caller-f) 4)) |
| 1428 | 1427 | ||
| 1429 | (should (subr-native-elisp-p (symbol-function #'comp-tests-pure-fibn-entry-f))) | 1428 | (should (subr-native-elisp-p (symbol-function 'comp-tests-pure-fibn-entry-f))) |
| 1430 | (should (= (comp-tests-pure-fibn-entry-f) 6765)))) | 1429 | (should (= (comp-tests-pure-fibn-entry-f) 6765)))) |
| 1431 | 1430 | ||
| 1432 | (defvar comp-tests-cond-rw-checked-function nil | 1431 | (defvar comp-tests-cond-rw-checked-function nil |