unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
To: 45948@debbugs.gnu.org
Subject: [bug#45948] [PATCH 1/5] build: test-driver.scm Make output redirection optional.
Date: Mon, 18 Jan 2021 01:24:56 -0500	[thread overview]
Message-ID: <20210118062501.27022-1-maxim.cournoyer@gmail.com> (raw)
In-Reply-To: <20210118061853.26808-1-maxim.cournoyer@gmail.com>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=yes, Size: 3978 bytes --]

This makes it easier (and less surprising) for users to experiment with the
custom Scheme test driver directly.  The behavior is unchanged from Automake's
point of view.

* build-aux/test-driver.scm (main): Make the --log-file and --trs-file
arguments optional.  Only open, redirect and close a port to a log file when
the --log-file option is provided.  Only open and close a port to a trs file
when the --trs-file option is provided.
(test-runner-gnu): Set OUT-PORT parameter default value to the current output
port.  Set the TRS-PORT parameter default value to a void port.  Update doc.
---
 build-aux/test-driver.scm | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/build-aux/test-driver.scm b/build-aux/test-driver.scm
index 52af1e9be7..b7622c3ed2 100644
--- a/build-aux/test-driver.scm
+++ b/build-aux/test-driver.scm
@@ -1,8 +1,9 @@
 ;;;; test-driver.scm - Guile test driver for Automake testsuite harness
 
-(define script-version "2017-03-22.13") ;UTC
+(define script-version "2021-01-18.06") ;UTC
 
 ;;; Copyright © 2015, 2016 Mathieu Lirzin <mthl@gnu.org>
+;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;;
 ;;; This program is free software; you can redistribute it and/or modify it
 ;;; under the terms of the GNU General Public License as published by
@@ -75,11 +76,14 @@ The '--test-name', '--log-file' and '--trs-file' options are mandatory.\n"))
                        "^[[m")          ;no color
         result)))
 
-(define* (test-runner-gnu test-name #:key color? brief? out-port trs-port)
+(define* (test-runner-gnu test-name #:key color? brief?
+                          (out-port (current-output-port))
+                          (trs-port (%make-void-port "w")))
   "Return an custom SRFI-64 test runner.  TEST-NAME is a string specifying the
 file name of the current the test.  COLOR? specifies whether to use colors,
-and BRIEF?, well, you know.  OUT-PORT and TRS-PORT must be output ports.  The
-current output port is supposed to be redirected to a '.log' file."
+and BRIEF?, well, you know.  OUT-PORT and TRS-PORT must be output ports.
+OUT-PORT defaults to the current output port, while TRS-PORT defaults to a
+void port, which means no TRS output is logged."
 
   (define (test-on-test-begin-gnu runner)
     ;; Procedure called at the start of an individual test case, before the
@@ -156,20 +160,22 @@ current output port is supposed to be redirected to a '.log' file."
      ((option 'help #f)    (show-help))
      ((option 'version #f) (format #t "test-driver.scm ~A" script-version))
      (else
-      (let ((log (open-file (option 'log-file "") "w0"))
-            (trs (open-file (option 'trs-file "") "wl"))
-            (out (duplicate-port (current-output-port) "wl")))
-        (redirect-port log (current-output-port))
-        (redirect-port log (current-warning-port))
-        (redirect-port log (current-error-port))
+      (let ((log (and=> (option 'log-file #f) (cut open-file <> "w0")))
+            (trs (and=> (option 'trs-file #f) (cut open-file <> "wl")))
+            (out (duplicate-port (current-output-port) "wl"))
+            (test-name (option 'test-name #f)))
+        (when log
+          (redirect-port log (current-output-port))
+          (redirect-port log (current-warning-port))
+          (redirect-port log (current-error-port)))
         (test-with-runner
-            (test-runner-gnu (option 'test-name #f)
+            (test-runner-gnu test-name
                              #:color? (option->boolean opts 'color-tests)
                              #:brief? (option->boolean opts 'brief)
                              #:out-port out #:trs-port trs)
-          (load-from-path (option 'test-name #f)))
-        (close-port log)
-        (close-port trs)
+          (load-from-path test-name))
+        (and=> log close-port)
+        (and=> trs close-port)
         (close-port out))))
     (exit 0)))
 
-- 
2.29.2





  reply	other threads:[~2021-01-18  6:27 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-18  6:18 [bug#45948] [PATCH 0/5] Improvements to the Automake SRFI 64 test driver Maxim Cournoyer
2021-01-18  6:24 ` Maxim Cournoyer [this message]
2021-01-18  6:24   ` [bug#45948] [PATCH 2/5] build: test-driver.scm: Define the --test-name option as required Maxim Cournoyer
2021-01-18 14:37     ` [bug#45948] [PATCH 0/5] Improvements to the Automake SRFI 64 test driver Maxim Cournoyer
2021-01-18  6:24   ` [bug#45948] [PATCH 3/5] build: test-driver.scm: Enable colored test results by default Maxim Cournoyer
2021-01-30 21:39     ` [bug#45948] [PATCH 0/5] Improvements to the Automake SRFI 64 test driver Ludovic Courtès
2021-02-01  2:47       ` Maxim Cournoyer
2021-01-18  6:24   ` [bug#45948] [PATCH 4/5] build: test-driver.scm: Add test cases filtering options Maxim Cournoyer
2021-01-18 14:38     ` [bug#45948] [PATCH 0/5] Improvements to the Automake SRFI 64 test driver Maxim Cournoyer
2021-01-18  6:25   ` [bug#45948] [PATCH 4/5] build: test-driver.scm: Provide the ability to filter on test case names Maxim Cournoyer
2021-01-30 21:34     ` [bug#45948] [PATCH 0/5] Improvements to the Automake SRFI 64 test driver Ludovic Courtès
2021-02-01  3:44       ` bug#45948: " Maxim Cournoyer
2021-01-18  6:25   ` [bug#45948] [PATCH 5/5] build: test-driver.scm: Add a new '--errors-only' option Maxim Cournoyer
2021-01-30 21:32   ` [bug#45948] [PATCH 0/5] Improvements to the Automake SRFI 64 test driver Ludovic Courtès
2021-02-01 22:18 ` Ludovic Courtès
2021-02-02  5:47   ` Maxim Cournoyer
2021-02-02  8:36     ` zimoun
2021-02-02 12:52       ` Maxim Cournoyer

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

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210118062501.27022-1-maxim.cournoyer@gmail.com \
    --to=maxim.cournoyer@gmail.com \
    --cc=45948@debbugs.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 public inbox

	https://git.savannah.gnu.org/cgit/guix.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).