From: npostavs@users.sourceforge.net
To: Glenn Morris <rgm@gnu.org>
Cc: 17851@debbugs.gnu.org
Subject: bug#17851: Some ert tests fail when run compiled
Date: Wed, 07 Sep 2016 21:15:48 -0400 [thread overview]
Message-ID: <87r38v19a3.fsf@users.sourceforge.net> (raw)
In-Reply-To: <87vaystgmy.fsf@users.sourceforge.net> (npostavs@users.sourceforge.net's message of "Mon, 22 Aug 2016 21:31:49 -0400")
[-- Attachment #1: Type: text/plain, Size: 358 bytes --]
npostavs@users.sourceforge.net writes:
>
> First one is an overly implementation specific test, second seems to be
> a bug in the `should' macro. Here's a patch to fix both (and also
> another nearby test that was too implementation specific):
Had some minor problems in the test (I must have run only an
intermediate version before), here's a new patch.
[-- Attachment #2: patch v2 --]
[-- Type: text/plain, Size: 5510 bytes --]
From 8ee7db328a275710fd9999757b5578514a83be6c Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Sun, 21 Aug 2016 22:58:37 -0400
Subject: [PATCH v2] 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 (Bug #17851).
* 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).
---
lisp/emacs-lisp/ert.el | 11 ++++---
test/lisp/emacs-lisp/ert-tests.el | 68 +++++++++++++--------------------------
2 files changed, 29 insertions(+), 50 deletions(-)
diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el
index 0308c9c..89f83dd 100644
--- a/lisp/emacs-lisp/ert.el
+++ b/lisp/emacs-lisp/ert.el
@@ -276,11 +276,12 @@ ert--special-operator-p
(defun ert--expand-should-1 (whole form inner-expander)
"Helper function for the `should' macro and its variants."
(let ((form
- (macroexpand form (cond
- ((boundp 'macroexpand-all-environment)
- macroexpand-all-environment)
- ((boundp 'cl-macro-environment)
- cl-macro-environment)))))
+ (macroexpand form (append byte-compile-macro-environment
+ (cond
+ ((boundp 'macroexpand-all-environment)
+ macroexpand-all-environment)
+ ((boundp 'cl-macro-environment)
+ cl-macro-environment))))))
(cond
((or (atom form) (ert--special-operator-p (car form)))
(let ((value (cl-gensym "value-")))
diff --git a/test/lisp/emacs-lisp/ert-tests.el b/test/lisp/emacs-lisp/ert-tests.el
index 5d36755..83fddd1 100644
--- a/test/lisp/emacs-lisp/ert-tests.el
+++ b/test/lisp/emacs-lisp/ert-tests.el
@@ -344,53 +344,35 @@ ert--test-my-list
((error)
(should (equal actual-condition expected-condition)))))))
+(defun ert-test--which-file ()
+ "Dummy function to help test `symbol-file' for tests.")
+
(ert-deftest ert-test-deftest ()
- ;; FIXME: These tests don't look very good. What is their intent, i.e. what
- ;; are they really testing? The precise generated code shouldn't matter, so
- ;; we should either test the behavior of the code, or else try to express the
- ;; kind of efficiency guarantees we're looking for.
- (should (equal (macroexpand '(ert-deftest abc () "foo" :tags '(bar)))
- '(progn
- (ert-set-test 'abc
- (progn
- "Constructor for objects of type `ert-test'."
- (vector 'cl-struct-ert-test 'abc "foo"
- #'(lambda nil)
- nil ':passed
- '(bar))))
- (setq current-load-list
- (cons
- '(ert-deftest . abc)
- current-load-list))
- 'abc)))
- (should (equal (macroexpand '(ert-deftest def ()
- :expected-result ':passed))
- '(progn
- (ert-set-test 'def
- (progn
- "Constructor for objects of type `ert-test'."
- (vector 'cl-struct-ert-test 'def nil
- #'(lambda nil)
- nil ':passed 'nil)))
- (setq current-load-list
- (cons
- '(ert-deftest . def)
- current-load-list))
- 'def)))
+ (ert-deftest ert-test-abc () "foo" :tags '(bar))
+ (let ((abc (ert-get-test 'ert-test-abc)))
+ (should (equal (ert-test-tags abc) '(bar)))
+ (should (equal (ert-test-documentation abc) "foo")))
+ (should (equal (symbol-file 'ert-test-deftest 'ert-deftest)
+ (symbol-file 'ert-test--which-file 'defun)))
+
+ (ert-deftest ert-test-def () :expected-result ':passed)
+ (let ((def (ert-get-test 'ert-test-def)))
+ (should (equal (ert-test-expected-result-type def) :passed)))
;; :documentation keyword is forbidden
(should-error (macroexpand '(ert-deftest ghi ()
:documentation "foo"))))
(ert-deftest ert-test-record-backtrace ()
- (let ((test (make-ert-test :body (lambda () (ert-fail "foo")))))
- (let ((result (ert-run-test test)))
- (should (ert-test-failed-p result))
- (with-temp-buffer
- (ert--print-backtrace (ert-test-failed-backtrace result))
- (goto-char (point-min))
- (end-of-line)
- (let ((first-line (buffer-substring-no-properties (point-min) (point))))
- (should (equal first-line " (closure (ert--test-body-was-run t) nil (ert-fail \"foo\"))()")))))))
+ (let* ((test-body (lambda () (ert-fail "foo")))
+ (test (make-ert-test :body test-body))
+ (result (ert-run-test test)))
+ (should (ert-test-failed-p result))
+ (with-temp-buffer
+ (ert--print-backtrace (ert-test-failed-backtrace result))
+ (goto-char (point-min))
+ (end-of-line)
+ (let ((first-line (buffer-substring-no-properties (point-min) (point))))
+ (should (equal first-line (format " %S()" test-body)))))))
(ert-deftest ert-test-messages ()
:tags '(:causes-redisplay)
@@ -837,7 +819,3 @@ ert--test-my-list
(provide 'ert-tests)
;;; ert-tests.el ends here
-
-;; Local Variables:
-;; no-byte-compile: t
-;; End:
--
2.9.3
next prev parent reply other threads:[~2016-09-08 1:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-26 5:57 bug#17851: Some ert tests fail when run compiled Glenn Morris
2016-08-23 1:31 ` npostavs
2016-09-08 1:15 ` npostavs [this message]
2016-12-07 3:32 ` npostavs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r38v19a3.fsf@users.sourceforge.net \
--to=npostavs@users.sourceforge.net \
--cc=17851@debbugs.gnu.org \
--cc=rgm@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.