guix-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug#35929] [PATCH] tests: hackage: avoid mock, and extract test data


From: Ludovic Courtès
Subject: [bug#35929] [PATCH] tests: hackage: avoid mock, and extract test data
Date: Fri, 31 May 2019 19:57:37 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux)

Hi,

Robert Vollmert <address@hidden> skribis:

>> On 29. May 2019, at 23:16, Ludovic Courtès <address@hidden> wrote:
>> --8<---------------cut here---------------start------------->8---
>> scheme@(guile-user)> (define-syntax-rule (match-pattern obj pattern)
>>                     (match obj
>>                       (pattern #t)
>>                       (_       #f)))
>> scheme@(guile-user)> (match-pattern '(1 2 3) (a b c))
>> $14 = #t
>> scheme@(guile-user)> (match-pattern '(1 2 3) (a b))
>> $15 = #f
>> scheme@(guile-user)> (match-pattern '(7 7) (a a))
>> $16 = #t
>> scheme@(guile-user)> (match-pattern '(1 2) (a a))
>> $17 = #f
>> --8<---------------cut here---------------end--------------->8—
>
> Hmm, I can’t quite get this to work. I’d like to supply a name for
> the pattern, so I can reuse it across test cases, and I’m currently
> at a loss for how to do tha:
>
> scheme@(ice-9 match)> (define pattern '(a b c))
> scheme@(ice-9 match)> (match-pattern '(a 2) pattern)
> $30 = #t

Indeed, ‘match’ expects patterns to be literals.  So you cannot do:

  (define pattern …)

and then use that pattern in ‘match’ clauses.

If you wanted to do that, you would need to define a “procedural”
variant of ‘match’, which is not terribly difficult either, but it’s a
different beast.

> I did manage to get things to work using eval, will send a revised
> patch.

Please don’t use ‘eval’; there’s a saying that “eval is evil”, because
basically anything can happen when calling out to ‘eval’.

So as it turns out, I realize that the factorization you wanted to make
is not all that easy to achieve.  Perhaps adding a procedural pattern
matcher, which would be similar to ‘equal?’ except that it would ignore
the sha256, synopsis, and description, is the right way to go.

HTH!

Ludo’.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]