aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNoam Postavsky2016-08-21 22:58:37 -0400
committerNoam Postavsky2016-12-06 22:20:23 -0500
commit58e418d2ceb82501f03d9c3316fd0a46faf7f0eb (patch)
tree699bd17367bc6fa8e8f244be5d040195250ff9ad
parent5202cb56add070eb7d9fe8015f2a4edd57a628f9 (diff)
downloademacs-58e418d2ceb82501f03d9c3316fd0a46faf7f0eb.tar.gz
emacs-58e418d2ceb82501f03d9c3316fd0a46faf7f0eb.zip
Fix ert-tests when running compiled
* test/lisp/emacs-lisp/ert-tests.el (ert-test-deftest): Don't test for specific macroexpansion, just check result of evaluation. (ert-test-record-backtrace): Don't hardcode representation of closure in expected backtrace, this lets the test succeed even when the test code is compiled. * lisp/emacs-lisp/ert.el (ert--expand-should-1): Also pass `byte-compile-macro-environment' to `macroexpand', this allows the `should' macro to properly handle macroexpansion of macros that were defined in the same file when it's being compiled (Bug #17851).
-rw-r--r--lisp/emacs-lisp/ert.el11
-rw-r--r--test/lisp/emacs-lisp/ert-tests.el68
2 files changed, 29 insertions, 50 deletions
diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el
index 0308c9cd37c..89f83ddff43 100644
--- a/lisp/emacs-lisp/ert.el
+++ b/lisp/emacs-lisp/ert.el
@@ -276,11 +276,12 @@ DATA is displayed to the user and should state the reason for skipping."
276(defun ert--expand-should-1 (whole form inner-expander) 276(defun ert--expand-should-1 (whole form inner-expander)
277 "Helper function for the `should' macro and its variants." 277 "Helper function for the `should' macro and its variants."
278 (let ((form 278 (let ((form
279 (macroexpand form (cond 279 (macroexpand form (append byte-compile-macro-environment
280 ((boundp 'macroexpand-all-environment) 280 (cond
281 macroexpand-all-environment) 281 ((boundp 'macroexpand-all-environment)
282 ((boundp 'cl-macro-environment) 282 macroexpand-all-environment)
283 cl-macro-environment))))) 283 ((boundp 'cl-macro-environment)
284 cl-macro-environment))))))
284 (cond 285 (cond
285 ((or (atom form) (ert--special-operator-p (car form))) 286 ((or (atom form) (ert--special-operator-p (car form)))
286 (let ((value (cl-gensym "value-"))) 287 (let ((value (cl-gensym "value-")))
diff --git a/test/lisp/emacs-lisp/ert-tests.el b/test/lisp/emacs-lisp/ert-tests.el
index 5d3675553d7..83fddd15165 100644
--- a/test/lisp/emacs-lisp/ert-tests.el
+++ b/test/lisp/emacs-lisp/ert-tests.el
@@ -344,53 +344,35 @@ This macro is used to test if macroexpansion in `should' works."
344 ((error) 344 ((error)
345 (should (equal actual-condition expected-condition))))))) 345 (should (equal actual-condition expected-condition)))))))
346 346
347(defun ert-test--which-file ()
348 "Dummy function to help test `symbol-file' for tests.")
349
347(ert-deftest ert-test-deftest () 350(ert-deftest ert-test-deftest ()
348 ;; FIXME: These tests don't look very good. What is their intent, i.e. what 351 (ert-deftest ert-test-abc () "foo" :tags '(bar))
349 ;; are they really testing? The precise generated code shouldn't matter, so 352 (let ((abc (ert-get-test 'ert-test-abc)))
350 ;; we should either test the behavior of the code, or else try to express the 353 (should (equal (ert-test-tags abc) '(bar)))
351 ;; kind of efficiency guarantees we're looking for. 354 (should (equal (ert-test-documentation abc) "foo")))
352 (should (equal (macroexpand '(ert-deftest abc () "foo" :tags '(bar))) 355 (should (equal (symbol-file 'ert-test-deftest 'ert-deftest)
353 '(progn 356 (symbol-file 'ert-test--which-file 'defun)))
354 (ert-set-test 'abc 357
355 (progn 358 (ert-deftest ert-test-def () :expected-result ':passed)
356 "Constructor for objects of type `ert-test'." 359 (let ((def (ert-get-test 'ert-test-def)))
357 (vector 'cl-struct-ert-test 'abc "foo" 360 (should (equal (ert-test-expected-result-type def) :passed)))
358 #'(lambda nil)
359 nil ':passed
360 '(bar))))
361 (setq current-load-list
362 (cons
363 '(ert-deftest . abc)
364 current-load-list))
365 'abc)))
366 (should (equal (macroexpand '(ert-deftest def ()
367 :expected-result ':passed))
368 '(progn
369 (ert-set-test 'def
370 (progn
371 "Constructor for objects of type `ert-test'."
372 (vector 'cl-struct-ert-test 'def nil
373 #'(lambda nil)
374 nil ':passed 'nil)))
375 (setq current-load-list
376 (cons
377 '(ert-deftest . def)
378 current-load-list))
379 'def)))
380 ;; :documentation keyword is forbidden 361 ;; :documentation keyword is forbidden
381 (should-error (macroexpand '(ert-deftest ghi () 362 (should-error (macroexpand '(ert-deftest ghi ()
382 :documentation "foo")))) 363 :documentation "foo"))))
383 364
384(ert-deftest ert-test-record-backtrace () 365(ert-deftest ert-test-record-backtrace ()
385 (let ((test (make-ert-test :body (lambda () (ert-fail "foo"))))) 366 (let* ((test-body (lambda () (ert-fail "foo")))
386 (let ((result (ert-run-test test))) 367 (test (make-ert-test :body test-body))
387 (should (ert-test-failed-p result)) 368 (result (ert-run-test test)))
388 (with-temp-buffer 369 (should (ert-test-failed-p result))
389 (ert--print-backtrace (ert-test-failed-backtrace result)) 370 (with-temp-buffer
390 (goto-char (point-min)) 371 (ert--print-backtrace (ert-test-failed-backtrace result))
391 (end-of-line) 372 (goto-char (point-min))
392 (let ((first-line (buffer-substring-no-properties (point-min) (point)))) 373 (end-of-line)
393 (should (equal first-line " (closure (ert--test-body-was-run t) nil (ert-fail \"foo\"))()"))))))) 374 (let ((first-line (buffer-substring-no-properties (point-min) (point))))
375 (should (equal first-line (format " %S()" test-body)))))))
394 376
395(ert-deftest ert-test-messages () 377(ert-deftest ert-test-messages ()
396 :tags '(:causes-redisplay) 378 :tags '(:causes-redisplay)
@@ -837,7 +819,3 @@ This macro is used to test if macroexpansion in `should' works."
837(provide 'ert-tests) 819(provide 'ert-tests)
838 820
839;;; ert-tests.el ends here 821;;; ert-tests.el ends here
840
841;; Local Variables:
842;; no-byte-compile: t
843;; End: