summaryrefslogtreecommitdiff
path: root/tests/services
diff options
context:
space:
mode:
authorAttila Lendvai <attila@lendvai.name>2022-05-17 13:39:26 +0200
committerLudovic Courtès <ludo@gnu.org>2022-06-15 00:25:21 +0200
commite11517052b1bbd9fa06891ad0b13b24494db757e (patch)
tree1b5249711e6f1e7a861de26c18487c9903dff9f5 /tests/services
parent3d0749b4e30dfbbdfc9c365e8ab8f7bebaa96fd7 (diff)
services: configuration: Support (field1 maybe-number "") format.
As opposed to explicitly using 'disabled as value, or using the (field1 (maybe-number) "") format. It's mostly the work of Maxime Devos shared under #54674, with some modifications by Attila Lendvai. * gnu/services/configuration.scm (normalize-field-type+def): New function. (define-configuration-helper) (define-configuration): Support new field format. * tests/services/configuration.scm (config-with-maybe-number->string): New function. ("maybe value serialization of the instance"): New test. ("maybe value serialization of the instance, unspecified"): New test. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'tests/services')
-rw-r--r--tests/services/configuration.scm28
1 files changed, 23 insertions, 5 deletions
diff --git a/tests/services/configuration.scm b/tests/services/configuration.scm
index 86a36a388d..0debf8095b 100644
--- a/tests/services/configuration.scm
+++ b/tests/services/configuration.scm
@@ -27,6 +27,9 @@
(test-begin "services-configuration")
+(define (serialize-number field value)
+ (format #f "~a=~a" field value))
+
;;;
;;; define-configuration macro.
@@ -47,7 +50,6 @@
80
(port-configuration-cs-port (port-configuration-cs)))
-(define serialize-number "")
(define-configuration port-configuration-ndv
(port (number) "The port number."))
@@ -101,15 +103,31 @@
(define-maybe number)
(define-configuration config-with-maybe-number
- (port (maybe-number 80) "The port number."))
-
-(define (serialize-number field value)
- (format #f "~a=~a" field value))
+ (port (maybe-number 80) "")
+ (count maybe-number ""))
(test-equal "maybe value serialization"
"port=80"
(serialize-maybe-number "port" 80))
+(define (config-with-maybe-number->string x)
+ (eval (gexp->approximate-sexp
+ (serialize-configuration x config-with-maybe-number-fields))
+ (current-module)))
+
+(test-equal "maybe value serialization of the instance"
+ "port=42count=43"
+ (config-with-maybe-number->string
+ (config-with-maybe-number
+ (port 42)
+ (count 43))))
+
+(test-equal "maybe value serialization of the instance, unspecified"
+ "port=42"
+ (config-with-maybe-number->string
+ (config-with-maybe-number
+ (port 42))))
+
(define-maybe/no-serialization string)
(define-configuration config-with-maybe-string/no-serialization