summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2017-04-15 23:53:23 +0200
committerLudovic Courtès <ludo@gnu.org>2017-04-16 00:48:08 +0200
commit1bb895eabf74a1e571887eb1521915e668a5c28d (patch)
tree7e8e5210a8c3f26d07ac46992f05740430436fe5 /tests
parentf816dba680124860022ba155cf5a6a337739ef11 (diff)
downloadguix-1bb895eabf74a1e571887eb1521915e668a5c28d.tar.gz
services: Service types can now specify a default value for instances.
* gnu/services.scm (&no-default-value): New variable.
(<service-type>)[default-value]: New field.
(<service>): Rename constructor from 'service' to 'make-service'.
(service): New macro.
(%service-with-default-value): New procedure.
(&missing-value-service-error): New error condition.
* tests/services.scm ("services, default value"): New test.
* doc/guix.texi (Service Types and Services): Document 'default-value'.
(Service Reference): Explain default values.
Diffstat (limited to 'tests')
-rw-r--r--tests/services.scm11
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/services.scm b/tests/services.scm
index 7983427a7d..8484ee982a 100644
--- a/tests/services.scm
+++ b/tests/services.scm
@@ -31,6 +31,17 @@
 
 (test-begin "services")
 
+(test-equal "services, default value"
+  '(42 123 234 error)
+  (let* ((t1 (service-type (name 't1) (extensions '())))
+         (t2 (service-type (name 't2) (extensions '())
+                           (default-value 42))))
+    (list (service-value (service t2))
+          (service-value (service t2 123))
+          (service-value (service t1 234))
+          (guard (c ((missing-value-service-error? c) 'error))
+            (service t1)))))
+
 (test-assert "service-back-edges"
   (let* ((t1 (service-type (name 't1) (extensions '())
                            (compose +) (extend *)))