unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#29025: Option to run ERT in quiet mode
@ 2017-10-27  9:51 Paul Pogonyshev
  2017-10-27 12:03 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Pogonyshev @ 2017-10-27  9:51 UTC (permalink / raw)
  To: 29025

[-- Attachment #1: Type: text/plain, Size: 532 bytes --]

Severity: wishlist
Tags: patch

When running ERT from command-line with (ert-run-tests-batch ...), it
prints lots of lines for passed tests. The attached patch adds
variable `ert-quiet' that lets you omit such non-important lines:

    (let ((ert-quiet t)) (ert-run-tests-batch ...))

Of course, default is nil, so there is no change for existing
invocations. It is fully backward compatible. Users don't have to
check Emacs version prior to binding this variable: on older version
there will be no effect, but ERT will work.

Paul

[-- Attachment #2: 0001-Add-ert-quiet-variable.patch --]
[-- Type: text/x-patch, Size: 3175 bytes --]

From 689a0faf794908992a0a9a8aebc3a0002ec03508 Mon Sep 17 00:00:00 2001
From: Paul Pogonyshev <pogonyshev@gmail.com>
Date: Fri, 27 Oct 2017 11:35:40 +0200
Subject: [PATCH] Add `ert-quiet' variable.

* ert.el (ert-quiet): New variable.
(ert-run-tests-batch): When `ert-quiet' is non-nil, don't
print non-important information.
---
 lisp/emacs-lisp/ert.el | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el
index 3a3979e81f..1d69af8063 100644
--- a/lisp/emacs-lisp/ert.el
+++ b/lisp/emacs-lisp/ert.el
@@ -1333,6 +1333,9 @@ ert--insert-infos
 
 ;;; Running tests in batch mode.
 
+(defvar ert-quiet nil
+  "Non-nil makes ERT only print important information in batch mode.")
+
 ;;;###autoload
 (defun ert-run-tests-batch (&optional selector)
   "Run the tests specified by SELECTOR, printing results to the terminal.
@@ -1349,10 +1352,11 @@ ert-run-tests-batch
    (lambda (event-type &rest event-args)
      (cl-ecase event-type
        (run-started
-        (cl-destructuring-bind (stats) event-args
-          (message "Running %s tests (%s)"
-                   (length (ert--stats-tests stats))
-                   (ert--format-time-iso8601 (ert--stats-start-time stats)))))
+        (unless ert-quiet
+          (cl-destructuring-bind (stats) event-args
+            (message "Running %s tests (%s)"
+                     (length (ert--stats-tests stats))
+                     (ert--format-time-iso8601 (ert--stats-start-time stats))))))
        (run-ended
         (cl-destructuring-bind (stats abortedp) event-args
           (let ((unexpected (ert-stats-completed-unexpected stats))
@@ -1438,16 +1442,17 @@ ert-run-tests-batch
                         (ert-test-name test)))
               (ert-test-quit
                (message "Quit during %S" (ert-test-name test)))))
-          (let* ((max (prin1-to-string (length (ert--stats-tests stats))))
-                 (format-string (concat "%9s  %"
-                                        (prin1-to-string (length max))
-                                        "s/" max "  %S")))
-            (message format-string
-                     (ert-string-for-test-result result
-                                                 (ert-test-result-expected-p
-                                                  test result))
-                     (1+ (ert--stats-test-pos stats test))
-                     (ert-test-name test)))))))
+          (unless ert-quiet
+            (let* ((max (prin1-to-string (length (ert--stats-tests stats))))
+                   (format-string (concat "%9s  %"
+                                          (prin1-to-string (length max))
+                                          "s/" max "  %S")))
+              (message format-string
+                       (ert-string-for-test-result result
+                                                   (ert-test-result-expected-p
+                                                    test result))
+                       (1+ (ert--stats-test-pos stats test))
+                       (ert-test-name test))))))))
    nil))
 
 ;;;###autoload
-- 
2.14.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#29025: Option to run ERT in quiet mode
  2017-10-27  9:51 bug#29025: Option to run ERT in quiet mode Paul Pogonyshev
@ 2017-10-27 12:03 ` Eli Zaretskii
  2017-10-27 12:26   ` Paul Pogonyshev
  0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2017-10-27 12:03 UTC (permalink / raw)
  To: Paul Pogonyshev; +Cc: 29025

> From: Paul Pogonyshev <pogonyshev@gmail.com>
> Date: Fri, 27 Oct 2017 11:51:40 +0200
> 
> When running ERT from command-line with (ert-run-tests-batch ...), it
> prints lots of lines for passed tests. The attached patch adds
> variable `ert-quiet' that lets you omit such non-important lines:
> 
>     (let ((ert-quiet t)) (ert-run-tests-batch ...))
> 
> Of course, default is nil, so there is no change for existing
> invocations. It is fully backward compatible. Users don't have to
> check Emacs version prior to binding this variable: on older version
> there will be no effect, but ERT will work.

Thanks, but please also provide patches for the Texinfo manual and
NEWS.





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#29025: Option to run ERT in quiet mode
  2017-10-27 12:03 ` Eli Zaretskii
@ 2017-10-27 12:26   ` Paul Pogonyshev
  2017-10-28 10:51     ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Pogonyshev @ 2017-10-27 12:26 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 29025

[-- Attachment #1: Type: text/plain, Size: 820 bytes --]

Attached is the patch extended with requested changes.

Paul

On 27 October 2017 at 14:03, Eli Zaretskii <eliz@gnu.org> wrote:
>> From: Paul Pogonyshev <pogonyshev@gmail.com>
>> Date: Fri, 27 Oct 2017 11:51:40 +0200
>>
>> When running ERT from command-line with (ert-run-tests-batch ...), it
>> prints lots of lines for passed tests. The attached patch adds
>> variable `ert-quiet' that lets you omit such non-important lines:
>>
>>     (let ((ert-quiet t)) (ert-run-tests-batch ...))
>>
>> Of course, default is nil, so there is no change for existing
>> invocations. It is fully backward compatible. Users don't have to
>> check Emacs version prior to binding this variable: on older version
>> there will be no effect, but ERT will work.
>
> Thanks, but please also provide patches for the Texinfo manual and
> NEWS.

[-- Attachment #2: 0001-Add-ert-quiet-variable.patch --]
[-- Type: text/x-patch, Size: 4756 bytes --]

From 116b31d20b0a23a73f489d2773ea9c746adc1c60 Mon Sep 17 00:00:00 2001
From: Paul Pogonyshev <pogonyshev@gmail.com>
Date: Fri, 27 Oct 2017 14:21:59 +0200
Subject: [PATCH] Add `ert-quiet' variable.

* lisp/emacs-lisp/ert.el (ert-quiet): New variable.
(ert-run-tests-batch): When `ert-quiet' is non-nil, don't
print non-important information.
* doc/misc/ert.texi (Running Tests in Batch Mode): Document it.
---
 doc/misc/ert.texi      | 13 +++++++++++++
 etc/NEWS               |  5 +++++
 lisp/emacs-lisp/ert.el | 33 +++++++++++++++++++--------------
 3 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/doc/misc/ert.texi b/doc/misc/ert.texi
index 4a2c29dcb9..cdfba5701c 100644
--- a/doc/misc/ert.texi
+++ b/doc/misc/ert.texi
@@ -292,6 +292,19 @@ Running Tests in Batch Mode
 emacs -batch -l ert -f ert-summarize-tests-batch-and-exit output.log
 @end example
 
+By default, ERT in batch mode is quite verbose, printing a line with
+result after each test.  This gives you progress information: how many
+tests have been executed and how many there are.  However, in some
+cases this much output may be not wanted.  In this case, set
+@code{ert-quiet} variable to a non-nil value:
+
+@example
+emacs -batch -l ert -l my-tests.el \
+      --eval "(let ((ert-quiet t)) (ert-run-tests-batch-and-exit))"
+@end example
+
+In quiet mode ERT prints only unexpected results and summary.
+
 If ERT is not part of your Emacs distribution, you may need to use
 @code{-L /path/to/ert/} so that Emacs can find it.  You may need
 additional @code{-L} flags to ensure that @code{my-tests.el} and all the
diff --git a/etc/NEWS b/etc/NEWS
index ec52460f77..9c23cb20dd 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -84,6 +84,11 @@ by default.
 
 ** Gamegrid
 
+** ERT
+
+*** New variable 'ert-quiet' allows to make ERT output in batch mode
+less verbose by removing non-essential information.
+
 ---
 *** Gamegrid now determines its default glyph size based on display
 dimensions, instead of always using 16 pixels. As a result, Tetris,
diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el
index 3a3979e81f..1d69af8063 100644
--- a/lisp/emacs-lisp/ert.el
+++ b/lisp/emacs-lisp/ert.el
@@ -1333,6 +1333,9 @@ ert--insert-infos
 
 ;;; Running tests in batch mode.
 
+(defvar ert-quiet nil
+  "Non-nil makes ERT only print important information in batch mode.")
+
 ;;;###autoload
 (defun ert-run-tests-batch (&optional selector)
   "Run the tests specified by SELECTOR, printing results to the terminal.
@@ -1349,10 +1352,11 @@ ert-run-tests-batch
    (lambda (event-type &rest event-args)
      (cl-ecase event-type
        (run-started
-        (cl-destructuring-bind (stats) event-args
-          (message "Running %s tests (%s)"
-                   (length (ert--stats-tests stats))
-                   (ert--format-time-iso8601 (ert--stats-start-time stats)))))
+        (unless ert-quiet
+          (cl-destructuring-bind (stats) event-args
+            (message "Running %s tests (%s)"
+                     (length (ert--stats-tests stats))
+                     (ert--format-time-iso8601 (ert--stats-start-time stats))))))
        (run-ended
         (cl-destructuring-bind (stats abortedp) event-args
           (let ((unexpected (ert-stats-completed-unexpected stats))
@@ -1438,16 +1442,17 @@ ert-run-tests-batch
                         (ert-test-name test)))
               (ert-test-quit
                (message "Quit during %S" (ert-test-name test)))))
-          (let* ((max (prin1-to-string (length (ert--stats-tests stats))))
-                 (format-string (concat "%9s  %"
-                                        (prin1-to-string (length max))
-                                        "s/" max "  %S")))
-            (message format-string
-                     (ert-string-for-test-result result
-                                                 (ert-test-result-expected-p
-                                                  test result))
-                     (1+ (ert--stats-test-pos stats test))
-                     (ert-test-name test)))))))
+          (unless ert-quiet
+            (let* ((max (prin1-to-string (length (ert--stats-tests stats))))
+                   (format-string (concat "%9s  %"
+                                          (prin1-to-string (length max))
+                                          "s/" max "  %S")))
+              (message format-string
+                       (ert-string-for-test-result result
+                                                   (ert-test-result-expected-p
+                                                    test result))
+                       (1+ (ert--stats-test-pos stats test))
+                       (ert-test-name test))))))))
    nil))
 
 ;;;###autoload
-- 
2.14.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#29025: Option to run ERT in quiet mode
  2017-10-27 12:26   ` Paul Pogonyshev
@ 2017-10-28 10:51     ` Eli Zaretskii
  0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2017-10-28 10:51 UTC (permalink / raw)
  To: Paul Pogonyshev; +Cc: 29025-done

> From: Paul Pogonyshev <pogonyshev@gmail.com>
> Date: Fri, 27 Oct 2017 14:26:38 +0200
> Cc: 29025@debbugs.gnu.org
> 
> Attached is the patch extended with requested changes.

Thanks, pushed to the master branch.





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-10-28 10:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-27  9:51 bug#29025: Option to run ERT in quiet mode Paul Pogonyshev
2017-10-27 12:03 ` Eli Zaretskii
2017-10-27 12:26   ` Paul Pogonyshev
2017-10-28 10:51     ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).