diff options
| author | Maxim Cournoyer <maxim.cournoyer@gmail.com> | 2021-05-16 01:09:39 -0400 |
|---|---|---|
| committer | Maxim Cournoyer <maxim.cournoyer@gmail.com> | 2021-05-17 23:27:39 -0400 |
| commit | b7297d66c58b4fe2c153dce4f1069235269cd005 (patch) | |
| tree | 40f2e87c8f74db175aab3037f0b374e72974fea5 /tests | |
| parent | e7e2b1c10b9a779ac7938909dbfafbc739740363 (diff) | |
services: configuration: Add a define-maybe/no-serialization syntax.
Before this change, using define-maybe along define-configuration with the
no-serialization syntactic keyword would result in the following warning:
warning: possibly unbound variable `VARIABLE-NAME'
This change introduces the define-maybe/no-serialization variant that does
away with defining a serialization helper procedure, which makes it possible
to avoid the above warning.
* gnu/services/configuration.scm (define-maybe/no-serialization): New syntax.
(define-maybe-helper): New procedure.
(define-maybe): Define syntax using the above procedure.
* tests/services/configuration.scm (tests): Fix module name.
(custom-number-serializer): Do not print to standard output.
(maybe-number?, serialize-maybe-number): New procedures defined via the
define-maybe macro.
(config-with-maybe-number): New configuration.
(serialize-number): New procedure.
("maybe value serialization"): New test.
(maybe-string?): New procedure defined via the define-maybe/no-serialization
macro.
(config-with-maybe-string/no-serialization): New configuration.
("maybe value without serialization no procedure bound"): New test.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/services/configuration.scm | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/tests/services/configuration.scm b/tests/services/configuration.scm index 21ad1884850..85badd2da65 100644 --- a/tests/services/configuration.scm +++ b/tests/services/configuration.scm | |||
| @@ -16,7 +16,7 @@ | |||
| 16 | ;;; You should have received a copy of the GNU General Public License | 16 | ;;; You should have received a copy of the GNU General Public License |
| 17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | 17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. |
| 18 | 18 | ||
| 19 | (define-module (tests services linux) | 19 | (define-module (tests services configuration) |
| 20 | #:use-module (gnu services configuration) | 20 | #:use-module (gnu services configuration) |
| 21 | #:use-module (guix gexp) | 21 | #:use-module (guix gexp) |
| 22 | #:use-module (srfi srfi-34) | 22 | #:use-module (srfi srfi-34) |
| @@ -61,7 +61,7 @@ | |||
| 61 | (port-configuration-ndv-port (port-configuration-ndv)))) | 61 | (port-configuration-ndv-port (port-configuration-ndv)))) |
| 62 | 62 | ||
| 63 | (define (custom-number-serializer name value) | 63 | (define (custom-number-serializer name value) |
| 64 | (format #t "~a = ~a;" name value)) | 64 | (format #f "~a = ~a;" name value)) |
| 65 | 65 | ||
| 66 | (define-configuration serializable-configuration | 66 | (define-configuration serializable-configuration |
| 67 | (port (number 80) "The port number." custom-number-serializer)) | 67 | (port (number 80) "The port number." custom-number-serializer)) |
| @@ -81,3 +81,28 @@ | |||
| 81 | (not (false-if-exception | 81 | (not (false-if-exception |
| 82 | (let ((config (serializable-configuration))) | 82 | (let ((config (serializable-configuration))) |
| 83 | (serialize-configuration config serializable-configuration-fields))))) | 83 | (serialize-configuration config serializable-configuration-fields))))) |
| 84 | |||
| 85 | |||
| 86 | ;;; | ||
| 87 | ;;; define-maybe macro. | ||
| 88 | ;;; | ||
| 89 | (define-maybe number) | ||
| 90 | |||
| 91 | (define-configuration config-with-maybe-number | ||
| 92 | (port (maybe-number 80) "The port number.")) | ||
| 93 | |||
| 94 | (define (serialize-number field value) | ||
| 95 | (format #f "~a=~a" field value)) | ||
| 96 | |||
| 97 | (test-equal "maybe value serialization" | ||
| 98 | "port=80" | ||
| 99 | (serialize-maybe-number "port" 80)) | ||
| 100 | |||
| 101 | (define-maybe/no-serialization string) | ||
| 102 | |||
| 103 | (define-configuration config-with-maybe-string/no-serialization | ||
| 104 | (name (maybe-string) "The name of the item.") | ||
| 105 | (no-serialization)) | ||
| 106 | |||
| 107 | (test-assert "maybe value without serialization no procedure bound" | ||
| 108 | (not (defined? 'serialize-maybe-string))) | ||
