diff mbox

[1/2] utils: Fix default-keyword-arguments.

Message ID 20160920212916.18530-1-ericbavier@openmailbox.org
State New
Headers show

Commit Message

Eric Bavier Sept. 20, 2016, 9:29 p.m. UTC
From: Eric Bavier <bavier@member.fsf.org>

* guix/utils.scm (default-keyword-arguments): Properly test for present
keywords.
* tests/utils.scm (default-keyword-arguments): New test.
---
 guix/utils.scm  |  2 +-
 tests/utils.scm | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

Comments

Ludovic Courtès Sept. 24, 2016, 2:16 a.m. UTC | #1
Eric Bavier <ericbavier@openmailbox.org> skribis:

> From: Eric Bavier <bavier@member.fsf.org>
>
> * guix/utils.scm (default-keyword-arguments): Properly test for present
> keywords.
> * tests/utils.scm (default-keyword-arguments): New test.

Good catch, please push!

Thanks,
Ludo’.
diff mbox

Patch

diff --git a/guix/utils.scm b/guix/utils.scm
index c68094c..ded3114 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -369,7 +369,7 @@  keywords not already present in ARGS."
     (match defaults
       ((kw value rest ...)
        (loop rest
-             (if (assoc-ref kw args)
+             (if (memq kw args)
                  args
                  (cons* kw value args))))
       (()
diff --git a/tests/utils.scm b/tests/utils.scm
index 6590ed9..960928c 100644
--- a/tests/utils.scm
+++ b/tests/utils.scm
@@ -111,6 +111,18 @@ 
         (ensure-keyword-arguments '(#:foo 2) '(#:bar 3))
         (ensure-keyword-arguments '(#:foo 2) '(#:bar 3 #:foo 42))))
 
+(test-equal "default-keyword-arguments"
+  '((#:foo 2)
+    (#:foo 2)
+    (#:foo 2 #:bar 3)
+    (#:foo 2 #:bar 3)
+    (#:foo 2 #:bar 3))
+  (list (default-keyword-arguments '() '(#:foo 2))
+        (default-keyword-arguments '(#:foo 2) '(#:foo 4))
+        (default-keyword-arguments '() '(#:bar 3 #:foo 2))
+        (default-keyword-arguments '(#:bar 3) '(#:foo 2))
+        (default-keyword-arguments '(#:foo 2 #:bar 3) '(#:bar 6))))
+
 (test-assert "filtered-port, file"
   (let* ((file  (search-path %load-path "guix.scm"))
          (input (open-file file "r0b")))