From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Julian Scheid via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#47071: 28.0.50; Show ERT failure reason in batch mode Date: Thu, 11 Mar 2021 10:42:19 +0000 Message-ID: Reply-To: Julian Scheid Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20347"; mail-complaints-to="usenet@ciao.gmane.io" To: 47071@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Mar 11 16:54:44 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lKNe8-0005Ax-1i for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 11 Mar 2021 16:54:44 +0100 Original-Received: from localhost ([::1]:52376 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lKNe6-0007UA-UG for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 11 Mar 2021 10:54:43 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51232) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lKNAR-0006xN-77 for bug-gnu-emacs@gnu.org; Thu, 11 Mar 2021 10:24:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:43106) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lKNAQ-0006Nn-NV for bug-gnu-emacs@gnu.org; Thu, 11 Mar 2021 10:24:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lKNAQ-0002Ed-HO for bug-gnu-emacs@gnu.org; Thu, 11 Mar 2021 10:24:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Julian Scheid Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 11 Mar 2021 15:24:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 47071 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16154762028522 (code B ref -1); Thu, 11 Mar 2021 15:24:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 11 Mar 2021 15:23:22 +0000 Original-Received: from localhost ([127.0.0.1]:54650 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lKN9l-0002DN-Bt for submit@debbugs.gnu.org; Thu, 11 Mar 2021 10:23:22 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:36662) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lKIlx-0007LC-NC for submit@debbugs.gnu.org; Thu, 11 Mar 2021 05:42:30 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49856) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lKIlx-0006u7-EI for bug-gnu-emacs@gnu.org; Thu, 11 Mar 2021 05:42:29 -0500 Original-Received: from mail-40134.protonmail.ch ([185.70.40.134]:11251) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lKIlu-0002lp-PG for bug-gnu-emacs@gnu.org; Thu, 11 Mar 2021 05:42:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1615459343; bh=2VbFHyhrJ7DBJ5zLfJYSflqbpimhVUfkBUZ6WTFhSdU=; h=Date:To:From:Reply-To:Subject:From; b=R0mJopsnQFOja7X4PnxqAt/KiFrArRjjOMMd73La5s6lzdOeQOXj9+wn96hpC+/WH pSPIOEjUrGAFrl1oCm+WFnwI0lV810b1KaNyz2mFMTg7GaL0GddznqCor5Zp+0ageY GDJBzWIqKhHuPiMWSLmbIKuJVKi0xxoiEhXDEi6Q= Received-SPF: pass client-ip=185.70.40.134; envelope-from=jscheid@protonmail.com; helo=mail-40134.protonmail.ch X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 11 Mar 2021 10:23:19 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" X-ACL-Warn: , Julian Scheid Xref: news.gmane.io gmane.emacs.bugs:202067 Archived-At: Severity: normal Tags: patch `ert-fail' and `ert-skip' both require an argument described as "[data that] is displayed to the user and should state the reason of the failure [or the reason for skipping]." The data is only displayed in interactive mode as a side-effect however, not in batch mode. I think it's useful to see the failure or skip reason in batch mode as well, which is why I would like to suggest the following change. (I've borrowed `print-level' etc. from other parts of ERT code but don't have a strong opinion on it. I'd imagine that most of the time people would just pass in a short string anyway. That's what a quick grep of Emacs code seems to point to as well.) >From 053abfe6e9a35a76b7f0af866a6336fb35d959f9 Mon Sep 17 00:00:00 2001 From: Julian Scheid Date: Thu, 11 Mar 2021 22:49:11 +1300 Subject: [PATCH] Output test failure or skip reason in batch mode * lisp/emacs-lisp/ert.el (ert-reason-for-test-result): New function. (ert-run-tests-batch): Output failure or skip reason. --- lisp/emacs-lisp/ert.el | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el index e91ec0af44..05edbb6fd1 100644 --- a/lisp/emacs-lisp/ert.el +++ b/lisp/emacs-lisp/ert.el @@ -1279,6 +1279,23 @@ ert-string-for-test-result (ert-test-quit '("quit" "QUIT"))))) (elt s (if expectedp 0 1)))) +(defun ert-reason-for-test-result (result) + "Return the reason given for RESULT, as a string. + +The reason is the argument given when invoking `ert-fail' or `ert-skip'. +It is output using `prin1' prefixed by two spaces. + +If no reason was given, or for a successful RESULT, return the +empty string." + (let ((reason + (and + (ert-test-result-with-condition-p result) + (cadr (ert-test-result-with-condition-condition result)))) + (print-escape-newlines t) + (print-level 6) + (print-length 10)) + (if reason (format " %S" reason) ""))) + (defun ert--pp-with-indentation-and-newline (object) "Pretty-print OBJECT, indenting it to the current column of point. Ensures a final newline is inserted." @@ -1369,18 +1386,20 @@ ert-run-tests-batch (cl-loop for test across (ert--stats-tests stats) for result =3D (ert-test-most-recent-result test) d= o (when (not (ert-test-result-expected-p test result)= ) - (message "%9s %S" + (message "%9s %S%s" (ert-string-for-test-result result nil) - (ert-test-name test)))) + (ert-test-name test) + (ert-reason-for-test-result result)))) (message "%s" "")) (unless (zerop skipped) (message "%s skipped results:" skipped) (cl-loop for test across (ert--stats-tests stats) for result =3D (ert-test-most-recent-result test) d= o (when (ert-test-result-type-p result :skipped) - (message "%9s %S" + (message "%9s %S%s" (ert-string-for-test-result result nil) - (ert-test-name test)))) + (ert-test-name test) + (ert-reason-for-test-result result)))) (message "%s" ""))))) (test-started ) -- 2.30.2