unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Maxime Devos <maximedevos@telenet.be>
To: "Aleix Conchillo Flaqué" <aconchillo@gmail.com>, guile-devel@gnu.org
Subject: Re: [PATCH] srfi-64: fix unused variable warnings
Date: Thu, 01 Apr 2021 13:37:26 +0200	[thread overview]
Message-ID: <74a46c307dac2d9e2dbc4affdaa5c56a75fc2b1b.camel@telenet.be> (raw)
In-Reply-To: <20210401061135.11914-1-aconchillo@gmail.com>

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

On Wed, 2021-03-31 at 23:11 -0700, Aleix Conchillo Flaqué wrote:
> * module/srfi/srfi-64/testing.scm: remove unused name variable and use
> let instead of let*.
> 

I don't think this is the correct approach with respect to side effects.
For example, in:

>  (define (%test-comp2 comp x)
>      (syntax-case (list x (list (syntax quote) (%test-source-line2 x)) comp) ()
>        (((mac tname expected expr) line comp)
>         (syntax
> -	(let* ((r (test-runner-get))
> -	       (name tname))
> +	(let ((r (test-runner-get)))
>  	  (test-result-alist! r (cons (cons 'test-name tname) line))
>  	  (%test-comp2body r comp expected expr))))

I would keep the let* (but reverse the binding order), but change 'tname'
with 'name' in the call to 'test-result-alist!', such that 'test-X' macros
behave somewhat more like procedure calls (except for installing exeption
handlers and having access to the s-expression of the code that will be run,
of course).  It's largely a matter of taste, though.

In any case, it is good that 'tname' is now evaluated only once, as per
SRFI-64 (notice ***It is evaluated only once.*** (markup mine)):

 (test-assert [test-name] expression)

 This evaluates the expression. The test passes if the result is true;
 if the result is false, a test failure is reported. The test also fails
 if an exception is raised, assuming the implementation has a way to catch
 exceptions. How the failure is reported depends on the test runner environment.
 The test-name is a string that names the test case. (Though the test-name is
 a string literal in the examples, it is an expression. ***It is evaluated only once.***)
 It is used when reporting errors, and also when skipping tests, as described below.
 It is an error to invoke test-assert if there is no current test runner.

(My suggestion would be to also evaluate 'test-name' at least once, even if there
is no test runner, which seems a bit stricter than SRFI-64 demands, but seems like
a nice property to have and easy to achieve.)

As this patch does not ‘merely’ fix a warnings, but fixes a bug, could you change
the patch message accordingly?  Something like

  srfi-64: fix double evaluation of test-name.

perhaps?

Greetings,
Maxime.

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 260 bytes --]

  reply	other threads:[~2021-04-01 11:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-01  6:11 [PATCH] srfi-64: fix unused variable warnings Aleix Conchillo Flaqué
2021-04-01 11:37 ` Maxime Devos [this message]
2021-04-02  6:13   ` Aleix Conchillo Flaqué
     [not found]   ` <CA+XASoWMDakd2rAu96iZB-=giHLoer1gcM4dgu+wxg1MCZ9xDw@mail.gmail.com>
2021-04-02  6:58     ` Maxime Devos

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://www.gnu.org/software/guile/

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

  git send-email \
    --in-reply-to=74a46c307dac2d9e2dbc4affdaa5c56a75fc2b1b.camel@telenet.be \
    --to=maximedevos@telenet.be \
    --cc=aconchillo@gmail.com \
    --cc=guile-devel@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.
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).