diff options
| author | Noam Postavsky | 2017-08-07 21:09:19 -0400 |
|---|---|---|
| committer | Noam Postavsky | 2017-08-07 21:09:19 -0400 |
| commit | bec5b602597b8b6f596067167f3b3fe0e6eff285 (patch) | |
| tree | f228a53ad54805030c7bde905604aa4a4d08b816 | |
| parent | e6fa08363dc950e48d72d41fd0f65444d2755ce3 (diff) | |
| parent | 79a74568e9166f63a12adb30f54edcd57a6405a3 (diff) | |
| download | emacs-bec5b602597b8b6f596067167f3b3fe0e6eff285.tar.gz emacs-bec5b602597b8b6f596067167f3b3fe0e6eff285.zip | |
; Merge: Fixes for macroexpansion and compilation
| -rw-r--r-- | lisp/emacs-lisp/bytecomp.el | 29 | ||||
| -rw-r--r-- | lisp/emacs-lisp/eieio.el | 2 | ||||
| -rw-r--r-- | lisp/emacs-lisp/ert.el | 41 | ||||
| -rw-r--r-- | lisp/emacs-lisp/gv.el | 7 | ||||
| -rw-r--r-- | lisp/emacs-lisp/testcover.el | 10 | ||||
| -rw-r--r-- | src/fns.c | 11 | ||||
| -rw-r--r-- | test/lisp/dom-tests.el | 5 | ||||
| -rw-r--r-- | test/lisp/emacs-lisp/bytecomp-tests.el | 17 | ||||
| -rw-r--r-- | test/lisp/emacs-lisp/cl-lib-tests.el | 8 | ||||
| -rw-r--r-- | test/lisp/emacs-lisp/ert-tests.el | 9 | ||||
| -rw-r--r-- | test/lisp/emacs-lisp/gv-tests.el | 147 | ||||
| -rw-r--r-- | test/lisp/emacs-lisp/testcover-resources/testcases.el | 10 |
12 files changed, 277 insertions, 19 deletions
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 5fa7389e431..9e14c91c953 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el | |||
| @@ -1572,6 +1572,7 @@ extra args." | |||
| 1572 | ;; macroenvironment. | 1572 | ;; macroenvironment. |
| 1573 | (copy-alist byte-compile-initial-macro-environment)) | 1573 | (copy-alist byte-compile-initial-macro-environment)) |
| 1574 | (byte-compile--outbuffer nil) | 1574 | (byte-compile--outbuffer nil) |
| 1575 | (overriding-plist-environment nil) | ||
| 1575 | (byte-compile-function-environment nil) | 1576 | (byte-compile-function-environment nil) |
| 1576 | (byte-compile-bound-variables nil) | 1577 | (byte-compile-bound-variables nil) |
| 1577 | (byte-compile-lexical-variables nil) | 1578 | (byte-compile-lexical-variables nil) |
| @@ -4714,6 +4715,34 @@ binding slots have been popped." | |||
| 4714 | 'byte-hunk-handler 'byte-compile-form-make-variable-buffer-local) | 4715 | 'byte-hunk-handler 'byte-compile-form-make-variable-buffer-local) |
| 4715 | (defun byte-compile-form-make-variable-buffer-local (form) | 4716 | (defun byte-compile-form-make-variable-buffer-local (form) |
| 4716 | (byte-compile-keep-pending form 'byte-compile-normal-call)) | 4717 | (byte-compile-keep-pending form 'byte-compile-normal-call)) |
| 4718 | |||
| 4719 | (put 'function-put 'byte-hunk-handler 'byte-compile-define-symbol-prop) | ||
| 4720 | (put 'define-symbol-prop 'byte-hunk-handler 'byte-compile-define-symbol-prop) | ||
| 4721 | (defun byte-compile-define-symbol-prop (form) | ||
| 4722 | (pcase form | ||
| 4723 | ((and `(,op ,fun ,prop ,val) | ||
| 4724 | (guard (and (macroexp-const-p fun) | ||
| 4725 | (macroexp-const-p prop) | ||
| 4726 | (or (macroexp-const-p val) | ||
| 4727 | ;; Also accept anonymous functions, since | ||
| 4728 | ;; we're at top-level which implies they're | ||
| 4729 | ;; also constants. | ||
| 4730 | (pcase val (`(function (lambda . ,_)) t)))))) | ||
| 4731 | (byte-compile-push-constant op) | ||
| 4732 | (byte-compile-form fun) | ||
| 4733 | (byte-compile-form prop) | ||
| 4734 | (let* ((fun (eval fun)) | ||
| 4735 | (prop (eval prop)) | ||
| 4736 | (val (if (macroexp-const-p val) | ||
| 4737 | (eval val) | ||
| 4738 | (byte-compile-lambda (cadr val))))) | ||
| 4739 | (push `(,fun | ||
| 4740 | . (,prop ,val ,@(alist-get fun overriding-plist-environment))) | ||
| 4741 | overriding-plist-environment) | ||
| 4742 | (byte-compile-push-constant val) | ||
| 4743 | (byte-compile-out 'byte-call 3))) | ||
| 4744 | |||
| 4745 | (_ (byte-compile-keep-pending form)))) | ||
| 4717 | 4746 | ||
| 4718 | ;;; tags | 4747 | ;;; tags |
| 4719 | 4748 | ||
diff --git a/lisp/emacs-lisp/eieio.el b/lisp/emacs-lisp/eieio.el index 1a7de55fcef..8b92d5b7acd 100644 --- a/lisp/emacs-lisp/eieio.el +++ b/lisp/emacs-lisp/eieio.el | |||
| @@ -246,7 +246,7 @@ This method is obsolete." | |||
| 246 | ;; test, so we can let typep have the CLOS documented behavior | 246 | ;; test, so we can let typep have the CLOS documented behavior |
| 247 | ;; while keeping our above predicate clean. | 247 | ;; while keeping our above predicate clean. |
| 248 | 248 | ||
| 249 | (put ',name 'cl-deftype-satisfies #',testsym2) | 249 | (define-symbol-prop ',name 'cl-deftype-satisfies #',testsym2) |
| 250 | 250 | ||
| 251 | (eieio-defclass-internal ',name ',superclasses ',slots ',options-and-doc) | 251 | (eieio-defclass-internal ',name ',superclasses ',slots ',options-and-doc) |
| 252 | 252 | ||
diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el index d7bd331c11b..c232b08bd1a 100644 --- a/lisp/emacs-lisp/ert.el +++ b/lisp/emacs-lisp/ert.el | |||
| @@ -260,6 +260,14 @@ DATA is displayed to the user and should state the reason for skipping." | |||
| 260 | (when ert--should-execution-observer | 260 | (when ert--should-execution-observer |
| 261 | (funcall ert--should-execution-observer form-description))) | 261 | (funcall ert--should-execution-observer form-description))) |
| 262 | 262 | ||
| 263 | ;; See Bug#24402 for why this exists | ||
| 264 | (defun ert--should-signal-hook (error-symbol data) | ||
| 265 | "Stupid hack to stop `condition-case' from catching ert signals. | ||
| 266 | It should only be stopped when ran from inside ert--run-test-internal." | ||
| 267 | (when (and (not (symbolp debugger)) ; only run on anonymous debugger | ||
| 268 | (memq error-symbol '(ert-test-failed ert-test-skipped))) | ||
| 269 | (funcall debugger 'error data))) | ||
| 270 | |||
| 263 | (defun ert--special-operator-p (thing) | 271 | (defun ert--special-operator-p (thing) |
| 264 | "Return non-nil if THING is a symbol naming a special operator." | 272 | "Return non-nil if THING is a symbol naming a special operator." |
| 265 | (and (symbolp thing) | 273 | (and (symbolp thing) |
| @@ -267,16 +275,22 @@ DATA is displayed to the user and should state the reason for skipping." | |||
| 267 | (and (subrp definition) | 275 | (and (subrp definition) |
| 268 | (eql (cdr (subr-arity definition)) 'unevalled))))) | 276 | (eql (cdr (subr-arity definition)) 'unevalled))))) |
| 269 | 277 | ||
| 278 | ;; FIXME: Code inside of here should probably be evaluated like it is | ||
| 279 | ;; outside of tests, with the sole exception of error handling | ||
| 270 | (defun ert--expand-should-1 (whole form inner-expander) | 280 | (defun ert--expand-should-1 (whole form inner-expander) |
| 271 | "Helper function for the `should' macro and its variants." | 281 | "Helper function for the `should' macro and its variants." |
| 272 | (let ((form | 282 | (let ((form |
| 273 | (macroexpand form (append (bound-and-true-p | 283 | ;; catch macroexpansion errors |
| 274 | byte-compile-macro-environment) | 284 | (condition-case err |
| 275 | (cond | 285 | (macroexpand-all form |
| 276 | ((boundp 'macroexpand-all-environment) | 286 | (append (bound-and-true-p |
| 277 | macroexpand-all-environment) | 287 | byte-compile-macro-environment) |
| 278 | ((boundp 'cl-macro-environment) | 288 | (cond |
| 279 | cl-macro-environment)))))) | 289 | ((boundp 'macroexpand-all-environment) |
| 290 | macroexpand-all-environment) | ||
| 291 | ((boundp 'cl-macro-environment) | ||
| 292 | cl-macro-environment)))) | ||
| 293 | (error `(signal ',(car err) ',(cdr err)))))) | ||
| 280 | (cond | 294 | (cond |
| 281 | ((or (atom form) (ert--special-operator-p (car form))) | 295 | ((or (atom form) (ert--special-operator-p (car form))) |
| 282 | (let ((value (cl-gensym "value-"))) | 296 | (let ((value (cl-gensym "value-"))) |
| @@ -297,8 +311,13 @@ DATA is displayed to the user and should state the reason for skipping." | |||
| 297 | (args (cl-gensym "args-")) | 311 | (args (cl-gensym "args-")) |
| 298 | (value (cl-gensym "value-")) | 312 | (value (cl-gensym "value-")) |
| 299 | (default-value (cl-gensym "ert-form-evaluation-aborted-"))) | 313 | (default-value (cl-gensym "ert-form-evaluation-aborted-"))) |
| 300 | `(let ((,fn (function ,fn-name)) | 314 | `(let* ((,fn (function ,fn-name)) |
| 301 | (,args (list ,@arg-forms))) | 315 | (,args (condition-case err |
| 316 | (let ((signal-hook-function #'ert--should-signal-hook)) | ||
| 317 | (list ,@arg-forms)) | ||
| 318 | (error (progn (setq ,fn #'signal) | ||
| 319 | (list (car err) | ||
| 320 | (cdr err))))))) | ||
| 302 | (let ((,value ',default-value)) | 321 | (let ((,value ',default-value)) |
| 303 | ,(funcall inner-expander | 322 | ,(funcall inner-expander |
| 304 | `(setq ,value (apply ,fn ,args)) | 323 | `(setq ,value (apply ,fn ,args)) |
| @@ -760,6 +779,10 @@ This mainly sets up debugger-related bindings." | |||
| 760 | ;; too expensive, we can remove it. | 779 | ;; too expensive, we can remove it. |
| 761 | (with-temp-buffer | 780 | (with-temp-buffer |
| 762 | (save-window-excursion | 781 | (save-window-excursion |
| 782 | ;; FIXME: Use `signal-hook-function' instead of `debugger' to | ||
| 783 | ;; handle ert errors. Once that's done, remove | ||
| 784 | ;; `ert--should-signal-hook'. See Bug#24402 and Bug#11218 for | ||
| 785 | ;; details. | ||
| 763 | (let ((debugger (lambda (&rest args) | 786 | (let ((debugger (lambda (&rest args) |
| 764 | (ert--run-test-debugger test-execution-info | 787 | (ert--run-test-debugger test-execution-info |
| 765 | args))) | 788 | args))) |
diff --git a/lisp/emacs-lisp/gv.el b/lisp/emacs-lisp/gv.el index 27376fc7f95..a8b8974cb4f 100644 --- a/lisp/emacs-lisp/gv.el +++ b/lisp/emacs-lisp/gv.el | |||
| @@ -146,12 +146,7 @@ NAME is a symbol: the name of a function, macro, or special form. | |||
| 146 | HANDLER is a function which takes an argument DO followed by the same | 146 | HANDLER is a function which takes an argument DO followed by the same |
| 147 | arguments as NAME. DO is a function as defined in `gv-get'." | 147 | arguments as NAME. DO is a function as defined in `gv-get'." |
| 148 | (declare (indent 1) (debug (sexp form))) | 148 | (declare (indent 1) (debug (sexp form))) |
| 149 | ;; Use eval-and-compile so the method can be used in the same file as it | 149 | `(function-put ',name 'gv-expander ,handler)) |
| 150 | ;; is defined. | ||
| 151 | ;; FIXME: Just like byte-compile-macro-environment, we should have something | ||
| 152 | ;; like byte-compile-symbolprop-environment so as to handle these things | ||
| 153 | ;; cleanly without affecting the running Emacs. | ||
| 154 | `(eval-and-compile (put ',name 'gv-expander ,handler))) | ||
| 155 | 150 | ||
| 156 | ;;;###autoload | 151 | ;;;###autoload |
| 157 | (defun gv--defun-declaration (symbol name args handler &optional fix) | 152 | (defun gv--defun-declaration (symbol name args handler &optional fix) |
diff --git a/lisp/emacs-lisp/testcover.el b/lisp/emacs-lisp/testcover.el index 433ad38a147..17891fd6096 100644 --- a/lisp/emacs-lisp/testcover.el +++ b/lisp/emacs-lisp/testcover.el | |||
| @@ -463,7 +463,10 @@ binding `testcover-vector' to the code-coverage vector for TESTCOVER-SYM | |||
| 463 | (cond | 463 | (cond |
| 464 | ((eq (aref testcover-vector idx) 'unknown) | 464 | ((eq (aref testcover-vector idx) 'unknown) |
| 465 | (aset testcover-vector idx val)) | 465 | (aset testcover-vector idx val)) |
| 466 | ((not (equal (aref testcover-vector idx) val)) | 466 | ((not (condition-case () |
| 467 | (equal (aref testcover-vector idx) val) | ||
| 468 | ;; TODO: Actually check circular lists for equality. | ||
| 469 | (circular-list nil))) | ||
| 467 | (aset testcover-vector idx 'ok-coverage))) | 470 | (aset testcover-vector idx 'ok-coverage))) |
| 468 | val) | 471 | val) |
| 469 | 472 | ||
| @@ -475,7 +478,10 @@ same value during coverage testing." | |||
| 475 | ((eq (aref testcover-vector idx) '1value) | 478 | ((eq (aref testcover-vector idx) '1value) |
| 476 | (aset testcover-vector idx (cons '1value val))) | 479 | (aset testcover-vector idx (cons '1value val))) |
| 477 | ((not (and (eq (car-safe (aref testcover-vector idx)) '1value) | 480 | ((not (and (eq (car-safe (aref testcover-vector idx)) '1value) |
| 478 | (equal (cdr (aref testcover-vector idx)) val))) | 481 | (condition-case () |
| 482 | (equal (cdr (aref testcover-vector idx)) val) | ||
| 483 | ;; TODO: Actually check circular lists for equality. | ||
| 484 | (circular-list nil)))) | ||
| 479 | (error "Value of form marked with `1value' does vary: %s" val))) | 485 | (error "Value of form marked with `1value' does vary: %s" val))) |
| 480 | val) | 486 | val) |
| 481 | 487 | ||
| @@ -1987,6 +1987,10 @@ This is the last value stored with `(put SYMBOL PROPNAME VALUE)'. */) | |||
| 1987 | (Lisp_Object symbol, Lisp_Object propname) | 1987 | (Lisp_Object symbol, Lisp_Object propname) |
| 1988 | { | 1988 | { |
| 1989 | CHECK_SYMBOL (symbol); | 1989 | CHECK_SYMBOL (symbol); |
| 1990 | Lisp_Object propval = Fplist_get (CDR (Fassq (symbol, Voverriding_plist_environment)), | ||
| 1991 | propname); | ||
| 1992 | if (!NILP (propval)) | ||
| 1993 | return propval; | ||
| 1990 | return Fplist_get (XSYMBOL (symbol)->plist, propname); | 1994 | return Fplist_get (XSYMBOL (symbol)->plist, propname); |
| 1991 | } | 1995 | } |
| 1992 | 1996 | ||
| @@ -5163,6 +5167,13 @@ syms_of_fns (void) | |||
| 5163 | DEFSYM (Qcursor_in_echo_area, "cursor-in-echo-area"); | 5167 | DEFSYM (Qcursor_in_echo_area, "cursor-in-echo-area"); |
| 5164 | DEFSYM (Qwidget_type, "widget-type"); | 5168 | DEFSYM (Qwidget_type, "widget-type"); |
| 5165 | 5169 | ||
| 5170 | DEFVAR_LISP ("overriding-plist-environment", Voverriding_plist_environment, | ||
| 5171 | doc: /* An alist overrides the plists of the symbols which it lists. | ||
| 5172 | Used by the byte-compiler to apply `define-symbol-prop' during | ||
| 5173 | compilation. */); | ||
| 5174 | Voverriding_plist_environment = Qnil; | ||
| 5175 | DEFSYM (Qoverriding_plist_environment, "overriding-plist-environment"); | ||
| 5176 | |||
| 5166 | staticpro (&string_char_byte_cache_string); | 5177 | staticpro (&string_char_byte_cache_string); |
| 5167 | string_char_byte_cache_string = Qnil; | 5178 | string_char_byte_cache_string = Qnil; |
| 5168 | 5179 | ||
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)." | |||
| 545 | This functionality has been obsolete for more than 10 years already | 545 | This functionality has been obsolete for more than 10 years already |
| 546 | and will be removed soon. See (elisp)Backquote in the manual."))))))) | 546 | and 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. |