aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorNoam Postavsky2017-08-07 21:09:19 -0400
committerNoam Postavsky2017-08-07 21:09:19 -0400
commitbec5b602597b8b6f596067167f3b3fe0e6eff285 (patch)
treef228a53ad54805030c7bde905604aa4a4d08b816 /test
parente6fa08363dc950e48d72d41fd0f65444d2755ce3 (diff)
parent79a74568e9166f63a12adb30f54edcd57a6405a3 (diff)
downloademacs-bec5b602597b8b6f596067167f3b3fe0e6eff285.tar.gz
emacs-bec5b602597b8b6f596067167f3b3fe0e6eff285.zip
; Merge: Fixes for macroexpansion and compilation
Diffstat (limited to 'test')
-rw-r--r--test/lisp/dom-tests.el5
-rw-r--r--test/lisp/emacs-lisp/bytecomp-tests.el17
-rw-r--r--test/lisp/emacs-lisp/cl-lib-tests.el8
-rw-r--r--test/lisp/emacs-lisp/ert-tests.el9
-rw-r--r--test/lisp/emacs-lisp/gv-tests.el147
-rw-r--r--test/lisp/emacs-lisp/testcover-resources/testcases.el10
6 files changed, 195 insertions, 1 deletions
diff --git a/test/lisp/dom-tests.el b/test/lisp/dom-tests.el
index 32d231a47e5..24d4b932452 100644
--- a/test/lisp/dom-tests.el
+++ b/test/lisp/dom-tests.el
@@ -26,7 +26,10 @@
26 26
27(require 'dom) 27(require 'dom)
28(require 'ert) 28(require 'ert)
29(eval-when-compile (require 'subr-x)) 29
30;; `defsubst's are not inlined inside `ert-deftest' (see Bug#24402),
31;; therefore we can't use `eval-when-compile' here.
32(require 'subr-x)
30 33
31(defun dom-tests--tree () 34(defun dom-tests--tree ()
32 "Return a DOM tree for testing." 35 "Return a DOM tree for testing."
diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el
index d15bd8b6e65..8ef2ce70251 100644
--- a/test/lisp/emacs-lisp/bytecomp-tests.el
+++ b/test/lisp/emacs-lisp/bytecomp-tests.el
@@ -545,6 +545,23 @@ literals (Bug#20852)."
545This functionality has been obsolete for more than 10 years already 545This functionality has been obsolete for more than 10 years already
546and will be removed soon. See (elisp)Backquote in the manual."))))))) 546and will be removed soon. See (elisp)Backquote in the manual.")))))))
547 547
548
549(ert-deftest bytecomp-tests-function-put ()
550 "Check `function-put' operates during compilation."
551 (should (boundp 'lread--old-style-backquotes))
552 (bytecomp-tests--with-temp-file source
553 (dolist (form '((function-put 'bytecomp-tests--foo 'foo 1)
554 (function-put 'bytecomp-tests--foo 'bar 2)
555 (defmacro bytecomp-tests--foobar ()
556 `(cons ,(function-get 'bytecomp-tests--foo 'foo)
557 ,(function-get 'bytecomp-tests--foo 'bar)))
558 (defvar bytecomp-tests--foobar 1)
559 (setq bytecomp-tests--foobar (bytecomp-tests--foobar))))
560 (print form (current-buffer)))
561 (write-region (point-min) (point-max) source nil 'silent)
562 (byte-compile-file source t)
563 (should (equal bytecomp-tests--foobar (cons 1 2)))))
564
548;; Local Variables: 565;; Local Variables:
549;; no-byte-compile: t 566;; no-byte-compile: t
550;; End: 567;; End:
diff --git a/test/lisp/emacs-lisp/cl-lib-tests.el b/test/lisp/emacs-lisp/cl-lib-tests.el
index 65bd97f3b2d..9e68dceb8f1 100644
--- a/test/lisp/emacs-lisp/cl-lib-tests.el
+++ b/test/lisp/emacs-lisp/cl-lib-tests.el
@@ -518,7 +518,15 @@
518(ert-deftest cl-lib-symbol-macrolet-2 () 518(ert-deftest cl-lib-symbol-macrolet-2 ()
519 (should (equal (cl-lib-symbol-macrolet-4+5) (+ 4 5)))) 519 (should (equal (cl-lib-symbol-macrolet-4+5) (+ 4 5))))
520 520
521(defun cl-lib-tests--dummy-function ()
522 ;; Dummy function to see if the file is compiled.
523 t)
524
521(ert-deftest cl-lib-defstruct-record () 525(ert-deftest cl-lib-defstruct-record ()
526 ;; This test fails when compiled, see Bug#24402/27718.
527 :expected-result (if (byte-code-function-p
528 (symbol-function 'cl-lib-tests--dummy-function))
529 :failed :passed)
522 (cl-defstruct foo x) 530 (cl-defstruct foo x)
523 (let ((x (make-foo :x 42))) 531 (let ((x (make-foo :x 42)))
524 (should (recordp x)) 532 (should (recordp x))
diff --git a/test/lisp/emacs-lisp/ert-tests.el b/test/lisp/emacs-lisp/ert-tests.el
index 57463ad932d..2fbc188dcb9 100644
--- a/test/lisp/emacs-lisp/ert-tests.el
+++ b/test/lisp/emacs-lisp/ert-tests.el
@@ -294,6 +294,15 @@ failed or if there was a problem."
294 "the error signaled was a subtype of the expected type"))))) 294 "the error signaled was a subtype of the expected type")))))
295 )) 295 ))
296 296
297(ert-deftest ert-test-should-error-argument ()
298 "Errors due to evaluating arguments should not break tests."
299 (should-error (identity (/ 1 0))))
300
301(ert-deftest ert-test-should-error-macroexpansion ()
302 "Errors due to expanding macros should not break tests."
303 (cl-macrolet ((test () (error "Foo")))
304 (should-error (test))))
305
297(ert-deftest ert-test-skip-unless () 306(ert-deftest ert-test-skip-unless ()
298 ;; Don't skip. 307 ;; Don't skip.
299 (let ((test (make-ert-test :body (lambda () (skip-unless t))))) 308 (let ((test (make-ert-test :body (lambda () (skip-unless t)))))
diff --git a/test/lisp/emacs-lisp/gv-tests.el b/test/lisp/emacs-lisp/gv-tests.el
new file mode 100644
index 00000000000..f19af024b57
--- /dev/null
+++ b/test/lisp/emacs-lisp/gv-tests.el
@@ -0,0 +1,147 @@
1;;; gv-tests.el --- tests for gv.el -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2017 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 <http://www.gnu.org/licenses/>.
19
20;;; Code:
21
22(require 'ert)
23(eval-when-compile (require 'cl-lib))
24
25(cl-defmacro gv-tests--in-temp-dir ((elvar elcvar)
26 (&rest filebody)
27 &rest body)
28 (declare (indent 2))
29 `(let ((default-directory (make-temp-file "gv-test" t)))
30 (unwind-protect
31 (let ((,elvar "gv-test-deffoo.el")
32 (,elcvar "gv-test-deffoo.elc"))
33 (with-temp-file ,elvar
34 (insert ";; -*- lexical-binding: t; -*-\n")
35 (dolist (form ',filebody)
36 (pp form (current-buffer))))
37 ,@body)
38 (delete-directory default-directory t))))
39
40(ert-deftest gv-define-expander-in-file ()
41 (gv-tests--in-temp-dir (el elc)
42 ((gv-define-setter gv-test-foo (newval cons)
43 `(setcar ,cons ,newval))
44 (defvar gv-test-pair (cons 1 2))
45 (setf (gv-test-foo gv-test-pair) 99)
46 (message "%d" (car gv-test-pair)))
47 (with-temp-buffer
48 (call-process (concat invocation-directory invocation-name)
49 nil '(t t) nil
50 "-Q" "-batch" "--eval" (prin1-to-string `(byte-compile-file ,el))
51 "-l" elc)
52 (should (equal (buffer-string) "99\n")))))
53
54(ert-deftest gv-define-expander-in-file-twice ()
55 (gv-tests--in-temp-dir (el elc)
56 ((gv-define-setter gv-test-foo (newval cons)
57 `(setcar ,cons ,newval))
58 (defvar gv-test-pair (cons 1 2))
59 (setf (gv-test-foo gv-test-pair) 99)
60 (gv-define-setter gv-test-foo (newval cons)
61 `(setcdr ,cons ,newval))
62 (setf (gv-test-foo gv-test-pair) 42)
63 (message "%S" gv-test-pair))
64 (with-temp-buffer
65 (call-process (concat invocation-directory invocation-name)
66 nil '(t t) nil
67 "-Q" "-batch" "--eval" (prin1-to-string `(byte-compile-file ,el))
68 "-l" elc)
69 (should (equal (buffer-string) "(99 . 42)\n")))))
70
71(ert-deftest gv-dont-define-expander-in-file ()
72 ;; The expander is defined while we are compiling the file, even
73 ;; though it's inside (when nil ...) because the compiler won't
74 ;; analyze the conditional.
75 :expected-result :failed
76 (gv-tests--in-temp-dir (el elc)
77 ((when nil (gv-define-setter gv-test-foo (newval cons)
78 `(setcar ,cons ,newval)))
79 (defvar gv-test-pair (cons 1 2))
80 (setf (gv-test-foo gv-test-pair) 99)
81 (message "%d" (car gv-test-pair)))
82 (with-temp-buffer
83 (call-process (concat invocation-directory invocation-name)
84 nil '(t t) nil
85 "-Q" "-batch" "--eval" (prin1-to-string `(byte-compile-file ,el))
86 "-l" elc)
87 (should (equal (buffer-string)
88 "Symbol's function definition is void: \\(setf\\ gv-test-foo\\)\n")))))
89
90(ert-deftest gv-define-expander-in-function ()
91 ;; The expander is not defined while we are compiling the file, the
92 ;; compiler won't handle gv definitions not at top-level.
93 :expected-result :failed
94 (gv-tests--in-temp-dir (el elc)
95 ((defun foo ()
96 (gv-define-setter gv-test-foo (newval cons)
97 `(setcar ,cons ,newval))
98 t)
99 (defvar gv-test-pair (cons 1 2))
100 (setf (gv-test-foo gv-test-pair) 99)
101 (message "%d" (car gv-test-pair)))
102 (with-temp-buffer
103 (call-process (concat invocation-directory invocation-name)
104 nil '(t t) nil
105 "-Q" "-batch" "--eval" (prin1-to-string `(byte-compile-file ,el))
106 "-l" elc)
107 (should (equal (buffer-string) "99\n")))))
108
109(ert-deftest gv-define-expander-out-of-file ()
110 (gv-tests--in-temp-dir (el elc)
111 ((gv-define-setter gv-test-foo (newval cons)
112 `(setcar ,cons ,newval))
113 (defvar gv-test-pair (cons 1 2)))
114 (with-temp-buffer
115 (call-process (concat invocation-directory invocation-name)
116 nil '(t t) nil
117 "-Q" "-batch" "--eval" (prin1-to-string `(byte-compile-file ,el))
118 "-l" elc
119 "--eval"
120 (prin1-to-string '(progn (setf (gv-test-foo gv-test-pair) 99)
121 (message "%d" (car gv-test-pair)))))
122 (should (equal (buffer-string) "99\n")))))
123
124(ert-deftest gv-dont-define-expander-other-file ()
125 (gv-tests--in-temp-dir (el elc)
126 ((if nil (gv-define-setter gv-test-foo (newval cons)
127 `(setcar ,cons ,newval)))
128 (defvar gv-test-pair (cons 1 2)))
129 (with-temp-buffer
130 (call-process (concat invocation-directory invocation-name)
131 nil '(t t) nil
132 "-Q" "-batch" "--eval" (prin1-to-string `(byte-compile-file ,el))
133 "-l" elc
134 "--eval"
135 (prin1-to-string '(progn (setf (gv-test-foo gv-test-pair) 99)
136 (message "%d" (car gv-test-pair)))))
137 (should (equal (buffer-string)
138 "Symbol's function definition is void: \\(setf\\ gv-test-foo\\)\n")))))
139
140;; `ert-deftest' messes up macroexpansion when the test file itself is
141;; compiled (see Bug #24402).
142
143;; Local Variables:
144;; no-byte-compile: t
145;; End:
146
147;;; gv-tests.el ends here
diff --git a/test/lisp/emacs-lisp/testcover-resources/testcases.el b/test/lisp/emacs-lisp/testcover-resources/testcases.el
index 1eb791a993c..c9a5a6daacd 100644
--- a/test/lisp/emacs-lisp/testcover-resources/testcases.el
+++ b/test/lisp/emacs-lisp/testcover-resources/testcases.el
@@ -490,4 +490,14 @@ edebug spec, so testcover needs to cope with that."
490 490
491(should (eq (testcover-testcase-how-do-i-know-you "Liz") 'unknown)) 491(should (eq (testcover-testcase-how-do-i-know-you "Liz") 'unknown))
492 492
493;; ==== circular-lists-bug-24402 ====
494"Testcover captures and ignores circular list errors."
495;; ====
496(defun testcover-testcase-cyc1 (a)
497 (let ((ls (make-list 10 a%%%)))
498 (nconc ls ls)
499 ls))
500(testcover-testcase-cyc1 1)
501(testcover-testcase-cyc1 1)
502
493;; testcases.el ends here. 503;; testcases.el ends here.