mirror of
https://git.savannah.gnu.org/git/guix.git
synced 2026-05-27 19:41:50 +02:00
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>
This commit is contained in:
committed by
Ludovic Courtès
parent
3d0749b4e3
commit
e11517052b
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user