gnu: jsoncpp: Update to 1.9.1.
[guix.git] / tests / gexp.scm
blob460afe7f59b665355cc3cf7036c5f8af16453a76
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
3 ;;;
4 ;;; This file is part of GNU Guix.
5 ;;;
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
10 ;;;
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 ;;; GNU General Public License for more details.
15 ;;;
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/>.
19 (define-module (test-gexp)
20   #:use-module (guix store)
21   #:use-module (guix monads)
22   #:use-module (guix gexp)
23   #:use-module (guix grafts)
24   #:use-module (guix derivations)
25   #:use-module (guix packages)
26   #:use-module (guix build-system trivial)
27   #:use-module (guix tests)
28   #:use-module ((guix build utils) #:select (with-directory-excursion))
29   #:use-module ((guix utils) #:select (call-with-temporary-directory))
30   #:use-module (gnu packages)
31   #:use-module (gnu packages base)
32   #:use-module (gnu packages bootstrap)
33   #:use-module (srfi srfi-1)
34   #:use-module (srfi srfi-34)
35   #:use-module (srfi srfi-64)
36   #:use-module (rnrs io ports)
37   #:use-module (ice-9 match)
38   #:use-module (ice-9 regex)
39   #:use-module (ice-9 popen)
40   #:use-module (ice-9 ftw))
42 ;; Test the (guix gexp) module.
44 (define %store
45   (open-connection-for-tests))
47 ;; Globally disable grafts because they can trigger early builds.
48 (%graft? #f)
50 ;; For white-box testing.
51 (define (gexp-inputs x)
52   ((@@ (guix gexp) gexp-inputs) x))
53 (define (gexp-native-inputs x)
54   ((@@ (guix gexp) gexp-native-inputs) x))
55 (define (gexp-outputs x)
56   ((@@ (guix gexp) gexp-outputs) x))
57 (define (gexp->sexp . x)
58   (apply (@@ (guix gexp) gexp->sexp) x))
60 (define* (gexp->sexp* exp #:optional target)
61   (run-with-store %store (gexp->sexp exp
62                                      #:target target)
63                   #:guile-for-build (%guile-for-build)))
65 (define %extension-package
66   ;; Example of a package to use when testing 'with-extensions'.
67   (dummy-package "extension"
68                  (build-system trivial-build-system)
69                  (arguments
70                   `(#:guile ,%bootstrap-guile
71                     #:modules ((guix build utils))
72                     #:builder
73                     (begin
74                       (use-modules (guix build utils))
75                       (let* ((out (string-append (assoc-ref %outputs "out")
76                                                  "/share/guile/site/"
77                                                  (effective-version))))
78                         (mkdir-p out)
79                         (call-with-output-file (string-append out "/hg2g.scm")
80                           (lambda (port)
81                             (write '(define-module (hg2g)
82                                       #:export (the-answer))
83                                    port)
84                             (write '(define the-answer 42) port)))))))))
87 (test-begin "gexp")
89 (test-equal "no refs"
90   '(display "hello!")
91   (let ((exp (gexp (display "hello!"))))
92     (and (gexp? exp)
93          (null? (gexp-inputs exp))
94          (gexp->sexp* exp))))
96 (test-equal "unquote"
97   '(display `(foo ,(+ 2 3)))
98   (let ((exp (gexp (display `(foo ,(+ 2 3))))))
99     (and (gexp? exp)
100          (null? (gexp-inputs exp))
101          (gexp->sexp* exp))))
103 (test-assert "one input package"
104   (let ((exp (gexp (display (ungexp coreutils)))))
105     (and (gexp? exp)
106          (match (gexp-inputs exp)
107            (((p "out"))
108             (eq? p coreutils)))
109          (equal? `(display ,(derivation->output-path
110                              (package-derivation %store coreutils)))
111                  (gexp->sexp* exp)))))
113 (test-assert "one input package, dotted list"
114   (let ((exp (gexp (coreutils . (ungexp coreutils)))))
115     (and (gexp? exp)
116          (match (gexp-inputs exp)
117            (((p "out"))
118             (eq? p coreutils)))
119          (equal? `(coreutils . ,(derivation->output-path
120                                  (package-derivation %store coreutils)))
121                  (gexp->sexp* exp)))))
123 (test-assert "one input origin"
124   (let ((exp (gexp (display (ungexp (package-source coreutils))))))
125     (and (gexp? exp)
126          (match (gexp-inputs exp)
127            (((o "out"))
128             (eq? o (package-source coreutils))))
129          (equal? `(display ,(derivation->output-path
130                              (package-source-derivation
131                               %store (package-source coreutils))))
132                  (gexp->sexp* exp)))))
134 (test-assert "one local file"
135   (let* ((file  (search-path %load-path "guix.scm"))
136          (local (local-file file))
137          (exp   (gexp (display (ungexp local))))
138          (intd  (add-to-store %store (basename file) #f
139                               "sha256" file)))
140     (and (gexp? exp)
141          (match (gexp-inputs exp)
142            (((x "out"))
143             (eq? x local)))
144          (equal? `(display ,intd) (gexp->sexp* exp)))))
146 (test-assert "one local file, symlink"
147   (let ((file (search-path %load-path "guix.scm"))
148         (link (tmpnam)))
149     (dynamic-wind
150       (const #t)
151       (lambda ()
152         (symlink (canonicalize-path file) link)
153         (let* ((local (local-file link "my-file" #:recursive? #f))
154                (exp   (gexp (display (ungexp local))))
155                (intd  (add-to-store %store "my-file" #f
156                                     "sha256" file)))
157           (and (gexp? exp)
158                (match (gexp-inputs exp)
159                  (((x "out"))
160                   (eq? x local)))
161                (equal? `(display ,intd) (gexp->sexp* exp)))))
162       (lambda ()
163         (false-if-exception (delete-file link))))))
165 (test-equal "local-file, relative file name"
166   (canonicalize-path (search-path %load-path "guix/base32.scm"))
167   (let ((directory (dirname (search-path %load-path
168                                          "guix/build-system/gnu.scm"))))
169     (with-directory-excursion directory
170         (let ((file (local-file "../guix/base32.scm")))
171           (local-file-absolute-file-name file)))))
173 (test-assertm "local-file, #:select?"
174   (mlet* %store-monad ((select? -> (lambda (file stat)
175                                      (member (basename file)
176                                              '("guix.scm" "tests"
177                                                "gexp.scm"))))
178                        (file -> (local-file ".." "directory"
179                                             #:recursive? #t
180                                             #:select? select?))
181                        (dir (lower-object file)))
182     (return (and (store-path? dir)
183                  (equal? (scandir dir)
184                          '("." ".." "guix.scm" "tests"))
185                  (equal? (scandir (string-append dir "/tests"))
186                          '("." ".." "gexp.scm"))))))
188 (test-assert "one plain file"
189   (let* ((file     (plain-file "hi" "Hello, world!"))
190          (exp      (gexp (display (ungexp file))))
191          (expected (add-text-to-store %store "hi" "Hello, world!")))
192     (and (gexp? exp)
193          (match (gexp-inputs exp)
194            (((x "out"))
195             (eq? x file)))
196          (equal? `(display ,expected) (gexp->sexp* exp)))))
198 (test-assert "same input twice"
199   (let ((exp (gexp (begin
200                      (display (ungexp coreutils))
201                      (display (ungexp coreutils))))))
202     (and (gexp? exp)
203          (match (gexp-inputs exp)
204            (((p "out"))
205             (eq? p coreutils)))
206          (let ((e `(display ,(derivation->output-path
207                               (package-derivation %store coreutils)))))
208            (equal? `(begin ,e ,e) (gexp->sexp* exp))))))
210 (test-assert "two input packages, one derivation, one file"
211   (let* ((drv (build-expression->derivation
212                %store "foo" 'bar
213                #:guile-for-build (package-derivation %store %bootstrap-guile)))
214          (txt (add-text-to-store %store "foo" "Hello, world!"))
215          (exp (gexp (begin
216                       (display (ungexp coreutils))
217                       (display (ungexp %bootstrap-guile))
218                       (display (ungexp drv))
219                       (display (ungexp txt))))))
220     (define (match-input thing)
221       (match-lambda
222        ((drv-or-pkg _ ...)
223         (eq? thing drv-or-pkg))))
225     (and (gexp? exp)
226          (= 4 (length (gexp-inputs exp)))
227          (every (lambda (input)
228                   (find (match-input input) (gexp-inputs exp)))
229                 (list drv coreutils %bootstrap-guile txt))
230          (let ((e0 `(display ,(derivation->output-path
231                                (package-derivation %store coreutils))))
232                (e1 `(display ,(derivation->output-path
233                                (package-derivation %store %bootstrap-guile))))
234                (e2 `(display ,(derivation->output-path drv)))
235                (e3 `(display ,txt)))
236            (equal? `(begin ,e0 ,e1 ,e2 ,e3) (gexp->sexp* exp))))))
238 (test-assert "file-append"
239   (let* ((drv (package-derivation %store %bootstrap-guile))
240          (fa  (file-append %bootstrap-guile "/bin/guile"))
241          (exp #~(here we go #$fa)))
242     (and (match (gexp->sexp* exp)
243            (('here 'we 'go (? string? result))
244             (string=? result
245                       (string-append (derivation->output-path drv)
246                                      "/bin/guile"))))
247          (match (gexp-inputs exp)
248            (((thing "out"))
249             (eq? thing fa))))))
251 (test-assert "file-append, output"
252   (let* ((drv (package-derivation %store glibc))
253          (fa  (file-append glibc "/lib" "/debug"))
254          (exp #~(foo #$fa:debug)))
255     (and (match (gexp->sexp* exp)
256            (('foo (? string? result))
257             (string=? result
258                       (string-append (derivation->output-path drv "debug")
259                                      "/lib/debug"))))
260          (match (gexp-inputs exp)
261            (((thing "debug"))
262             (eq? thing fa))))))
264 (test-assert "file-append, nested"
265   (let* ((drv   (package-derivation %store glibc))
266          (dir   (file-append glibc "/bin"))
267          (slash (file-append dir "/"))
268          (file  (file-append slash "getent"))
269          (exp   #~(foo #$file)))
270     (and (match (gexp->sexp* exp)
271            (('foo (? string? result))
272             (string=? result
273                       (string-append (derivation->output-path drv)
274                                      "/bin/getent"))))
275          (match (gexp-inputs exp)
276            (((thing "out"))
277             (eq? thing file))))))
279 (test-assert "ungexp + ungexp-native"
280   (let* ((exp    (gexp (list (ungexp-native %bootstrap-guile)
281                              (ungexp coreutils)
282                              (ungexp-native glibc)
283                              (ungexp binutils))))
284          (target "mips64el-linux")
285          (guile  (derivation->output-path
286                   (package-derivation %store %bootstrap-guile)))
287          (cu     (derivation->output-path
288                   (package-cross-derivation %store coreutils target)))
289          (libc   (derivation->output-path
290                   (package-derivation %store glibc)))
291          (bu     (derivation->output-path
292                   (package-cross-derivation %store binutils target))))
293     (and (lset= equal?
294                 `((,%bootstrap-guile "out") (,glibc "out"))
295                 (gexp-native-inputs exp))
296          (lset= equal?
297                 `((,coreutils "out") (,binutils "out"))
298                 (gexp-inputs exp))
299          (equal? `(list ,guile ,cu ,libc ,bu)
300                  (gexp->sexp* exp target)))))
302 (test-equal "ungexp + ungexp-native, nested"
303   (list `((,%bootstrap-guile "out")) '<> `((,coreutils "out")))
304   (let* ((exp (gexp (list (ungexp-native (gexp (ungexp coreutils)))
305                           (ungexp %bootstrap-guile)))))
306     (list (gexp-inputs exp) '<> (gexp-native-inputs exp))))
308 (test-equal "ungexp + ungexp-native, nested, special mixture"
309   `(() <> ((,coreutils "out")))
311   ;; (gexp-native-inputs exp) used to return '(), wrongfully.
312   (let* ((foo (gexp (foo (ungexp-native coreutils))))
313          (exp (gexp (bar (ungexp foo)))))
314     (list (gexp-inputs exp) '<> (gexp-native-inputs exp))))
316 (test-assert "input list"
317   (let ((exp   (gexp (display
318                       '(ungexp (list %bootstrap-guile coreutils)))))
319         (guile (derivation->output-path
320                 (package-derivation %store %bootstrap-guile)))
321         (cu    (derivation->output-path
322                 (package-derivation %store coreutils))))
323     (and (lset= equal?
324                 `((,%bootstrap-guile "out") (,coreutils "out"))
325                 (gexp-inputs exp))
326          (equal? `(display '(,guile ,cu))
327                  (gexp->sexp* exp)))))
329 (test-assert "input list + ungexp-native"
330   (let* ((target "mips64el-linux")
331          (exp   (gexp (display
332                        (cons '(ungexp-native (list %bootstrap-guile coreutils))
333                              '(ungexp (list glibc binutils))))))
334          (guile (derivation->output-path
335                  (package-derivation %store %bootstrap-guile)))
336          (cu    (derivation->output-path
337                  (package-derivation %store coreutils)))
338          (xlibc (derivation->output-path
339                  (package-cross-derivation %store glibc target)))
340          (xbu   (derivation->output-path
341                  (package-cross-derivation %store binutils target))))
342     (and (lset= equal?
343                 `((,%bootstrap-guile "out") (,coreutils "out"))
344                 (gexp-native-inputs exp))
345          (lset= equal?
346                 `((,glibc "out") (,binutils "out"))
347                 (gexp-inputs exp))
348          (equal? `(display (cons '(,guile ,cu) '(,xlibc ,xbu)))
349                  (gexp->sexp* exp target)))))
351 (test-assert "input list splicing"
352   (let* ((inputs  (list (gexp-input glibc "debug") %bootstrap-guile))
353          (outputs (list (derivation->output-path
354                          (package-derivation %store glibc)
355                          "debug")
356                         (derivation->output-path
357                          (package-derivation %store %bootstrap-guile))))
358          (exp     (gexp (list (ungexp-splicing (cons (+ 2 3) inputs))))))
359     (and (lset= equal?
360                 `((,glibc "debug") (,%bootstrap-guile "out"))
361                 (gexp-inputs exp))
362          (equal? (gexp->sexp* exp)
363                  `(list ,@(cons 5 outputs))))))
365 (test-assert "input list splicing + ungexp-native-splicing"
366   (let* ((inputs (list (gexp-input glibc "debug" #:native? #t)
367                        %bootstrap-guile))
368          (exp    (gexp (list (ungexp-native-splicing (cons (+ 2 3) inputs))))))
369     (and (lset= equal?
370                 `((,glibc "debug") (,%bootstrap-guile "out"))
371                 (gexp-native-inputs exp))
372          (null? (gexp-inputs exp))
373          (equal? (gexp->sexp* exp)                ;native
374                  (gexp->sexp* exp "mips64el-linux")))))
376 (test-assert "gexp list splicing + ungexp-splicing"
377   (let* ((inner (gexp (ungexp-native glibc)))
378          (exp   (gexp (list (ungexp-splicing (list inner))))))
379     (and (equal? `((,glibc "out")) (gexp-native-inputs exp))
380          (null? (gexp-inputs exp))
381          (equal? (gexp->sexp* exp)                ;native
382                  (gexp->sexp* exp "mips64el-linux")))))
384 (test-equal "output list"
385   2
386   (let ((exp (gexp (begin (mkdir (ungexp output))
387                           (mkdir (ungexp output "bar"))))))
388     (length (gexp-outputs exp))))                ;XXX: <output-ref> is private
390 (test-assert "output list, combined gexps"
391   (let* ((exp0  (gexp (mkdir (ungexp output))))
392          (exp1  (gexp (mkdir (ungexp output "foo"))))
393          (exp2  (gexp (begin (display "hi!") (ungexp exp0) (ungexp exp1)))))
394     (and (lset= equal?
395                 (append (gexp-outputs exp0) (gexp-outputs exp1))
396                 (gexp-outputs exp2))
397          (= 2 (length (gexp-outputs exp2))))))
399 (test-equal "output list, combined gexps, duplicate output"
400   1
401   (let* ((exp0 (gexp (mkdir (ungexp output))))
402          (exp1 (gexp (begin (mkdir (ungexp output)) (ungexp exp0))))
403          (exp2 (gexp (begin (mkdir (ungexp output)) (ungexp exp1)))))
404     (length (gexp-outputs exp2))))
406 (test-assert "output list + ungexp-splicing list, combined gexps"
407   (let* ((exp0  (gexp (mkdir (ungexp output))))
408          (exp1  (gexp (mkdir (ungexp output "foo"))))
409          (exp2  (gexp (begin (display "hi!")
410                              (ungexp-splicing (list exp0 exp1))))))
411     (and (lset= equal?
412                 (append (gexp-outputs exp0) (gexp-outputs exp1))
413                 (gexp-outputs exp2))
414          (= 2 (length (gexp-outputs exp2))))))
416 (test-assertm "gexp->file"
417   (mlet* %store-monad ((exp -> (gexp (display (ungexp %bootstrap-guile))))
418                        (guile  (package-file %bootstrap-guile))
419                        (sexp   (gexp->sexp exp))
420                        (drv    (gexp->file "foo" exp))
421                        (out -> (derivation->output-path drv))
422                        (done   (built-derivations (list drv)))
423                        (refs   (references* out)))
424     (return (and (equal? sexp (call-with-input-file out read))
425                  (equal? (list guile) refs)))))
427 (test-assertm "gexp->file + file-append"
428   (mlet* %store-monad ((exp -> #~#$(file-append %bootstrap-guile
429                                                 "/bin/guile"))
430                        (guile  (package-file %bootstrap-guile))
431                        (drv    (gexp->file "foo" exp))
432                        (out -> (derivation->output-path drv))
433                        (done   (built-derivations (list drv)))
434                        (refs   (references* out)))
435     (return (and (equal? (string-append guile "/bin/guile")
436                          (call-with-input-file out read))
437                  (equal? (list guile) refs)))))
439 (test-assertm "gexp->file + #:splice?"
440   (mlet* %store-monad ((exp -> (list
441                                 #~(define foo 'bar)
442                                 #~(define guile #$%bootstrap-guile)))
443                        (guile  (package-file %bootstrap-guile))
444                        (drv    (gexp->file "splice" exp #:splice? #t))
445                        (out -> (derivation->output-path drv))
446                        (done   (built-derivations (list drv)))
447                        (refs   (references* out)))
448     (pk 'splice out)
449     (return (and (equal? `((define foo 'bar)
450                            (define guile ,guile)
451                            ,(call-with-input-string "" read))
452                          (call-with-input-file out
453                            (lambda (port)
454                              (list (read port) (read port) (read port)))))
455                  (equal? (list guile) refs)))))
457 (test-assertm "gexp->derivation"
458   (mlet* %store-monad ((file    (text-file "foo" "Hello, world!"))
459                        (exp ->  (gexp
460                                  (begin
461                                    (mkdir (ungexp output))
462                                    (chdir (ungexp output))
463                                    (symlink
464                                     (string-append (ungexp %bootstrap-guile)
465                                                    "/bin/guile")
466                                     "foo")
467                                    (symlink (ungexp file)
468                                             (ungexp output "2nd")))))
469                        (drv     (gexp->derivation "foo" exp))
470                        (out ->  (derivation->output-path drv))
471                        (out2 -> (derivation->output-path drv "2nd"))
472                        (done    (built-derivations (list drv)))
473                        (refs    (references* out))
474                        (refs2   (references* out2))
475                        (guile   (package-file %bootstrap-guile "bin/guile")))
476     (return (and (string=? (readlink (string-append out "/foo")) guile)
477                  (string=? (readlink out2) file)
478                  (equal? refs (list (dirname (dirname guile))))
479                  (equal? refs2 (list file))
480                  (null? (derivation-properties drv))))))
482 (test-assertm "gexp->derivation properties"
483   (mlet %store-monad ((drv (gexp->derivation "foo"
484                                              #~(mkdir #$output)
485                                              #:properties '((type . test)))))
486     (return (equal? '((type . test))
487                     (derivation-properties drv)))))
489 (test-assertm "gexp->derivation vs. grafts"
490   (mlet* %store-monad ((graft?  (set-grafting #f))
491                        (p0 ->   (dummy-package "dummy"
492                                                (arguments
493                                                 '(#:implicit-inputs? #f))))
494                        (r  ->   (package (inherit p0) (name "DuMMY")))
495                        (p1 ->   (package (inherit p0) (replacement r)))
496                        (exp0 -> (gexp (frob (ungexp p0) (ungexp output))))
497                        (exp1 -> (gexp (frob (ungexp p1) (ungexp output))))
498                        (void    (set-guile-for-build %bootstrap-guile))
499                        (drv0    (gexp->derivation "t" exp0 #:graft? #t))
500                        (drv1    (gexp->derivation "t" exp1 #:graft? #t))
501                        (drv1*   (gexp->derivation "t" exp1 #:graft? #f))
502                        (_       (set-grafting graft?)))
503     (return (and (not (string=? (derivation->output-path drv0)
504                                 (derivation->output-path drv1)))
505                  (string=? (derivation->output-path drv0)
506                            (derivation->output-path drv1*))))))
508 (test-assertm "gexp->derivation, composed gexps"
509   (mlet* %store-monad ((exp0 -> (gexp (begin
510                                         (mkdir (ungexp output))
511                                         (chdir (ungexp output)))))
512                        (exp1 -> (gexp (symlink
513                                        (string-append (ungexp %bootstrap-guile)
514                                                       "/bin/guile")
515                                        "foo")))
516                        (exp  -> (gexp (begin (ungexp exp0) (ungexp exp1))))
517                        (drv     (gexp->derivation "foo" exp))
518                        (out ->  (derivation->output-path drv))
519                        (done    (built-derivations (list drv)))
520                        (guile   (package-file %bootstrap-guile "bin/guile")))
521     (return (string=? (readlink (string-append out "/foo"))
522                       guile))))
524 (test-assertm "gexp->derivation, default system"
525   ;; The default system should be the one at '>>=' time, not the one at
526   ;; invocation time.  See <http://bugs.gnu.org/18002>.
527   (let ((system (%current-system))
528         (mdrv   (parameterize ((%current-system "foobar64-linux"))
529                   (gexp->derivation "foo"
530                                     (gexp
531                                      (mkdir (ungexp output)))))))
532     (mlet %store-monad ((drv mdrv))
533       (return (string=? system (derivation-system drv))))))
535 (test-assertm "gexp->derivation, local-file"
536   (mlet* %store-monad ((file ->  (search-path %load-path "guix.scm"))
537                        (intd     (interned-file file #:recursive? #f))
538                        (local -> (local-file file))
539                        (exp ->   (gexp (begin
540                                          (stat (ungexp local))
541                                          (symlink (ungexp local)
542                                                   (ungexp output)))))
543                        (drv      (gexp->derivation "local-file" exp)))
544     (mbegin %store-monad
545       (built-derivations (list drv))
546       (return (string=? (readlink (derivation->output-path drv))
547                         intd)))))
549 (test-assertm "gexp->derivation, cross-compilation"
550   (mlet* %store-monad ((target -> "mips64el-linux")
551                        (exp    -> (gexp (list (ungexp coreutils)
552                                               (ungexp output))))
553                        (xdrv      (gexp->derivation "foo" exp
554                                                     #:target target))
555                        (refs      (references*
556                                    (derivation-file-name xdrv)))
557                        (xcu       (package->cross-derivation coreutils
558                                                              target))
559                        (cu        (package->derivation coreutils)))
560     (return (and (member (derivation-file-name xcu) refs)
561                  (not (member (derivation-file-name cu) refs))))))
563 (test-assertm "gexp->derivation, ungexp-native"
564   (mlet* %store-monad ((target -> "mips64el-linux")
565                        (exp    -> (gexp (list (ungexp-native coreutils)
566                                               (ungexp output))))
567                        (xdrv      (gexp->derivation "foo" exp
568                                                     #:target target))
569                        (drv       (gexp->derivation "foo" exp)))
570     (return (string=? (derivation-file-name drv)
571                       (derivation-file-name xdrv)))))
573 (test-assertm "gexp->derivation, ungexp + ungexp-native"
574   (mlet* %store-monad ((target -> "mips64el-linux")
575                        (exp    -> (gexp (list (ungexp-native coreutils)
576                                               (ungexp glibc)
577                                               (ungexp output))))
578                        (xdrv      (gexp->derivation "foo" exp
579                                                     #:target target))
580                        (refs      (references*
581                                    (derivation-file-name xdrv)))
582                        (xglibc    (package->cross-derivation glibc target))
583                        (cu        (package->derivation coreutils)))
584     (return (and (member (derivation-file-name cu) refs)
585                  (member (derivation-file-name xglibc) refs)))))
587 (test-assertm "gexp->derivation, ungexp-native + composed gexps"
588   (mlet* %store-monad ((target -> "mips64el-linux")
589                        (exp0   -> (gexp (list 1 2
590                                               (ungexp coreutils))))
591                        (exp    -> (gexp (list 0 (ungexp-native exp0))))
592                        (xdrv      (gexp->derivation "foo" exp
593                                                     #:target target))
594                        (drv       (gexp->derivation "foo" exp)))
595     (return (string=? (derivation-file-name drv)
596                       (derivation-file-name xdrv)))))
598 (test-assertm "gexp->derivation, store copy"
599   (let ((build-one #~(call-with-output-file #$output
600                        (lambda (port)
601                          (display "This is the one." port))))
602         (build-two (lambda (one)
603                      #~(begin
604                          (mkdir #$output)
605                          (symlink #$one (string-append #$output "/one"))
606                          (call-with-output-file (string-append #$output "/two")
607                            (lambda (port)
608                              (display "This is the second one." port))))))
609         (build-drv #~(begin
610                        (use-modules (guix build store-copy))
612                        (mkdir #$output)
613                        (populate-store '("graph") #$output))))
614     (mlet* %store-monad ((one (gexp->derivation "one" build-one))
615                          (two (gexp->derivation "two" (build-two one)))
616                          (drv (gexp->derivation "store-copy" build-drv
617                                                 #:references-graphs
618                                                 `(("graph" ,two))
619                                                 #:modules
620                                                 '((guix build store-copy)
621                                                   (guix progress)
622                                                   (guix records)
623                                                   (guix sets)
624                                                   (guix build utils))))
625                          (ok? (built-derivations (list drv)))
626                          (out -> (derivation->output-path drv)))
627       (let ((one (derivation->output-path one))
628             (two (derivation->output-path two)))
629         (return (and ok?
630                      (file-exists? (string-append out "/" one))
631                      (file-exists? (string-append out "/" two))
632                      (file-exists? (string-append out "/" two "/two"))
633                      (string=? (readlink (string-append out "/" two "/one"))
634                                one)))))))
636 (test-assertm "imported-files"
637   (mlet* %store-monad
638       ((files -> `(("x"     . ,(search-path %load-path "ice-9/q.scm"))
639                    ("a/b/c" . ,(search-path %load-path
640                                             "guix/derivations.scm"))
641                    ("p/q"   . ,(search-path %load-path "guix.scm"))
642                    ("p/z"   . ,(search-path %load-path "guix/store.scm"))))
643        (dir (imported-files files)))
644     (mbegin %store-monad
645       (return
646        (every (match-lambda
647                 ((path . source)
648                  (equal? (call-with-input-file (string-append dir "/" path)
649                            get-bytevector-all)
650                          (call-with-input-file source
651                            get-bytevector-all))))
652               files)))))
654 (test-assertm "imported-files with file-like objects"
655   (mlet* %store-monad ((plain -> (plain-file "foo" "bar!"))
656                        (q-scm -> (search-path %load-path "ice-9/q.scm"))
657                        (files -> `(("a/b/c" . ,q-scm)
658                                    ("p/q"   . ,plain)))
659                        (drv      (imported-files files)))
660     (define (file=? file1 file2)
661       ;; Assume deduplication is in place.
662       (= (stat:ino (stat file1))
663          (stat:ino (stat file2))))
665     (mbegin %store-monad
666       (built-derivations (list (pk 'drv drv)))
667       (mlet %store-monad ((dir -> (derivation->output-path drv))
668                           (plain* (text-file "foo" "bar!"))
669                           (q-scm* (interned-file q-scm "c")))
670         (return
671          (and (file=? (string-append dir "/a/b/c") q-scm*)
672               (file=? (string-append dir "/p/q") plain*)))))))
674 (test-equal "gexp-modules & ungexp"
675   '((bar) (foo))
676   ((@@ (guix gexp) gexp-modules)
677    #~(foo #$(with-imported-modules '((foo)) #~+)
678           #+(with-imported-modules '((bar)) #~-))))
680 (test-equal "gexp-modules & ungexp-splicing"
681   '((foo) (bar))
682   ((@@ (guix gexp) gexp-modules)
683    #~(foo #$@(list (with-imported-modules '((foo)) #~+)
684                    (with-imported-modules '((bar)) #~-)))))
686 (test-assert "gexp-modules deletes duplicates"   ;<https://bugs.gnu.org/32966>
687   (let ((make-file (lambda ()
688                      ;; Use 'eval' to make sure we get an object that's not
689                      ;; 'eq?' nor 'equal?' due to the closures it embeds.
690                      (eval '(scheme-file "bar.scm" #~(define-module (bar)))
691                            (current-module)))))
692     (define result
693       ((@@ (guix gexp) gexp-modules)
694        (with-imported-modules `(((bar) => ,(make-file))
695                                 ((bar) => ,(make-file))
696                                 (foo) (foo))
697          #~+)))
699     (match result
700       (((('bar) '=> (? scheme-file?)) ('foo)) #t))))
702 (test-equal "gexp-modules and literal Scheme object"
703   '()
704   (gexp-modules #t))
706 (test-assertm "gexp->derivation #:modules"
707   (mlet* %store-monad
708       ((build ->  #~(begin
709                       (use-modules (guix build utils))
710                       (mkdir-p (string-append #$output "/guile/guix/nix"))
711                       #t))
712        (drv       (gexp->derivation "test-with-modules" build
713                                     #:modules '((guix build utils)))))
714     (mbegin %store-monad
715       (built-derivations (list drv))
716       (let* ((p (derivation->output-path drv))
717              (s (stat (string-append p "/guile/guix/nix"))))
718         (return (eq? (stat:type s) 'directory))))))
720 (test-assertm "gexp->derivation & with-imported-modules"
721   ;; Same test as above, but using 'with-imported-modules'.
722   (mlet* %store-monad
723       ((build ->  (with-imported-modules '((guix build utils))
724                     #~(begin
725                         (use-modules (guix build utils))
726                         (mkdir-p (string-append #$output "/guile/guix/nix"))
727                         #t)))
728        (drv       (gexp->derivation "test-with-modules" build)))
729     (mbegin %store-monad
730       (built-derivations (list drv))
731       (let* ((p (derivation->output-path drv))
732              (s (stat (string-append p "/guile/guix/nix"))))
733         (return (eq? (stat:type s) 'directory))))))
735 (test-assertm "gexp->derivation & nested with-imported-modules"
736   (mlet* %store-monad
737       ((build1 ->  (with-imported-modules '((guix build utils))
738                      #~(begin
739                          (use-modules (guix build utils))
740                          (mkdir-p (string-append #$output "/guile/guix/nix"))
741                          #t)))
742        (build2 ->  (with-imported-modules '((guix build bournish))
743                      #~(begin
744                          (use-modules (guix build bournish)
745                                       (system base compile))
746                          #+build1
747                          (call-with-output-file (string-append #$output "/b")
748                            (lambda (port)
749                              (write
750                               (read-and-compile (open-input-string "cd /foo")
751                                                 #:from %bournish-language
752                                                 #:to 'scheme)
753                               port))))))
754        (drv        (gexp->derivation "test-with-modules" build2)))
755     (mbegin %store-monad
756       (built-derivations (list drv))
757       (let* ((p (derivation->output-path drv))
758              (s (stat (string-append p "/guile/guix/nix")))
759              (b (string-append p "/b")))
760         (return (and (eq? (stat:type s) 'directory)
761                      (equal? '(chdir "/foo")
762                              (call-with-input-file b read))))))))
764 (test-assertm "gexp->derivation & with-imported-module & computed module"
765   (mlet* %store-monad
766       ((module -> (scheme-file "x" #~(;; splice!
767                                        (define-module (foo bar)
768                                          #:export (the-answer))
770                                        (define the-answer 42))
771                                #:splice? #t))
772        (build -> (with-imported-modules `(((foo bar) => ,module)
773                                           (guix build utils))
774                    #~(begin
775                        (use-modules (guix build utils)
776                                     (foo bar))
777                        mkdir-p
778                        (call-with-output-file #$output
779                          (lambda (port)
780                            (write the-answer port))))))
781        (drv      (gexp->derivation "thing" build))
782        (out ->   (derivation->output-path drv)))
783     (mbegin %store-monad
784       (built-derivations (list drv))
785       (return (= 42 (call-with-input-file out read))))))
787 (test-equal "gexp-extensions & ungexp"
788   (list sed grep)
789   ((@@ (guix gexp) gexp-extensions)
790    #~(foo #$(with-extensions (list grep) #~+)
791           #+(with-extensions (list sed)  #~-))))
793 (test-equal "gexp-extensions & ungexp-splicing"
794   (list grep sed)
795   ((@@ (guix gexp) gexp-extensions)
796    #~(foo #$@(list (with-extensions (list grep) #~+)
797                    (with-imported-modules '((foo))
798                      (with-extensions (list sed) #~-))))))
800 (test-equal "gexp-extensions and literal Scheme object"
801   '()
802   ((@@ (guix gexp) gexp-extensions) #t))
804 (test-assertm "gexp->derivation & with-extensions"
805   ;; Create a fake Guile extension and make sure it is accessible both to the
806   ;; imported modules and to the derivation build script.
807   (mlet* %store-monad
808       ((extension -> %extension-package)
809        (module -> (scheme-file "x" #~( ;; splice!
810                                       (define-module (foo)
811                                         #:use-module (hg2g)
812                                         #:export (multiply))
814                                       (define (multiply x)
815                                         (* the-answer x)))
816                                #:splice? #t))
817        (build -> (with-extensions (list extension)
818                    (with-imported-modules `((guix build utils)
819                                             ((foo) => ,module))
820                      #~(begin
821                          (use-modules (guix build utils)
822                                       (hg2g) (foo))
823                          (call-with-output-file #$output
824                            (lambda (port)
825                              (write (list the-answer (multiply 2))
826                                     port)))))))
827        (drv      (gexp->derivation "thingie" build
828                                    ;; %BOOTSTRAP-GUILE is 2.0.
829                                    #:effective-version "2.0"))
830        (out ->   (derivation->output-path drv)))
831     (mbegin %store-monad
832       (built-derivations (list drv))
833       (return (equal? '(42 84) (call-with-input-file out read))))))
835 (test-assertm "lower-gexp"
836   (mlet* %store-monad
837       ((extension -> %extension-package)
838        (extension-drv (package->derivation %extension-package))
839        (coreutils-drv (package->derivation coreutils))
840        (exp ->   (with-extensions (list extension)
841                    (with-imported-modules `((guix build utils))
842                      #~(begin
843                          (use-modules (guix build utils)
844                                       (hg2g))
845                          #$coreutils:debug
846                          mkdir-p
847                          the-answer))))
848        (lexp     (lower-gexp exp
849                              #:effective-version "2.0")))
850     (define (matching-input drv output)
851       (lambda (input)
852         (and (eq? (derivation-input-derivation input) drv)
853              (equal? (derivation-input-sub-derivations input)
854                      (list output)))))
856     (mbegin %store-monad
857       (return (and (find (matching-input extension-drv "out")
858                          (lowered-gexp-inputs (pk 'lexp lexp)))
859                    (find (matching-input coreutils-drv "debug")
860                          (lowered-gexp-inputs lexp))
861                    (member (string-append
862                             (derivation->output-path extension-drv)
863                             "/share/guile/site/2.0")
864                            (lowered-gexp-load-path lexp))
865                    (= 2 (length (lowered-gexp-load-path lexp)))
866                    (member (string-append
867                             (derivation->output-path extension-drv)
868                             "/lib/guile/2.0/site-ccache")
869                            (lowered-gexp-load-compiled-path lexp))
870                    (= 2 (length (lowered-gexp-load-compiled-path lexp)))
871                    (eq? (derivation-input-derivation (lowered-gexp-guile lexp))
872                         (%guile-for-build)))))))
874 (test-assertm "gexp->derivation #:references-graphs"
875   (mlet* %store-monad
876       ((one (text-file "one" (random-text)))
877        (two (gexp->derivation "two"
878                               #~(symlink #$one #$output:chbouib)))
879        (build -> (with-imported-modules '((guix build store-copy)
880                                           (guix progress)
881                                           (guix records)
882                                           (guix sets)
883                                           (guix build utils))
884                    #~(begin
885                        (use-modules (guix build store-copy))
886                        (with-output-to-file #$output
887                          (lambda ()
888                            (write (map store-info-item
889                                        (call-with-input-file "guile"
890                                          read-reference-graph)))))
891                        (with-output-to-file #$output:one
892                          (lambda ()
893                            (write (map store-info-item
894                                        (call-with-input-file "one"
895                                          read-reference-graph)))))
896                        (with-output-to-file #$output:two
897                          (lambda ()
898                            (write (map store-info-item
899                                        (call-with-input-file "two"
900                                          read-reference-graph))))))))
901        (drv (gexp->derivation "ref-graphs" build
902                               #:references-graphs `(("one" ,one)
903                                                     ("two" ,two "chbouib")
904                                                     ("guile" ,%bootstrap-guile))))
905        (ok? (built-derivations (list drv)))
906        (guile-drv  (package->derivation %bootstrap-guile))
907        (bash       (interned-file (search-bootstrap-binary "bash"
908                                                            (%current-system))
909                                   "bash" #:recursive? #t))
910        (g-one   -> (derivation->output-path drv "one"))
911        (g-two   -> (derivation->output-path drv "two"))
912        (g-guile -> (derivation->output-path drv)))
913     (return (and ok?
914                  (equal? (call-with-input-file g-one read) (list one))
915                  (lset= string=?
916                         (call-with-input-file g-two read)
917                         (list one (derivation->output-path two "chbouib")))
919                  ;; Note: %BOOTSTRAP-GUILE depends on the bootstrap Bash.
920                  (lset= string=?
921                         (call-with-input-file g-guile read)
922                         (list (derivation->output-path guile-drv) bash))))))
924 (test-assertm "gexp->derivation #:allowed-references"
925   (mlet %store-monad ((drv (gexp->derivation "allowed-refs"
926                                              #~(begin
927                                                  (mkdir #$output)
928                                                  (chdir #$output)
929                                                  (symlink #$output "self")
930                                                  (symlink #$%bootstrap-guile
931                                                           "guile"))
932                                              #:allowed-references
933                                              (list "out" %bootstrap-guile))))
934     (built-derivations (list drv))))
936 (test-assertm "gexp->derivation #:allowed-references, specific output"
937   (mlet* %store-monad ((in  (gexp->derivation "thing"
938                                               #~(begin
939                                                   (mkdir #$output:ok)
940                                                   (mkdir #$output:not-ok))))
941                        (drv (gexp->derivation "allowed-refs"
942                                               #~(begin
943                                                   (pk #$in:not-ok)
944                                                   (mkdir #$output)
945                                                   (chdir #$output)
946                                                   (symlink #$output "self")
947                                                   (symlink #$in:ok "ok"))
948                                               #:allowed-references
949                                               (list "out"
950                                                     (gexp-input in "ok")))))
951     (built-derivations (list drv))))
953 (test-assert "gexp->derivation #:allowed-references, disallowed"
954   (let ((drv (run-with-store %store
955                (gexp->derivation "allowed-refs"
956                                  #~(begin
957                                      (mkdir #$output)
958                                      (chdir #$output)
959                                      (symlink #$%bootstrap-guile "guile"))
960                                  #:allowed-references '()))))
961     (guard (c ((store-protocol-error? c) #t))
962       (build-derivations %store (list drv))
963       #f)))
965 (test-assertm "gexp->derivation #:disallowed-references, allowed"
966   (mlet %store-monad ((drv (gexp->derivation "disallowed-refs"
967                                              #~(begin
968                                                  (mkdir #$output)
969                                                  (chdir #$output)
970                                                  (symlink #$output "self")
971                                                  (symlink #$%bootstrap-guile
972                                                           "guile"))
973                                              #:disallowed-references '())))
974     (built-derivations (list drv))))
977 (test-assert "gexp->derivation #:disallowed-references"
978   (let ((drv (run-with-store %store
979                (gexp->derivation "disallowed-refs"
980                                  #~(begin
981                                      (mkdir #$output)
982                                      (chdir #$output)
983                                      (symlink #$%bootstrap-guile "guile"))
984                                  #:disallowed-references (list %bootstrap-guile)))))
985     (guard (c ((store-protocol-error? c) #t))
986       (build-derivations %store (list drv))
987       #f)))
989 (define shebang
990   (string-append "#!" (derivation->output-path (%guile-for-build))
991                  "/bin/guile --no-auto-compile"))
993 ;; If we're going to hit the silly shebang limit (128 chars on Linux-based
994 ;; systems), then skip the following test.
995 (test-skip (if (> (string-length shebang) 127) 2 0))
997 (test-assertm "gexp->script"
998   (mlet* %store-monad ((n ->   (random (expt 2 50)))
999                        (exp -> (gexp
1000                                 (system*
1001                                  (string-append (ungexp %bootstrap-guile)
1002                                                 "/bin/guile")
1003                                  "-c" (object->string
1004                                        '(display (expt (ungexp n) 2))))))
1005                        (drv    (gexp->script "guile-thing" exp
1006                                              #:guile %bootstrap-guile))
1007                        (out -> (derivation->output-path drv))
1008                        (done   (built-derivations (list drv))))
1009     (let* ((pipe  (open-input-pipe out))
1010            (str   (get-string-all pipe)))
1011       (return (and (zero? (close-pipe pipe))
1012                    (= (expt n 2) (string->number str)))))))
1014 (test-assert "gexp->script #:module-path"
1015   (call-with-temporary-directory
1016    (lambda (directory)
1017      (define str
1018        "Fake (guix base32) module!")
1020      (mkdir (string-append directory "/guix"))
1021      (call-with-output-file (string-append directory "/guix/base32.scm")
1022        (lambda (port)
1023          (write `(begin (define-module (guix base32))
1024                         (define-public %fake! ,str))
1025                 port)))
1027      (run-with-store %store
1028        (mlet* %store-monad ((exp -> (with-imported-modules '((guix base32))
1029                                       (gexp (begin
1030                                               (use-modules (guix base32))
1031                                               (write (list %load-path
1032                                                            %fake!))))))
1033                             (drv    (gexp->script "guile-thing" exp
1034                                                   #:guile %bootstrap-guile
1035                                                   #:module-path (list directory)))
1036                             (out -> (derivation->output-path drv))
1037                             (done   (built-derivations (list drv))))
1038          (let* ((pipe  (open-input-pipe out))
1039                 (data  (read pipe)))
1040            (return (and (zero? (close-pipe pipe))
1041                         (match data
1042                           ((load-path str*)
1043                            (and (string=? str* str)
1044                                 (not (member directory load-path)))))))))))))
1046 (test-assertm "program-file"
1047   (let* ((n      (random (expt 2 50)))
1048          (exp    (with-imported-modules '((guix build utils))
1049                    (gexp (begin
1050                            (use-modules (guix build utils))
1051                            (display (ungexp n))))))
1052          (file   (program-file "program" exp
1053                                #:guile %bootstrap-guile)))
1054     (mlet* %store-monad ((drv (lower-object file))
1055                          (out -> (derivation->output-path drv)))
1056       (mbegin %store-monad
1057         (built-derivations (list drv))
1058         (let* ((pipe  (open-input-pipe out))
1059                (str   (get-string-all pipe)))
1060           (return (and (zero? (close-pipe pipe))
1061                        (= n (string->number str)))))))))
1063 (test-assert "program-file #:module-path"
1064   (call-with-temporary-directory
1065    (lambda (directory)
1066      (define text (random-text))
1068      (call-with-output-file (string-append directory "/stupid-module.scm")
1069        (lambda (port)
1070          (write `(begin (define-module (stupid-module))
1071                         (define-public %stupid-thing ,text))
1072                 port)))
1074      (let* ((exp    (with-imported-modules '((stupid-module))
1075                       (gexp (begin
1076                               (use-modules (stupid-module))
1077                               (display %stupid-thing)))))
1078             (file   (program-file "program" exp
1079                                   #:guile %bootstrap-guile
1080                                   #:module-path (list directory))))
1081        (run-with-store %store
1082          (mlet* %store-monad ((drv (lower-object file))
1083                               (out -> (derivation->output-path drv)))
1084            (mbegin %store-monad
1085              (built-derivations (list drv))
1086              (let* ((pipe  (open-input-pipe out))
1087                     (str   (get-string-all pipe)))
1088                (return (and (zero? (close-pipe pipe))
1089                             (string=? text str)))))))))))
1091 (test-assertm "program-file & with-extensions"
1092   (let* ((exp    (with-extensions (list %extension-package)
1093                    (gexp (begin
1094                            (use-modules (hg2g))
1095                            (display the-answer)))))
1096          (file   (program-file "program" exp
1097                                #:guile %bootstrap-guile)))
1098     (mlet* %store-monad ((drv (lower-object file))
1099                          (out -> (derivation->output-path drv)))
1100       (mbegin %store-monad
1101         (built-derivations (list drv))
1102         (let* ((pipe  (open-input-pipe out))
1103                (str   (get-string-all pipe)))
1104           (return (and (zero? (close-pipe pipe))
1105                        (= 42 (string->number str)))))))))
1107 (test-assertm "scheme-file"
1108   (let* ((text   (plain-file "foo" "Hello, world!"))
1109          (scheme (scheme-file "bar" #~(list "foo" #$text))))
1110     (mlet* %store-monad ((drv  (lower-object scheme))
1111                          (text (lower-object text))
1112                          (out -> (derivation->output-path drv)))
1113       (mbegin %store-monad
1114         (built-derivations (list drv))
1115         (mlet %store-monad ((refs (references* out)))
1116           (return (and (equal? refs (list text))
1117                        (equal? `(list "foo" ,text)
1118                                (call-with-input-file out read)))))))))
1120 (test-assert "text-file*"
1121   (run-with-store %store
1122     (mlet* %store-monad
1123         ((drv  (package->derivation %bootstrap-guile))
1124          (guile -> (derivation->output-path drv))
1125          (file (text-file "bar" "This is bar."))
1126          (text (text-file* "foo"
1127                            %bootstrap-guile "/bin/guile "
1128                            (gexp-input %bootstrap-guile "out") "/bin/guile "
1129                            drv "/bin/guile "
1130                            file))
1131          (done (built-derivations (list text)))
1132          (out -> (derivation->output-path text))
1133          (refs (references* out)))
1134       ;; Make sure we get the right references and the right content.
1135       (return (and (lset= string=? refs (list guile file))
1136                    (equal? (call-with-input-file out get-string-all)
1137                            (string-append guile "/bin/guile "
1138                                           guile "/bin/guile "
1139                                           guile "/bin/guile "
1140                                           file)))))
1141     #:guile-for-build (package-derivation %store %bootstrap-guile)))
1143 (test-assertm "mixed-text-file"
1144   (mlet* %store-monad ((file ->   (mixed-text-file "mixed"
1145                                                    "export PATH="
1146                                                    %bootstrap-guile "/bin"))
1147                        (drv       (lower-object file))
1148                        (out ->    (derivation->output-path drv))
1149                        (guile-drv (package->derivation %bootstrap-guile))
1150                        (guile ->  (derivation->output-path guile-drv)))
1151     (mbegin %store-monad
1152       (built-derivations (list drv))
1153       (mlet %store-monad ((refs (references* out)))
1154         (return (and (string=? (string-append "export PATH=" guile "/bin")
1155                                (call-with-input-file out get-string-all))
1156                      (equal? refs (list guile))))))))
1158 (test-assertm "file-union"
1159   (mlet* %store-monad ((union -> (file-union "union"
1160                                              `(("a" ,(plain-file "a" "1"))
1161                                                ("b/c/d" ,(plain-file "d" "2"))
1162                                                ("e" ,(plain-file "e" "3")))))
1163                        (drv      (lower-object union))
1164                        (out ->   (derivation->output-path drv)))
1165     (define (contents=? file str)
1166       (string=? (call-with-input-file (string-append out "/" file)
1167                   get-string-all)
1168                 str))
1170     (mbegin %store-monad
1171       (built-derivations (list drv))
1172       (return (and (contents=? "a" "1")
1173                    (contents=? "b/c/d" "2")
1174                    (contents=? "e" "3"))))))
1176 (test-assert "gexp->derivation vs. %current-target-system"
1177   (let ((mval (gexp->derivation "foo"
1178                                 #~(begin
1179                                     (mkdir #$output)
1180                                     (foo #+gnu-make))
1181                                 #:target #f)))
1182     ;; The value of %CURRENT-TARGET-SYSTEM at bind-time should have no
1183     ;; influence.
1184     (parameterize ((%current-target-system "fooooo"))
1185       (derivation? (run-with-store %store mval)))))
1187 (test-assertm "lower-object"
1188   (mlet %store-monad ((drv1 (lower-object %bootstrap-guile))
1189                       (drv2 (lower-object (package-source coreutils)))
1190                       (item (lower-object (plain-file "foo" "Hello!"))))
1191     (return (and (derivation? drv1) (derivation? drv2)
1192                  (store-path? item)))))
1194 (test-assertm "lower-object, computed-file"
1195   (let* ((text     (plain-file "foo" "Hello!"))
1196          (exp      #~(begin
1197                        (mkdir #$output)
1198                        (symlink #$%bootstrap-guile
1199                                 (string-append #$output "/guile"))
1200                        (symlink #$text (string-append #$output "/text"))))
1201          (computed (computed-file "computed" exp)))
1202     (mlet* %store-monad ((text      (lower-object text))
1203                          (guile-drv (lower-object %bootstrap-guile))
1204                          (comp-drv  (lower-object computed))
1205                          (comp ->   (derivation->output-path comp-drv)))
1206       (mbegin %store-monad
1207         (built-derivations (list comp-drv))
1208         (return (and (string=? (readlink (string-append comp "/guile"))
1209                                (derivation->output-path guile-drv))
1210                      (string=? (readlink (string-append comp "/text"))
1211                                text)))))))
1213 (test-equal "lower-object, computed-file, #:system"
1214   '("mips64el-linux")
1215   (run-with-store %store
1216     (let* ((exp      #~(symlink #$coreutils #$output))
1217            (computed (computed-file "computed" exp
1218                                     #:guile %bootstrap-guile)))
1219       ;; Make sure that the SYSTEM argument to 'lower-object' is honored.
1220       (mlet* %store-monad ((drv  (lower-object computed "mips64el-linux"))
1221                            (refs (references* (derivation-file-name drv))))
1222         (return (delete-duplicates
1223                  (filter-map (lambda (file)
1224                                (and (string-suffix? ".drv" file)
1225                                     (let ((drv (read-derivation-from-file
1226                                                 file)))
1227                                       (derivation-system drv))))
1228                              (cons (derivation-file-name drv)
1229                                    refs))))))))
1231 (test-assert "lower-object & gexp-input-error?"
1232   (guard (c ((gexp-input-error? c)
1233              (gexp-error-invalid-input c)))
1234     (run-with-store %store
1235       (lower-object (current-module))
1236       #:guile-for-build (%guile-for-build))))
1238 (test-assert "printer"
1239   (string-match "^#<gexp \\(string-append .*#<package coreutils.*\
1240  \"/bin/uname\"\\) [[:xdigit:]]+>$"
1241                 (with-output-to-string
1242                   (lambda ()
1243                     (write
1244                      (gexp (string-append (ungexp coreutils)
1245                                           "/bin/uname")))))))
1247 (test-assert "printer vs. ungexp-splicing"
1248   (string-match "^#<gexp .* [[:xdigit:]]+>$"
1249                 (with-output-to-string
1250                   (lambda ()
1251                     ;; #~(begin #$@#~())
1252                     (write
1253                      (gexp (begin (ungexp-splicing (gexp ())))))))))
1255 (test-equal "sugar"
1256   '(gexp (foo (ungexp bar) (ungexp baz "out")
1257               (ungexp (chbouib 42))
1258               (ungexp-splicing (list x y z))
1259               (ungexp-native foo) (ungexp-native foo "out")
1260               (ungexp-native (chbouib 42))
1261               (ungexp-native-splicing (list x y z))))
1262   '#~(foo #$bar #$baz:out #$(chbouib 42) #$@(list x y z)
1263           #+foo #+foo:out #+(chbouib 42) #+@(list x y z)))
1265 (test-end "gexp")
1267 ;; Local Variables:
1268 ;; eval: (put 'test-assertm 'scheme-indent-function 1)
1269 ;; End: