aboutsummaryrefslogtreecommitdiffstats
path: root/test/lisp
diff options
context:
space:
mode:
authorAndrea Corallo2021-04-13 12:06:23 +0200
committerAndrea Corallo2021-04-13 12:06:23 +0200
commitb064ddd3f600ed28e62b09d556ecced5f80d9883 (patch)
tree2ddf4889f385beb34cd064f245a7e59265377c37 /test/lisp
parent2d23f19e7d5ff8a1ec1a188dcd530c185029d1f8 (diff)
parent6de79542e43ece9a12ebc032c275a6c3fee0b73b (diff)
downloademacs-b064ddd3f600ed28e62b09d556ecced5f80d9883.tar.gz
emacs-b064ddd3f600ed28e62b09d556ecced5f80d9883.zip
Merge remote-tracking branch 'savannah/master' into native-comp
Diffstat (limited to 'test/lisp')
-rw-r--r--test/lisp/calculator-tests.el51
-rw-r--r--test/lisp/emacs-lisp/bytecomp-tests.el230
-rw-r--r--test/lisp/emacs-lisp/cl-macs-tests.el14
-rw-r--r--test/lisp/emacs-lisp/edebug-tests.el25
-rw-r--r--test/lisp/loadhist-tests.el57
-rw-r--r--test/lisp/shadowfile-tests.el2
6 files changed, 240 insertions, 139 deletions
diff --git a/test/lisp/calculator-tests.el b/test/lisp/calculator-tests.el
new file mode 100644
index 00000000000..9551b1a4c61
--- /dev/null
+++ b/test/lisp/calculator-tests.el
@@ -0,0 +1,51 @@
1;;; calculator-tests.el --- Test suite for calculator. -*- lexical-binding: t -*-
2
3;; Copyright (C) 2021 Free Software Foundation, Inc.
4
5;; This file is part of GNU Emacs.
6
7;; GNU Emacs is free software: you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
11
12;; GNU Emacs is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
19
20;;; Code:
21(require 'ert)
22(require 'calculator)
23
24(ert-deftest calculator-test-calculator-string-to-number ()
25 (dolist (x '(("" 0.0)
26 ("+" 0.0)
27 ("-" 0.0)
28 ("." 0.0)
29 ("+." 0.0)
30 ("-." -0.0)
31 (".-" 0.0)
32 ("--." 0.0)
33 ("-0.0e" -0.0)
34 ("1e1" 10.0)
35 ("1e+1" 10.0)
36 ("1e-1" 0.1)
37 ("+1e1" 10.0)
38 ("-1e1" -10.0)
39 ("+1e-1" 0.1)
40 ("-1e-1" -0.1)
41 (".1.e1" 0.1)
42 (".1..e1" 0.1)
43 ("1e+1.1" 10.0)
44 ("-2e-1.1" -0.2)))
45 (pcase x
46 (`(,str ,expected)
47 (let ((calculator-input-radix nil))
48 (should (equal (calculator-string-to-number str) expected)))))))
49
50(provide 'calculator-tests)
51;; calculator-tests.el ends here
diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el
index 5147cd26883..a11832d805e 100644
--- a/test/lisp/emacs-lisp/bytecomp-tests.el
+++ b/test/lisp/emacs-lisp/bytecomp-tests.el
@@ -41,7 +41,7 @@
41 "Identity, but hidden from some optimisations." 41 "Identity, but hidden from some optimisations."
42 x) 42 x)
43 43
44(defconst byte-opt-testsuite-arith-data 44(defconst bytecomp-tests--test-cases
45 '( 45 '(
46 ;; some functional tests 46 ;; some functional tests
47 (let ((a most-positive-fixnum) (b 1) (c 1.0)) (+ a b c)) 47 (let ((a most-positive-fixnum) (b 1) (c 1.0)) (+ a b c))
@@ -364,17 +364,17 @@
364 '((a c) (b c) (7 c) (-3 c) (nil nil) (t c) (q c) (r c) (s c) 364 '((a c) (b c) (7 c) (-3 c) (nil nil) (t c) (q c) (r c) (s c)
365 (t c) (x "a") (x "c") (x c) (x d) (x e))) 365 (t c) (x "a") (x "c") (x c) (x d) (x e)))
366 366
367 (mapcar (lambda (x) (cond ((member '(a . b) x) 1) 367 (mapcar (lambda (x) (ignore-errors (cond ((member '(a . b) x) 1)
368 ((equal x '(c)) 2))) 368 ((equal x '(c)) 2))))
369 '(((a . b)) a b (c) (d))) 369 '(((a . b)) a b (c) (d)))
370 (mapcar (lambda (x) (cond ((memq '(a . b) x) 1) 370 (mapcar (lambda (x) (ignore-errors (cond ((memq '(a . b) x) 1)
371 ((equal x '(c)) 2))) 371 ((equal x '(c)) 2))))
372 '(((a . b)) a b (c) (d))) 372 '(((a . b)) a b (c) (d)))
373 (mapcar (lambda (x) (cond ((member '(a b) x) 1) 373 (mapcar (lambda (x) (ignore-errors (cond ((member '(a b) x) 1)
374 ((equal x '(c)) 2))) 374 ((equal x '(c)) 2))))
375 '(((a b)) a b (c) (d))) 375 '(((a b)) a b (c) (d)))
376 (mapcar (lambda (x) (cond ((memq '(a b) x) 1) 376 (mapcar (lambda (x) (ignore-errors (cond ((memq '(a b) x) 1)
377 ((equal x '(c)) 2))) 377 ((equal x '(c)) 2))))
378 '(((a b)) a b (c) (d))) 378 '(((a b)) a b (c) (d)))
379 379
380 (assoc 'b '((a 1) (b 2) (c 3))) 380 (assoc 'b '((a 1) (b 2) (c 3)))
@@ -396,7 +396,7 @@
396 x) 396 x)
397 397
398 (let ((x 1) (bytecomp-test-var 2) (y 3)) 398 (let ((x 1) (bytecomp-test-var 2) (y 3))
399 (list x bytecomp-test-var (bytecomp-get-test-var) y)) 399 (list x bytecomp-test-var (bytecomp-test-get-var) y))
400 400
401 (progn 401 (progn
402 (defvar d) 402 (defvar d)
@@ -430,69 +430,67 @@
430 (list s x i)) 430 (list s x i))
431 431
432 (let ((x 2)) 432 (let ((x 2))
433 (list (or (bytecomp-identity 'a) (setq x 3)) x))) 433 (list (or (bytecomp-test-identity 'a) (setq x 3)) x))
434 "List of expression for test.
435Each element will be executed by interpreter and with
436bytecompiled code, and their results compared.")
437 434
438(defun bytecomp-check-1 (pat) 435 (let* ((x 1)
439 "Return non-nil if PAT is the same whether directly evalled or compiled." 436 (y (condition-case x
440 (let ((warning-minimum-log-level :emergency) 437 (/ 1 0)
441 (byte-compile-warnings nil) 438 (arith-error x))))
442 (v0 (condition-case err 439 (list x y))
443 (eval pat) 440
444 (error (list 'bytecomp-check-error (car err))))) 441 (funcall
445 (v1 (condition-case err 442 (condition-case x
446 (funcall (byte-compile (list 'lambda nil pat))) 443 (/ 1 0)
447 (error (list 'bytecomp-check-error (car err)))))) 444 (arith-error (prog1 (lambda (y) (+ y x))
448 (equal v0 v1))) 445 (setq x 10))))
449 446 4)
450(put 'bytecomp-check-1 'ert-explainer 'bytecomp-explain-1) 447 )
451 448 "List of expressions for cross-testing interpreted and compiled code.")
452(defun bytecomp-explain-1 (pat) 449
453 (let ((v0 (condition-case err 450(defconst bytecomp-tests--test-cases-lexbind-only
454 (eval pat) 451 `(
455 (error (list 'bytecomp-check-error (car err))))) 452 ;; This would infloop (and exhaust stack) with dynamic binding.
456 (v1 (condition-case err 453 (let ((f #'car))
457 (funcall (byte-compile (list 'lambda nil pat))) 454 (let ((f (lambda (x) (cons (funcall f x) (cdr x)))))
458 (error (list 'bytecomp-check-error (car err)))))) 455 (funcall f '(1 . 2))))
459 (format "Expression `%s' gives `%s' if directly evalled, `%s' if compiled." 456 )
460 pat v0 v1))) 457 "List of expressions for cross-testing interpreted and compiled code.
461 458These are only tested with lexical binding.")
462(ert-deftest bytecomp-tests () 459
463 "Test the Emacs byte compiler." 460(defun bytecomp-tests--eval-interpreted (form)
464 (dolist (pat byte-opt-testsuite-arith-data) 461 "Evaluate FORM using the Lisp interpreter, returning errors as a
465 (should (bytecomp-check-1 pat)))) 462special value."
466 463 (condition-case err
467(defun test-byte-opt-arithmetic (&optional arg) 464 (eval form lexical-binding)
468 "Unit test for byte-opt arithmetic operations. 465 (error (list 'bytecomp-check-error (car err)))))
469Subtests signal errors if something goes wrong." 466
470 (interactive "P") 467(defun bytecomp-tests--eval-compiled (form)
471 (switch-to-buffer (generate-new-buffer "*Font Pase Test*")) 468 "Evaluate FORM using the Lisp byte-code compiler, returning errors as a
469special value."
472 (let ((warning-minimum-log-level :emergency) 470 (let ((warning-minimum-log-level :emergency)
473 (byte-compile-warnings nil) 471 (byte-compile-warnings nil))
474 (pass-face '((t :foreground "green"))) 472 (condition-case err
475 (fail-face '((t :foreground "red"))) 473 (funcall (byte-compile (list 'lambda nil form)))
476 (print-escape-nonascii t) 474 (error (list 'bytecomp-check-error (car err))))))
477 (print-escape-newlines t) 475
478 (print-quoted t) 476(ert-deftest bytecomp-tests-lexbind ()
479 v0 v1) 477 "Check that various expressions behave the same when interpreted and
480 (dolist (pat byte-opt-testsuite-arith-data) 478byte-compiled. Run with lexical binding."
481 (condition-case err 479 (let ((lexical-binding t))
482 (setq v0 (eval pat)) 480 (dolist (form (append bytecomp-tests--test-cases-lexbind-only
483 (error (setq v0 (list 'bytecomp-check-error (car err))))) 481 bytecomp-tests--test-cases))
484 (condition-case err 482 (ert-info ((prin1-to-string form) :prefix "form: ")
485 (setq v1 (funcall (byte-compile (list 'lambda nil pat)))) 483 (should (equal (bytecomp-tests--eval-interpreted form)
486 (error (setq v1 (list 'bytecomp-check-error (car err))))) 484 (bytecomp-tests--eval-compiled form)))))))
487 (insert (format "%s" pat)) 485
488 (indent-to-column 65) 486(ert-deftest bytecomp-tests-dynbind ()
489 (if (equal v0 v1) 487 "Check that various expressions behave the same when interpreted and
490 (insert (propertize "OK" 'face pass-face)) 488byte-compiled. Run with dynamic binding."
491 (insert (propertize "FAIL\n" 'face fail-face)) 489 (let ((lexical-binding nil))
492 (indent-to-column 55) 490 (dolist (form bytecomp-tests--test-cases)
493 (insert (propertize (format "[%s] vs [%s]" v0 v1) 491 (ert-info ((prin1-to-string form) :prefix "form: ")
494 'face fail-face))) 492 (should (equal (bytecomp-tests--eval-interpreted form)
495 (insert "\n")))) 493 (bytecomp-tests--eval-compiled form)))))))
496 494
497(defun test-byte-comp-compile-and-load (compile &rest forms) 495(defun test-byte-comp-compile-and-load (compile &rest forms)
498 (declare (indent 1)) 496 (declare (indent 1))
@@ -584,8 +582,8 @@ Subtests signal errors if something goes wrong."
584 `(with-current-buffer (get-buffer-create "*Compile-Log*") 582 `(with-current-buffer (get-buffer-create "*Compile-Log*")
585 (let ((inhibit-read-only t)) (erase-buffer)) 583 (let ((inhibit-read-only t)) (erase-buffer))
586 (byte-compile ,@form) 584 (byte-compile ,@form)
587 (ert-info ((buffer-string) :prefix "buffer: ") 585 (ert-info ((prin1-to-string (buffer-string)) :prefix "buffer: ")
588 (should (re-search-forward ,re-warning))))) 586 (should (re-search-forward ,(string-replace " " "[ \n]+" re-warning))))))
589 587
590(ert-deftest bytecomp-warn-wrong-args () 588(ert-deftest bytecomp-warn-wrong-args ()
591 (bytecomp--with-warning-test "remq.*3.*2" 589 (bytecomp--with-warning-test "remq.*3.*2"
@@ -611,12 +609,13 @@ Subtests signal errors if something goes wrong."
611 609
612(defmacro bytecomp--define-warning-file-test (file re-warning &optional reverse) 610(defmacro bytecomp--define-warning-file-test (file re-warning &optional reverse)
613 `(ert-deftest ,(intern (format "bytecomp/%s" file)) () 611 `(ert-deftest ,(intern (format "bytecomp/%s" file)) ()
614 :expected-result ,(if reverse :failed :passed)
615 (with-current-buffer (get-buffer-create "*Compile-Log*") 612 (with-current-buffer (get-buffer-create "*Compile-Log*")
616 (let ((inhibit-read-only t)) (erase-buffer)) 613 (let ((inhibit-read-only t)) (erase-buffer))
617 (byte-compile-file ,(ert-resource-file file)) 614 (byte-compile-file ,(ert-resource-file file))
618 (ert-info ((buffer-string) :prefix "buffer: ") 615 (ert-info ((buffer-string) :prefix "buffer: ")
619 (should (re-search-forward ,re-warning)))))) 616 (,(if reverse 'should-not 'should)
617 (re-search-forward ,(string-replace " " "[ \n]+" re-warning)
618 nil t))))))
620 619
621(bytecomp--define-warning-file-test "error-lexical-var-with-add-hook.el" 620(bytecomp--define-warning-file-test "error-lexical-var-with-add-hook.el"
622 "add-hook.*lexical var") 621 "add-hook.*lexical var")
@@ -658,10 +657,10 @@ Subtests signal errors if something goes wrong."
658 "free.*foo") 657 "free.*foo")
659 658
660(bytecomp--define-warning-file-test "warn-free-variable-reference.el" 659(bytecomp--define-warning-file-test "warn-free-variable-reference.el"
661 "free.*bar") 660 "free variable .bar")
662 661
663(bytecomp--define-warning-file-test "warn-make-variable-buffer-local.el" 662(bytecomp--define-warning-file-test "warn-make-variable-buffer-local.el"
664 "make-variable-buffer-local.*not called at toplevel") 663 "make-variable-buffer-local. not called at toplevel")
665 664
666(bytecomp--define-warning-file-test "warn-interactive-only.el" 665(bytecomp--define-warning-file-test "warn-interactive-only.el"
667 "next-line.*interactive use only.*forward-line") 666 "next-line.*interactive use only.*forward-line")
@@ -670,19 +669,19 @@ Subtests signal errors if something goes wrong."
670 "malformed interactive spec") 669 "malformed interactive spec")
671 670
672(bytecomp--define-warning-file-test "warn-obsolete-defun.el" 671(bytecomp--define-warning-file-test "warn-obsolete-defun.el"
673 "foo-obsolete.*obsolete function.*99.99") 672 "foo-obsolete. is an obsolete function (as of 99.99)")
674 673
675(defvar bytecomp--tests-obsolete-var nil) 674(defvar bytecomp--tests-obsolete-var nil)
676(make-obsolete-variable 'bytecomp--tests-obsolete-var nil "99.99") 675(make-obsolete-variable 'bytecomp--tests-obsolete-var nil "99.99")
677 676
678(bytecomp--define-warning-file-test "warn-obsolete-hook.el" 677(bytecomp--define-warning-file-test "warn-obsolete-hook.el"
679 "bytecomp--tests-obs.*obsolete[^z-a]*99.99") 678 "bytecomp--tests-obsolete-var. is an obsolete variable (as of 99.99)")
680 679
681(bytecomp--define-warning-file-test "warn-obsolete-variable-same-file.el" 680(bytecomp--define-warning-file-test "warn-obsolete-variable-same-file.el"
682 "foo-obs.*obsolete.*99.99" t) 681 "foo-obs.*obsolete.*99.99" t)
683 682
684(bytecomp--define-warning-file-test "warn-obsolete-variable.el" 683(bytecomp--define-warning-file-test "warn-obsolete-variable.el"
685 "bytecomp--tests-obs.*obsolete[^z-a]*99.99") 684 "bytecomp--tests-obsolete-var. is an obsolete variable (as of 99.99)")
686 685
687(bytecomp--define-warning-file-test "warn-obsolete-variable-bound.el" 686(bytecomp--define-warning-file-test "warn-obsolete-variable-bound.el"
688 "bytecomp--tests-obs.*obsolete.*99.99" t) 687 "bytecomp--tests-obs.*obsolete.*99.99" t)
@@ -713,64 +712,64 @@ Subtests signal errors if something goes wrong."
713 712
714(bytecomp--define-warning-file-test 713(bytecomp--define-warning-file-test
715 "warn-wide-docstring-autoload.el" 714 "warn-wide-docstring-autoload.el"
716 "autoload.*foox.*wider than.*characters") 715 "autoload .foox. docstring wider than .* characters")
717 716
718(bytecomp--define-warning-file-test 717(bytecomp--define-warning-file-test
719 "warn-wide-docstring-custom-declare-variable.el" 718 "warn-wide-docstring-custom-declare-variable.el"
720 "custom-declare-variable.*foo.*wider than.*characters") 719 "custom-declare-variable .foo. docstring wider than .* characters")
721 720
722(bytecomp--define-warning-file-test 721(bytecomp--define-warning-file-test
723 "warn-wide-docstring-defalias.el" 722 "warn-wide-docstring-defalias.el"
724 "defalias.*foo.*wider than.*characters") 723 "defalias .foo. docstring wider than .* characters")
725 724
726(bytecomp--define-warning-file-test 725(bytecomp--define-warning-file-test
727 "warn-wide-docstring-defconst.el" 726 "warn-wide-docstring-defconst.el"
728 "defconst.*foo.*wider than.*characters") 727 "defconst .foo-bar. docstring wider than .* characters")
729 728
730(bytecomp--define-warning-file-test 729(bytecomp--define-warning-file-test
731 "warn-wide-docstring-define-abbrev-table.el" 730 "warn-wide-docstring-define-abbrev-table.el"
732 "define-abbrev.*foo.*wider than.*characters") 731 "define-abbrev-table .foo. docstring wider than .* characters")
733 732
734(bytecomp--define-warning-file-test 733(bytecomp--define-warning-file-test
735 "warn-wide-docstring-define-obsolete-function-alias.el" 734 "warn-wide-docstring-define-obsolete-function-alias.el"
736 "defalias.*foo.*wider than.*characters") 735 "defalias .foo. docstring wider than .* characters")
737 736
738(bytecomp--define-warning-file-test 737(bytecomp--define-warning-file-test
739 "warn-wide-docstring-define-obsolete-variable-alias.el" 738 "warn-wide-docstring-define-obsolete-variable-alias.el"
740 "defvaralias.*foo.*wider than.*characters") 739 "defvaralias .foo. docstring wider than .* characters")
741 740
742;; TODO: We don't yet issue warnings for defuns. 741;; TODO: We don't yet issue warnings for defuns.
743(bytecomp--define-warning-file-test 742(bytecomp--define-warning-file-test
744 "warn-wide-docstring-defun.el" 743 "warn-wide-docstring-defun.el"
745 "wider than.*characters" 'reverse) 744 "wider than .* characters" 'reverse)
746 745
747(bytecomp--define-warning-file-test 746(bytecomp--define-warning-file-test
748 "warn-wide-docstring-defvar.el" 747 "warn-wide-docstring-defvar.el"
749 "defvar.*foo.*wider than.*characters") 748 "defvar .foo-bar. docstring wider than .* characters")
750 749
751(bytecomp--define-warning-file-test 750(bytecomp--define-warning-file-test
752 "warn-wide-docstring-defvaralias.el" 751 "warn-wide-docstring-defvaralias.el"
753 "defvaralias.*foo.*wider than.*characters") 752 "defvaralias .foo-bar. docstring wider than .* characters")
754 753
755(bytecomp--define-warning-file-test 754(bytecomp--define-warning-file-test
756 "warn-wide-docstring-ignore-fill-column.el" 755 "warn-wide-docstring-ignore-fill-column.el"
757 "defvar.*foo.*wider than.*characters" 'reverse) 756 "defvar .foo-bar. docstring wider than .* characters" 'reverse)
758 757
759(bytecomp--define-warning-file-test 758(bytecomp--define-warning-file-test
760 "warn-wide-docstring-ignore-override.el" 759 "warn-wide-docstring-ignore-override.el"
761 "defvar.*foo.*wider than.*characters" 'reverse) 760 "defvar .foo-bar. docstring wider than .* characters" 'reverse)
762 761
763(bytecomp--define-warning-file-test 762(bytecomp--define-warning-file-test
764 "warn-wide-docstring-ignore.el" 763 "warn-wide-docstring-ignore.el"
765 "defvar.*foo.*wider than.*characters" 'reverse) 764 "defvar .foo-bar. docstring wider than .* characters" 'reverse)
766 765
767(bytecomp--define-warning-file-test 766(bytecomp--define-warning-file-test
768 "warn-wide-docstring-multiline-first.el" 767 "warn-wide-docstring-multiline-first.el"
769 "defvar.*foo.*wider than.*characters") 768 "defvar .foo-bar. docstring wider than .* characters")
770 769
771(bytecomp--define-warning-file-test 770(bytecomp--define-warning-file-test
772 "warn-wide-docstring-multiline.el" 771 "warn-wide-docstring-multiline.el"
773 "defvar.*foo.*wider than.*characters") 772 "defvar .foo-bar. docstring wider than .* characters")
774 773
775(bytecomp--define-warning-file-test 774(bytecomp--define-warning-file-test
776 "nowarn-inline-after-defvar.el" 775 "nowarn-inline-after-defvar.el"
@@ -813,47 +812,6 @@ Subtests signal errors if something goes wrong."
813 (defun def () (m)))) 812 (defun def () (m))))
814 (should (equal (funcall 'def) 4))) 813 (should (equal (funcall 'def) 4)))
815 814
816(defconst bytecomp-lexbind-tests
817 `(
818 (let ((f #'car))
819 (let ((f (lambda (x) (cons (funcall f x) (cdr x)))))
820 (funcall f '(1 . 2))))
821 )
822 "List of expression for test.
823Each element will be executed by interpreter and with
824bytecompiled code, and their results compared.")
825
826(defun bytecomp-lexbind-check-1 (pat)
827 "Return non-nil if PAT is the same whether directly evalled or compiled."
828 (let ((warning-minimum-log-level :emergency)
829 (byte-compile-warnings nil)
830 (v0 (condition-case err
831 (eval pat t)
832 (error (list 'bytecomp-check-error (car err)))))
833 (v1 (condition-case err
834 (funcall (let ((lexical-binding t))
835 (byte-compile `(lambda nil ,pat))))
836 (error (list 'bytecomp-check-error (car err))))))
837 (equal v0 v1)))
838
839(put 'bytecomp-lexbind-check-1 'ert-explainer 'bytecomp-lexbind-explain-1)
840
841(defun bytecomp-lexbind-explain-1 (pat)
842 (let ((v0 (condition-case err
843 (eval pat t)
844 (error (list 'bytecomp-check-error (car err)))))
845 (v1 (condition-case err
846 (funcall (let ((lexical-binding t))
847 (byte-compile (list 'lambda nil pat))))
848 (error (list 'bytecomp-check-error (car err))))))
849 (format "Expression `%s' gives `%s' if directly evalled, `%s' if compiled."
850 pat v0 v1)))
851
852(ert-deftest bytecomp-lexbind-tests ()
853 "Test the Emacs byte compiler lexbind handling."
854 (dolist (pat bytecomp-lexbind-tests)
855 (should (bytecomp-lexbind-check-1 pat))))
856
857(defmacro bytecomp-tests--with-temp-file (file-name-var &rest body) 815(defmacro bytecomp-tests--with-temp-file (file-name-var &rest body)
858 (declare (indent 1)) 816 (declare (indent 1))
859 (cl-check-type file-name-var symbol) 817 (cl-check-type file-name-var symbol)
diff --git a/test/lisp/emacs-lisp/cl-macs-tests.el b/test/lisp/emacs-lisp/cl-macs-tests.el
index dd6487603d3..5c3e603b92e 100644
--- a/test/lisp/emacs-lisp/cl-macs-tests.el
+++ b/test/lisp/emacs-lisp/cl-macs-tests.el
@@ -629,14 +629,24 @@ collection clause."
629 (let (n1) 629 (let (n1)
630 (and xs 630 (and xs
631 (progn (setq n1 (1+ n)) 631 (progn (setq n1 (1+ n))
632 (len2 (cdr xs) n1))))))) 632 (len2 (cdr xs) n1))))))
633 ;; Tail call in error handler.
634 (len3 (xs n)
635 (if xs
636 (condition-case nil
637 (/ 1 0)
638 (arith-error (len3 (cdr xs) (1+ n))))
639 n)))
633 (should (equal (len nil 0) 0)) 640 (should (equal (len nil 0) 0))
634 (should (equal (len2 nil 0) 0)) 641 (should (equal (len2 nil 0) 0))
642 (should (equal (len3 nil 0) 0))
635 (should (equal (len list-42 0) 42)) 643 (should (equal (len list-42 0) 42))
636 (should (equal (len2 list-42 0) 42)) 644 (should (equal (len2 list-42 0) 42))
645 (should (equal (len3 list-42 0) 42))
637 ;; Should not bump into stack depth limits. 646 ;; Should not bump into stack depth limits.
638 (should (equal (len list-42k 0) 42000)) 647 (should (equal (len list-42k 0) 42000))
639 (should (equal (len2 list-42k 0) 42000)))) 648 (should (equal (len2 list-42k 0) 42000))
649 (should (equal (len3 list-42k 0) 42000))))
640 650
641 ;; Check that non-recursive functions are handled more efficiently. 651 ;; Check that non-recursive functions are handled more efficiently.
642 (should (pcase (macroexpand '(cl-labels ((f (x) (+ x 1))) (f 5))) 652 (should (pcase (macroexpand '(cl-labels ((f (x) (+ x 1))) (f 5)))
diff --git a/test/lisp/emacs-lisp/edebug-tests.el b/test/lisp/emacs-lisp/edebug-tests.el
index dcb261c2eb9..7d45432e57e 100644
--- a/test/lisp/emacs-lisp/edebug-tests.el
+++ b/test/lisp/emacs-lisp/edebug-tests.el
@@ -1061,5 +1061,30 @@ backtracking (Bug#42701)."
1061 "edebug-anon10001" 1061 "edebug-anon10001"
1062 "edebug-tests-duplicate-symbol-backtrack")))))) 1062 "edebug-tests-duplicate-symbol-backtrack"))))))
1063 1063
1064(defmacro edebug-tests--duplicate-&define (_arg)
1065 "Helper macro for the ERT test `edebug-tests-duplicate-&define'.
1066The Edebug specification is similar to the one used by `cl-flet'
1067previously; see Bug#41988."
1068 (declare (debug (&or (&define name function-form) (defun)))))
1069
1070(ert-deftest edebug-tests-duplicate-&define ()
1071 "Check that Edebug doesn't backtrack out of `&define' forms.
1072This avoids potential duplicate definitions (Bug#41988)."
1073 (with-temp-buffer
1074 (print '(defun edebug-tests-duplicate-&define ()
1075 (edebug-tests--duplicate-&define
1076 (edebug-tests-duplicate-&define-inner () nil)))
1077 (current-buffer))
1078 (let* ((edebug-all-defs t)
1079 (edebug-initial-mode 'Go-nonstop)
1080 (instrumented-names ())
1081 (edebug-new-definition-function
1082 (lambda (name)
1083 (when (memq name instrumented-names)
1084 (error "Duplicate definition of `%s'" name))
1085 (push name instrumented-names)
1086 (edebug-new-definition name))))
1087 (should-error (eval-buffer) :type 'invalid-read-syntax))))
1088
1064(provide 'edebug-tests) 1089(provide 'edebug-tests)
1065;;; edebug-tests.el ends here 1090;;; edebug-tests.el ends here
diff --git a/test/lisp/loadhist-tests.el b/test/lisp/loadhist-tests.el
new file mode 100644
index 00000000000..b29796da42d
--- /dev/null
+++ b/test/lisp/loadhist-tests.el
@@ -0,0 +1,57 @@
1;;; loadhist-tests.el --- Tests for loadhist.el -*- lexical-binding:t -*-
2
3;; Copyright (C) 2021 Free Software Foundation, Inc.
4
5;; Author: Stefan Kangas <stefankangas@gmail.com>
6
7;; This file is part of GNU Emacs.
8
9;; GNU Emacs is free software: you can redistribute it and/or modify
10;; it under the terms of the GNU General Public License as published by
11;; the Free Software Foundation, either version 3 of the License, or
12;; (at your option) any later version.
13
14;; GNU Emacs is distributed in the hope that it will be useful,
15;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17;; GNU General Public License for more details.
18
19;; You should have received a copy of the GNU General Public License
20;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
21
22;;; Commentary:
23
24;;; Code:
25
26(require 'ert)
27(require 'loadhist)
28
29(ert-deftest loadhist-tests-feature-symbols ()
30 (should (equal (file-name-base (car (feature-symbols 'loadhist))) "loadhist"))
31 (should-not (feature-symbols 'non-existent-feature)))
32
33(ert-deftest loadhist-tests-feature-file ()
34 (should (equal (file-name-base (feature-file 'loadhist)) "loadhist"))
35 (should-error (feature-file 'non-existent-feature)))
36
37(ert-deftest loadhist-tests-file-loadhist-lookup ()
38 ;; This should probably be extended...
39 (should (listp (file-loadhist-lookup "loadhist"))))
40
41(ert-deftest loadhist-tests-file-provides ()
42 (should (eq (car (file-provides "loadhist")) 'loadhist)))
43
44(ert-deftest loadhist-tests-file-requires ()
45 (should-not (file-requires "loadhist")))
46
47(ert-deftest loadhist-tests-file-dependents ()
48 (require 'dired-x)
49 (let ((deps (file-dependents "dired")))
50 (should (member "dired-x" (mapcar #'file-name-base deps)))))
51
52(ert-deftest loadhist-tests-unload-feature ()
53 (require 'dired-x)
54 (should-error (unload-feature 'dired))
55 (unload-feature 'dired-x))
56
57;;; loadhist-tests.el ends here
diff --git a/test/lisp/shadowfile-tests.el b/test/lisp/shadowfile-tests.el
index 0c2d7123dd7..7b9c2ff63b2 100644
--- a/test/lisp/shadowfile-tests.el
+++ b/test/lisp/shadowfile-tests.el
@@ -117,8 +117,8 @@
117 (ignore-errors (delete-file shadow-info-file)) 117 (ignore-errors (delete-file shadow-info-file))
118 (ignore-errors (delete-file shadow-todo-file)) 118 (ignore-errors (delete-file shadow-todo-file))
119 ;; Reset variables. 119 ;; Reset variables.
120 (shadow-invalidate-hashtable)
120 (setq shadow-info-buffer nil 121 (setq shadow-info-buffer nil
121 shadow-hashtable nil
122 shadow-todo-buffer nil 122 shadow-todo-buffer nil
123 shadow-files-to-copy nil)) 123 shadow-files-to-copy nil))
124 124