From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: npostavs@users.sourceforge.net Newsgroups: gmane.emacs.bugs Subject: bug#17851: Some ert tests fail when run compiled Date: Mon, 22 Aug 2016 21:31:49 -0400 Message-ID: <87vaystgmy.fsf@users.sourceforge.net> References: <3etx78b4bo.fsf@fencepost.gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1471915942 25368 195.159.176.226 (23 Aug 2016 01:32:22 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 23 Aug 2016 01:32:22 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) Cc: 17851@debbugs.gnu.org To: Glenn Morris Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Aug 23 03:32:18 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bc0Zd-0006JK-Sy for geb-bug-gnu-emacs@m.gmane.org; Tue, 23 Aug 2016 03:32:18 +0200 Original-Received: from localhost ([::1]:43891 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bc0Zb-0007x9-7A for geb-bug-gnu-emacs@m.gmane.org; Mon, 22 Aug 2016 21:32:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35331) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bc0ZU-0007vb-4s for bug-gnu-emacs@gnu.org; Mon, 22 Aug 2016 21:32:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bc0ZO-0001yc-2b for bug-gnu-emacs@gnu.org; Mon, 22 Aug 2016 21:32:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:39575) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bc0ZN-0001yY-V4 for bug-gnu-emacs@gnu.org; Mon, 22 Aug 2016 21:32:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bc0ZN-000295-Rp for bug-gnu-emacs@gnu.org; Mon, 22 Aug 2016 21:32:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: npostavs@users.sourceforge.net Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 23 Aug 2016 01:32:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 17851 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 17851-submit@debbugs.gnu.org id=B17851.14719159037799 (code B ref 17851); Tue, 23 Aug 2016 01:32:01 +0000 Original-Received: (at 17851) by debbugs.gnu.org; 23 Aug 2016 01:31:43 +0000 Original-Received: from localhost ([127.0.0.1]:37287 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bc0Z4-00021F-Hn for submit@debbugs.gnu.org; Mon, 22 Aug 2016 21:31:42 -0400 Original-Received: from mail-it0-f45.google.com ([209.85.214.45]:36478) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bc0Z3-0001vC-Cs; Mon, 22 Aug 2016 21:31:41 -0400 Original-Received: by mail-it0-f45.google.com with SMTP id e63so121118932ith.1; Mon, 22 Aug 2016 18:31:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=oKKmwr9wUVxMWD0U3s6/UiGPgQlQrseAnCSXXjFhTw4=; b=URAv+LURiHNPCTOWFqfvWrhQglzC0TI6AJKYNBKpEx7VTOaX/leKcCZjXsmuSmuxx8 fzwsA/2FBuHx/Nkhpy77FNlt4lZoH6qtRKapKq3euNGh7AFj887q2c0+Tv/QA0JKVML9 acw2aTw9EDIuko3lHuVxjFdIPgOWmntQlqB1p7jXGM0ihjfpm4v0zXVcKW+7APveXwq9 y7Ew+qU1Hye70xK5Qo9N5Dx7lYvIBxWSN09mzFe6aP5cVckKwOMkl4DQmQ2XApSdOzNN SPUehbaIDwM8bPU+rqKTfVjLGAwcZF2WquysWTQK+76q0e2IEGmt6jZNNmAP/FrbU4Ur ZPSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=oKKmwr9wUVxMWD0U3s6/UiGPgQlQrseAnCSXXjFhTw4=; b=CNVSbsnhpkNBOvvPFLx6v5kHWnMu1LKznnnLiAAoBTII+3Rrf/sJY26dSzvkCGErY9 Tvq/b+wLE2ZvpGkuzOZI9m2l0Xh2J+aEneUEJ9KR+T67v/woO1KrEp6lK5EVYuNSU7T3 RlnU6Neq+vNkshPMwOGT+cAzKne36qLfY2P1IhM2uKK1bFsmQlBXrSU8/wi7YYPKeFgr spXlsP5jP5k3xiXyGmyc8JfDns/OoLQ1KcNW19oHos73Jh+A7uWLgAkkXIKF4uOommkA 1eyAAIBEO6rGm6ObWgdkQQd3EmI7EAYoqF4Bn2riomxJucnI+xHW0DDmF/6/lil6XZYH DphA== X-Gm-Message-State: AEkoout/Pr2SPiABELNNa5hzWPvqSKS+RDpaKDhabN9D/0jDedP701hvo482KIXTZY34Qg== X-Received: by 10.107.62.68 with SMTP id l65mr9954438ioa.185.1471915895805; Mon, 22 Aug 2016 18:31:35 -0700 (PDT) Original-Received: from zony ([45.2.7.130]) by smtp.googlemail.com with ESMTPSA id j12sm567494ioi.36.2016.08.22.18.31.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 Aug 2016 18:31:34 -0700 (PDT) In-Reply-To: <3etx78b4bo.fsf@fencepost.gnu.org> (Glenn Morris's message of "Thu, 26 Jun 2014 01:57:47 -0400") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:122529 Archived-At: --=-=-= Content-Type: text/plain tags 17851 patch quit Glenn Morris writes: > The following tests fail when run from a compiled file ert-tests.elc: > > ert-test-record-backtrace > ert-test-should-failure-debugging > > This was never apparent before because even though the files in > test/automated were compiled, the tests were always run from the > uncompiled file. > > I'll simply add no-byte-compile to this file for now. 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): --=-=-= Content-Type: text/plain Content-Disposition: inline; filename=v1-0001-Fix-ert-tests-when-running-compiled.patch Content-Description: patch >From a943e65f7ed09b843d99bcb93aa4c47ec1815276 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sun, 21 Aug 2016 22:58:37 -0400 Subject: [PATCH v1] 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..38d6f65 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--whichfile '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.2 --=-=-=--