aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDaniel Colascione2014-04-22 00:04:34 -0700
committerDaniel Colascione2014-04-22 00:04:34 -0700
commit12b1389c9039dd374951673ca43b1ddf65df400d (patch)
treef4d36afc9d1ccdd72f3d801b350d79d25dd5e8bb /test
parentc98212f9e7cef496dded06eba4476033062c171f (diff)
downloademacs-12b1389c9039dd374951673ca43b1ddf65df400d.tar.gz
emacs-12b1389c9039dd374951673ca43b1ddf65df400d.zip
Correctly macroexpand top-level forms during eager macroexpand
* lisp/emacs-lisp/byte-run.el (eval-when-compile, eval-and-compile): Improve docstrings. * lisp/emacs-lisp/macroexp.el (internal-macroexpand-for-load): Add `full-p' parameter; when nil, call `macroexpand' instead of `macroexpand-all'. * src/lread.c (readevalloop_eager_expand_eval): New function that can recurse into toplevel forms. (readevalloop): Call it. * src/lisp.h: Declare Qprogn. * src/callint.c (Qprogn): No longer static. * test/automated/bytecomp-tests.el (test-byte-comp-compile-and-load): Add compile flag. (test-byte-comp-macro-expansion) (test-byte-comp-macro-expansion-eval-and-compile) (test-byte-comp-macro-expansion-eval-when-compile) (test-byte-comp-macro-expand-lexical-override): Use it. (test-eager-load-macro-expansion) (test-eager-load-macro-expansion-eval-and-compile) (test-eager-load-macro-expansion-eval-when-compile) (test-eager-load-macro-expand-lexical-override): New tests.
Diffstat (limited to 'test')
-rw-r--r--test/ChangeLog14
-rw-r--r--test/automated/bytecomp-tests.el56
2 files changed, 60 insertions, 10 deletions
diff --git a/test/ChangeLog b/test/ChangeLog
index 1163402fd19..1caf0b3eb85 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,7 +1,19 @@
12014-04-22 Daniel Colascione <dancol@dancol.org> 12014-04-22 Daniel Colascione <dancol@dancol.org>
2 2
3 * automated/bytecomp-tests.el (test-byte-comp-compile-and-load):
4 Add compile flag.
5 (test-byte-comp-macro-expansion)
6 (test-byte-comp-macro-expansion-eval-and-compile)
7 (test-byte-comp-macro-expansion-eval-when-compile)
8 (test-byte-comp-macro-expand-lexical-override): Use it.
9 (test-eager-load-macro-expansion)
10 (test-eager-load-macro-expansion-eval-and-compile)
11 (test-eager-load-macro-expansion-eval-when-compile)
12 (test-eager-load-macro-expand-lexical-override): New tests.
13
3 * automated/cl-lib.el (cl-lib-struct-accessors): Fix test to 14 * automated/cl-lib.el (cl-lib-struct-accessors): Fix test to
4 account for removal of `cl-struct-set-slot-value'. 15 account for removal of `cl-struct-set-slot-value'. Also, move
16 the defstruct to top level.
5 17
62014-04-21 Daniel Colascione <dancol@dancol.org> 182014-04-21 Daniel Colascione <dancol@dancol.org>
7 19
diff --git a/test/automated/bytecomp-tests.el b/test/automated/bytecomp-tests.el
index e61c7c3a41d..a7fbdbe2e7f 100644
--- a/test/automated/bytecomp-tests.el
+++ b/test/automated/bytecomp-tests.el
@@ -305,30 +305,33 @@ Subtests signal errors if something goes wrong."
305 'face fail-face))) 305 'face fail-face)))
306 (insert "\n")))) 306 (insert "\n"))))
307 307
308(defun test-byte-comp-compile-and-load (&rest forms) 308(defun test-byte-comp-compile-and-load (compile &rest forms)
309 (let ((elfile nil) 309 (let ((elfile nil)
310 (elcfile nil)) 310 (elcfile nil))
311 (unwind-protect 311 (unwind-protect
312 (progn 312 (progn
313 (setf elfile (make-temp-file "test-bytecomp" nil ".el")) 313 (setf elfile (make-temp-file "test-bytecomp" nil ".el"))
314 (setf elcfile (make-temp-file "test-bytecomp" nil ".elc")) 314 (when compile
315 (setf elcfile (make-temp-file "test-bytecomp" nil ".elc")))
315 (with-temp-buffer 316 (with-temp-buffer
316 (dolist (form forms) 317 (dolist (form forms)
317 (print form (current-buffer))) 318 (print form (current-buffer)))
318 (write-region (point-min) (point-max) elfile)) 319 (write-region (point-min) (point-max) elfile))
319 (let ((byte-compile-dest-file elcfile)) 320 (if compile
320 (byte-compile-file elfile t))) 321 (let ((byte-compile-dest-file elcfile))
322 (byte-compile-file elfile t))
323 (load elfile)))
321 (when elfile (delete-file elfile)) 324 (when elfile (delete-file elfile))
322 (when elcfile (delete-file elcfile))))) 325 (when elcfile (delete-file elcfile)))))
323(put 'test-byte-comp-compile-and-load 'lisp-indent-function 0) 326(put 'test-byte-comp-compile-and-load 'lisp-indent-function 1)
324 327
325(ert-deftest test-byte-comp-macro-expansion () 328(ert-deftest test-byte-comp-macro-expansion ()
326 (test-byte-comp-compile-and-load 329 (test-byte-comp-compile-and-load t
327 '(progn (defmacro abc (arg) 1) (defun def () (abc 2)))) 330 '(progn (defmacro abc (arg) 1) (defun def () (abc 2))))
328 (should (equal (funcall 'def) 1))) 331 (should (equal (funcall 'def) 1)))
329 332
330(ert-deftest test-byte-comp-macro-expansion-eval-and-compile () 333(ert-deftest test-byte-comp-macro-expansion-eval-and-compile ()
331 (test-byte-comp-compile-and-load 334 (test-byte-comp-compile-and-load t
332 '(eval-and-compile (defmacro abc (arg) -1) (defun def () (abc 2)))) 335 '(eval-and-compile (defmacro abc (arg) -1) (defun def () (abc 2))))
333 (should (equal (funcall 'def) -1))) 336 (should (equal (funcall 'def) -1)))
334 337
@@ -336,7 +339,7 @@ Subtests signal errors if something goes wrong."
336 ;; Make sure we interpret eval-when-compile forms properly. CLISP 339 ;; Make sure we interpret eval-when-compile forms properly. CLISP
337 ;; and SBCL interpreter eval-when-compile (well, the CL equivalent) 340 ;; and SBCL interpreter eval-when-compile (well, the CL equivalent)
338 ;; in the same way. 341 ;; in the same way.
339 (test-byte-comp-compile-and-load 342 (test-byte-comp-compile-and-load t
340 '(eval-when-compile 343 '(eval-when-compile
341 (defmacro abc (arg) -10) 344 (defmacro abc (arg) -10)
342 (defun abc-1 () (abc 2))) 345 (defun abc-1 () (abc 2)))
@@ -349,13 +352,48 @@ Subtests signal errors if something goes wrong."
349 ;; macrolet since macrolet's is explicitly called out as being 352 ;; macrolet since macrolet's is explicitly called out as being
350 ;; equivalent to toplevel, but CLISP and SBCL both evaluate the form 353 ;; equivalent to toplevel, but CLISP and SBCL both evaluate the form
351 ;; this way, so we should too. 354 ;; this way, so we should too.
352 (test-byte-comp-compile-and-load 355 (test-byte-comp-compile-and-load t
353 '(require 'cl-lib) 356 '(require 'cl-lib)
354 '(cl-macrolet ((m () 4)) 357 '(cl-macrolet ((m () 4))
355 (defmacro m () 5) 358 (defmacro m () 5)
356 (defun def () (m)))) 359 (defun def () (m))))
357 (should (equal (funcall 'def) 4))) 360 (should (equal (funcall 'def) 4)))
358 361
362(ert-deftest test-eager-load-macro-expansion ()
363 (test-byte-comp-compile-and-load nil
364 '(progn (defmacro abc (arg) 1) (defun def () (abc 2))))
365 (should (equal (funcall 'def) 1)))
366
367(ert-deftest test-eager-load-macro-expansion-eval-and-compile ()
368 (test-byte-comp-compile-and-load nil
369 '(eval-and-compile (defmacro abc (arg) -1) (defun def () (abc 2))))
370 (should (equal (funcall 'def) -1)))
371
372(ert-deftest test-eager-load-macro-expansion-eval-when-compile ()
373 ;; Make sure we interpret eval-when-compile forms properly. CLISP
374 ;; and SBCL interpreter eval-when-compile (well, the CL equivalent)
375 ;; in the same way.
376 (test-byte-comp-compile-and-load nil
377 '(eval-when-compile
378 (defmacro abc (arg) -10)
379 (defun abc-1 () (abc 2)))
380 '(defmacro abc-2 () (abc-1))
381 '(defun def () (abc-2)))
382 (should (equal (funcall 'def) -10)))
383
384(ert-deftest test-eager-load-macro-expand-lexical-override ()
385 ;; Intuitively, one might expect the defmacro to override the
386 ;; macrolet since macrolet's is explicitly called out as being
387 ;; equivalent to toplevel, but CLISP and SBCL both evaluate the form
388 ;; this way, so we should too.
389 (test-byte-comp-compile-and-load nil
390 '(require 'cl-lib)
391 '(cl-macrolet ((m () 4))
392 (defmacro m () 5)
393 (defun def () (m))))
394 (should (equal (funcall 'def) 4)))
395
396
359;; Local Variables: 397;; Local Variables:
360;; no-byte-compile: t 398;; no-byte-compile: t
361;; End: 399;; End: