|
From: | Philip McGrath |
Subject: | bug#52749: G-expressions don't consistently preserve #nil |
Date: | Wed, 22 Dec 2021 23:25:35 -0500 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.1 |
The following program exposes the error: --8<---------------cut here---------------start------------->8--- (use-modules (guix build json) (guix gexp) (guix monads) (guix store) (guix derivations) (rnrs conditions) (ice-9 textual-ports)) (define (check-equal? actual expected message) (define who 'check-equal?) (unless (equal? actual expected) (raise-exception (condition (make-assertion-violation) (make-who-condition 'check-equal?) (make-irritants-condition (list actual)) (make-message-condition (format #f "~a: ~a\n ~a: ~s\n ~a: ~s\n ~a: ~s" who "test failed" "message" message "expected" expected "actual" actual)))))) (define (sexp->json-string sx) (call-with-output-string (lambda (out) (write-json sx out)))) (define (gexp->json-string gx) (run-with-store (open-connection) (mlet* %store-monad ((drv (gexp->derivation "example.json" (with-imported-modules `((guix build json)) #~(begin (use-modules (guix build json)) (call-with-output-file #$output (lambda (out) (write-json #$gx out))))))) (_built (built-derivations (list drv)))) (return (call-with-input-file (derivation->output-path drv) get-string-all))))) (check-equal? (sexp->json-string '()) "[]" "sexp: empty array") (check-equal? (gexp->json-string #~'()) "[]" "gexp: empty array") (check-equal? (sexp->json-string #nil) "null" "sexp: null") (check-equal? (gexp->json-string #~#nil) "null" "gexp: null") (check-equal? (sexp->json-string '(@ ("k" . #nil))) "{\"k\":null}" "sexp: null in object") ;; This one fails! (check-equal? (gexp->json-string #~'(@ ("k" . #nil))) "{\"k\":null}" "gexp: null in object") --8<---------------cut here---------------end--------------->8--- -Philip
[Prev in Thread] | Current Thread | [Next in Thread] |