store: Memoize 'add-to-store' based on the result of 'lstat', not 'stat'.
[jackhill/guix/guix.git] / tests / gexp.scm
CommitLineData
21b679f6 1;;; GNU Guix --- Functional package management for GNU
462a3fa3 2;;; Copyright © 2014, 2015 Ludovic Courtès <ludo@gnu.org>
21b679f6
LC
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/>.
18
19(define-module (test-gexp)
20 #:use-module (guix store)
21 #:use-module (guix monads)
22 #:use-module (guix gexp)
23 #:use-module (guix derivations)
79c0c8cd 24 #:use-module (guix packages)
c1bc358f 25 #:use-module (guix tests)
21b679f6
LC
26 #:use-module (gnu packages)
27 #:use-module (gnu packages base)
28 #:use-module (gnu packages bootstrap)
29 #:use-module (srfi srfi-1)
c8351d9a 30 #:use-module (srfi srfi-34)
21b679f6
LC
31 #:use-module (srfi srfi-64)
32 #:use-module (rnrs io ports)
33 #:use-module (ice-9 match)
2cf0ea0d 34 #:use-module (ice-9 regex)
21b679f6
LC
35 #:use-module (ice-9 popen))
36
37;; Test the (guix gexp) module.
38
39(define %store
c1bc358f 40 (open-connection-for-tests))
21b679f6
LC
41
42;; For white-box testing.
1f976033
LC
43(define (gexp-inputs x)
44 ((@@ (guix gexp) gexp-inputs) x))
45(define (gexp-native-inputs x)
46 ((@@ (guix gexp) gexp-native-inputs) x))
47(define (gexp-outputs x)
48 ((@@ (guix gexp) gexp-outputs) x))
49(define (gexp->sexp . x)
50 (apply (@@ (guix gexp) gexp->sexp) x))
21b679f6 51
667b2508 52(define* (gexp->sexp* exp #:optional target)
68a61e9f 53 (run-with-store %store (gexp->sexp exp
68a61e9f 54 #:target target)
c1bc358f 55 #:guile-for-build (%guile-for-build)))
21b679f6
LC
56
57(define-syntax-rule (test-assertm name exp)
58 (test-assert name
59 (run-with-store %store exp
c1bc358f 60 #:guile-for-build (%guile-for-build))))
21b679f6
LC
61
62\f
63(test-begin "gexp")
64
65(test-equal "no refs"
66 '(display "hello!")
67 (let ((exp (gexp (display "hello!"))))
68 (and (gexp? exp)
69 (null? (gexp-inputs exp))
70 (gexp->sexp* exp))))
71
72(test-equal "unquote"
73 '(display `(foo ,(+ 2 3)))
74 (let ((exp (gexp (display `(foo ,(+ 2 3))))))
75 (and (gexp? exp)
76 (null? (gexp-inputs exp))
77 (gexp->sexp* exp))))
78
79(test-assert "one input package"
80 (let ((exp (gexp (display (ungexp coreutils)))))
81 (and (gexp? exp)
82 (match (gexp-inputs exp)
83 (((p "out"))
84 (eq? p coreutils)))
85 (equal? `(display ,(derivation->output-path
86 (package-derivation %store coreutils)))
87 (gexp->sexp* exp)))))
88
79c0c8cd
LC
89(test-assert "one input origin"
90 (let ((exp (gexp (display (ungexp (package-source coreutils))))))
91 (and (gexp? exp)
92 (match (gexp-inputs exp)
93 (((o "out"))
94 (eq? o (package-source coreutils))))
95 (equal? `(display ,(derivation->output-path
96 (package-source-derivation
97 %store (package-source coreutils))))
98 (gexp->sexp* exp)))))
99
d9ae938f
LC
100(test-assert "one local file"
101 (let* ((file (search-path %load-path "guix.scm"))
102 (local (local-file file))
103 (exp (gexp (display (ungexp local))))
020f3e41 104 (intd (add-to-store %store (basename file) #f
d9ae938f
LC
105 "sha256" file)))
106 (and (gexp? exp)
107 (match (gexp-inputs exp)
108 (((x "out"))
109 (eq? x local)))
110 (equal? `(display ,intd) (gexp->sexp* exp)))))
111
558e8b11
LC
112(test-assert "one plain file"
113 (let* ((file (plain-file "hi" "Hello, world!"))
114 (exp (gexp (display (ungexp file))))
115 (expected (add-text-to-store %store "hi" "Hello, world!")))
116 (and (gexp? exp)
117 (match (gexp-inputs exp)
118 (((x "out"))
119 (eq? x file)))
120 (equal? `(display ,expected) (gexp->sexp* exp)))))
121
21b679f6
LC
122(test-assert "same input twice"
123 (let ((exp (gexp (begin
124 (display (ungexp coreutils))
125 (display (ungexp coreutils))))))
126 (and (gexp? exp)
127 (match (gexp-inputs exp)
128 (((p "out"))
129 (eq? p coreutils)))
130 (let ((e `(display ,(derivation->output-path
131 (package-derivation %store coreutils)))))
132 (equal? `(begin ,e ,e) (gexp->sexp* exp))))))
133
134(test-assert "two input packages, one derivation, one file"
135 (let* ((drv (build-expression->derivation
136 %store "foo" 'bar
137 #:guile-for-build (package-derivation %store %bootstrap-guile)))
138 (txt (add-text-to-store %store "foo" "Hello, world!"))
139 (exp (gexp (begin
140 (display (ungexp coreutils))
141 (display (ungexp %bootstrap-guile))
142 (display (ungexp drv))
143 (display (ungexp txt))))))
144 (define (match-input thing)
145 (match-lambda
146 ((drv-or-pkg _ ...)
147 (eq? thing drv-or-pkg))))
148
149 (and (gexp? exp)
150 (= 4 (length (gexp-inputs exp)))
151 (every (lambda (input)
152 (find (match-input input) (gexp-inputs exp)))
153 (list drv coreutils %bootstrap-guile txt))
154 (let ((e0 `(display ,(derivation->output-path
155 (package-derivation %store coreutils))))
156 (e1 `(display ,(derivation->output-path
157 (package-derivation %store %bootstrap-guile))))
158 (e2 `(display ,(derivation->output-path drv)))
159 (e3 `(display ,txt)))
160 (equal? `(begin ,e0 ,e1 ,e2 ,e3) (gexp->sexp* exp))))))
161
667b2508
LC
162(test-assert "ungexp + ungexp-native"
163 (let* ((exp (gexp (list (ungexp-native %bootstrap-guile)
164 (ungexp coreutils)
165 (ungexp-native glibc)
166 (ungexp binutils))))
167 (target "mips64el-linux")
168 (guile (derivation->output-path
169 (package-derivation %store %bootstrap-guile)))
170 (cu (derivation->output-path
171 (package-cross-derivation %store coreutils target)))
172 (libc (derivation->output-path
173 (package-derivation %store glibc)))
174 (bu (derivation->output-path
175 (package-cross-derivation %store binutils target))))
176 (and (lset= equal?
177 `((,%bootstrap-guile "out") (,glibc "out"))
178 (gexp-native-inputs exp))
179 (lset= equal?
180 `((,coreutils "out") (,binutils "out"))
181 (gexp-inputs exp))
182 (equal? `(list ,guile ,cu ,libc ,bu)
183 (gexp->sexp* exp target)))))
184
1123759b
LC
185(test-equal "ungexp + ungexp-native, nested"
186 (list `((,%bootstrap-guile "out")) '<> `((,coreutils "out")))
187 (let* ((exp (gexp (list (ungexp-native (gexp (ungexp coreutils)))
188 (ungexp %bootstrap-guile)))))
189 (list (gexp-inputs exp) '<> (gexp-native-inputs exp))))
190
21b679f6
LC
191(test-assert "input list"
192 (let ((exp (gexp (display
193 '(ungexp (list %bootstrap-guile coreutils)))))
194 (guile (derivation->output-path
195 (package-derivation %store %bootstrap-guile)))
196 (cu (derivation->output-path
197 (package-derivation %store coreutils))))
198 (and (lset= equal?
199 `((,%bootstrap-guile "out") (,coreutils "out"))
200 (gexp-inputs exp))
201 (equal? `(display '(,guile ,cu))
202 (gexp->sexp* exp)))))
203
667b2508
LC
204(test-assert "input list + ungexp-native"
205 (let* ((target "mips64el-linux")
206 (exp (gexp (display
207 (cons '(ungexp-native (list %bootstrap-guile coreutils))
208 '(ungexp (list glibc binutils))))))
209 (guile (derivation->output-path
210 (package-derivation %store %bootstrap-guile)))
211 (cu (derivation->output-path
212 (package-derivation %store coreutils)))
213 (xlibc (derivation->output-path
214 (package-cross-derivation %store glibc target)))
215 (xbu (derivation->output-path
216 (package-cross-derivation %store binutils target))))
217 (and (lset= equal?
218 `((,%bootstrap-guile "out") (,coreutils "out"))
219 (gexp-native-inputs exp))
220 (lset= equal?
221 `((,glibc "out") (,binutils "out"))
222 (gexp-inputs exp))
223 (equal? `(display (cons '(,guile ,cu) '(,xlibc ,xbu)))
224 (gexp->sexp* exp target)))))
225
21b679f6 226(test-assert "input list splicing"
a482cfdc 227 (let* ((inputs (list (gexp-input glibc "debug") %bootstrap-guile))
21b679f6
LC
228 (outputs (list (derivation->output-path
229 (package-derivation %store glibc)
230 "debug")
231 (derivation->output-path
232 (package-derivation %store %bootstrap-guile))))
233 (exp (gexp (list (ungexp-splicing (cons (+ 2 3) inputs))))))
234 (and (lset= equal?
235 `((,glibc "debug") (,%bootstrap-guile "out"))
236 (gexp-inputs exp))
237 (equal? (gexp->sexp* exp)
238 `(list ,@(cons 5 outputs))))))
239
667b2508 240(test-assert "input list splicing + ungexp-native-splicing"
0dbea56b
LC
241 (let* ((inputs (list (gexp-input glibc "debug") %bootstrap-guile))
242 (exp (gexp (list (ungexp-native-splicing (cons (+ 2 3) inputs))))))
243 (and (lset= equal?
244 `((,glibc "debug") (,%bootstrap-guile "out"))
245 (gexp-native-inputs exp))
246 (null? (gexp-inputs exp))
247 (equal? (gexp->sexp* exp) ;native
248 (gexp->sexp* exp "mips64el-linux")))))
249
4b23c466
LC
250(test-equal "output list"
251 2
252 (let ((exp (gexp (begin (mkdir (ungexp output))
253 (mkdir (ungexp output "bar"))))))
254 (length (gexp-outputs exp)))) ;XXX: <output-ref> is private
255
256(test-assert "output list, combined gexps"
257 (let* ((exp0 (gexp (mkdir (ungexp output))))
258 (exp1 (gexp (mkdir (ungexp output "foo"))))
259 (exp2 (gexp (begin (display "hi!") (ungexp exp0) (ungexp exp1)))))
260 (and (lset= equal?
261 (append (gexp-outputs exp0) (gexp-outputs exp1))
262 (gexp-outputs exp2))
263 (= 2 (length (gexp-outputs exp2))))))
264
7e75a673
LC
265(test-equal "output list, combined gexps, duplicate output"
266 1
267 (let* ((exp0 (gexp (mkdir (ungexp output))))
268 (exp1 (gexp (begin (mkdir (ungexp output)) (ungexp exp0))))
269 (exp2 (gexp (begin (mkdir (ungexp output)) (ungexp exp1)))))
270 (length (gexp-outputs exp2))))
271
f9efe568
LC
272(test-assert "output list + ungexp-splicing list, combined gexps"
273 (let* ((exp0 (gexp (mkdir (ungexp output))))
274 (exp1 (gexp (mkdir (ungexp output "foo"))))
275 (exp2 (gexp (begin (display "hi!")
276 (ungexp-splicing (list exp0 exp1))))))
277 (and (lset= equal?
278 (append (gexp-outputs exp0) (gexp-outputs exp1))
279 (gexp-outputs exp2))
280 (= 2 (length (gexp-outputs exp2))))))
281
21b679f6
LC
282(test-assertm "gexp->file"
283 (mlet* %store-monad ((exp -> (gexp (display (ungexp %bootstrap-guile))))
284 (guile (package-file %bootstrap-guile))
285 (sexp (gexp->sexp exp))
286 (drv (gexp->file "foo" exp))
287 (out -> (derivation->output-path drv))
288 (done (built-derivations (list drv)))
289 (refs ((store-lift references) out)))
290 (return (and (equal? sexp (call-with-input-file out read))
291 (equal? (list guile) refs)))))
292
293(test-assertm "gexp->derivation"
294 (mlet* %store-monad ((file (text-file "foo" "Hello, world!"))
295 (exp -> (gexp
296 (begin
297 (mkdir (ungexp output))
298 (chdir (ungexp output))
299 (symlink
300 (string-append (ungexp %bootstrap-guile)
301 "/bin/guile")
302 "foo")
303 (symlink (ungexp file)
304 (ungexp output "2nd")))))
305 (drv (gexp->derivation "foo" exp))
306 (out -> (derivation->output-path drv))
307 (out2 -> (derivation->output-path drv "2nd"))
308 (done (built-derivations (list drv)))
309 (refs ((store-lift references) out))
310 (refs2 ((store-lift references) out2))
311 (guile (package-file %bootstrap-guile "bin/guile")))
312 (return (and (string=? (readlink (string-append out "/foo")) guile)
313 (string=? (readlink out2) file)
314 (equal? refs (list (dirname (dirname guile))))
315 (equal? refs2 (list file))))))
316
ce45eb4c
LC
317(test-assertm "gexp->derivation vs. grafts"
318 (mlet* %store-monad ((p0 -> (dummy-package "dummy"
319 (arguments
320 '(#:implicit-inputs? #f))))
321 (r -> (package (inherit p0) (name "DuMMY")))
322 (p1 -> (package (inherit p0) (replacement r)))
323 (exp0 -> (gexp (frob (ungexp p0) (ungexp output))))
324 (exp1 -> (gexp (frob (ungexp p1) (ungexp output))))
325 (void (set-guile-for-build %bootstrap-guile))
326 (drv0 (gexp->derivation "t" exp0))
327 (drv1 (gexp->derivation "t" exp1))
328 (drv1* (gexp->derivation "t" exp1 #:graft? #f)))
329 (return (and (not (string=? (derivation->output-path drv0)
330 (derivation->output-path drv1)))
331 (string=? (derivation->output-path drv0)
332 (derivation->output-path drv1*))))))
333
21b679f6
LC
334(test-assertm "gexp->derivation, composed gexps"
335 (mlet* %store-monad ((exp0 -> (gexp (begin
336 (mkdir (ungexp output))
337 (chdir (ungexp output)))))
338 (exp1 -> (gexp (symlink
339 (string-append (ungexp %bootstrap-guile)
340 "/bin/guile")
341 "foo")))
342 (exp -> (gexp (begin (ungexp exp0) (ungexp exp1))))
343 (drv (gexp->derivation "foo" exp))
344 (out -> (derivation->output-path drv))
345 (done (built-derivations (list drv)))
346 (guile (package-file %bootstrap-guile "bin/guile")))
347 (return (string=? (readlink (string-append out "/foo"))
348 guile))))
349
5d098459
LC
350(test-assertm "gexp->derivation, default system"
351 ;; The default system should be the one at '>>=' time, not the one at
352 ;; invocation time. See <http://bugs.gnu.org/18002>.
353 (let ((system (%current-system))
354 (mdrv (parameterize ((%current-system "foobar64-linux"))
355 (gexp->derivation "foo"
356 (gexp
357 (mkdir (ungexp output)))))))
358 (mlet %store-monad ((drv mdrv))
359 (return (string=? system (derivation-system drv))))))
360
d9ae938f
LC
361(test-assertm "gexp->derivation, local-file"
362 (mlet* %store-monad ((file -> (search-path %load-path "guix.scm"))
020f3e41 363 (intd (interned-file file #:recursive? #f))
d9ae938f
LC
364 (local -> (local-file file))
365 (exp -> (gexp (begin
366 (stat (ungexp local))
367 (symlink (ungexp local)
368 (ungexp output)))))
369 (drv (gexp->derivation "local-file" exp)))
370 (mbegin %store-monad
371 (built-derivations (list drv))
372 (return (string=? (readlink (derivation->output-path drv))
373 intd)))))
374
68a61e9f
LC
375(test-assertm "gexp->derivation, cross-compilation"
376 (mlet* %store-monad ((target -> "mips64el-linux")
377 (exp -> (gexp (list (ungexp coreutils)
378 (ungexp output))))
379 (xdrv (gexp->derivation "foo" exp
380 #:target target))
381 (refs ((store-lift references)
382 (derivation-file-name xdrv)))
383 (xcu (package->cross-derivation coreutils
384 target))
385 (cu (package->derivation coreutils)))
386 (return (and (member (derivation-file-name xcu) refs)
387 (not (member (derivation-file-name cu) refs))))))
388
667b2508
LC
389(test-assertm "gexp->derivation, ungexp-native"
390 (mlet* %store-monad ((target -> "mips64el-linux")
391 (exp -> (gexp (list (ungexp-native coreutils)
392 (ungexp output))))
393 (xdrv (gexp->derivation "foo" exp
394 #:target target))
395 (drv (gexp->derivation "foo" exp)))
396 (return (string=? (derivation-file-name drv)
397 (derivation-file-name xdrv)))))
398
399(test-assertm "gexp->derivation, ungexp + ungexp-native"
400 (mlet* %store-monad ((target -> "mips64el-linux")
401 (exp -> (gexp (list (ungexp-native coreutils)
402 (ungexp glibc)
403 (ungexp output))))
404 (xdrv (gexp->derivation "foo" exp
405 #:target target))
406 (refs ((store-lift references)
407 (derivation-file-name xdrv)))
408 (xglibc (package->cross-derivation glibc target))
409 (cu (package->derivation coreutils)))
410 (return (and (member (derivation-file-name cu) refs)
411 (member (derivation-file-name xglibc) refs)))))
412
413(test-assertm "gexp->derivation, ungexp-native + composed gexps"
414 (mlet* %store-monad ((target -> "mips64el-linux")
415 (exp0 -> (gexp (list 1 2
416 (ungexp coreutils))))
417 (exp -> (gexp (list 0 (ungexp-native exp0))))
418 (xdrv (gexp->derivation "foo" exp
419 #:target target))
420 (drv (gexp->derivation "foo" exp)))
421 (return (string=? (derivation-file-name drv)
422 (derivation-file-name xdrv)))))
423
6fd1a796
LC
424(test-assertm "gexp->derivation, store copy"
425 (let ((build-one #~(call-with-output-file #$output
426 (lambda (port)
427 (display "This is the one." port))))
428 (build-two (lambda (one)
429 #~(begin
430 (mkdir #$output)
431 (symlink #$one (string-append #$output "/one"))
432 (call-with-output-file (string-append #$output "/two")
433 (lambda (port)
434 (display "This is the second one." port))))))
b53833b2
LC
435 (build-drv #~(begin
436 (use-modules (guix build store-copy))
6fd1a796 437
b53833b2
LC
438 (mkdir #$output)
439 (populate-store '("graph") #$output))))
6fd1a796
LC
440 (mlet* %store-monad ((one (gexp->derivation "one" build-one))
441 (two (gexp->derivation "two" (build-two one)))
b53833b2 442 (drv (gexp->derivation "store-copy" build-drv
6fd1a796 443 #:references-graphs
b53833b2 444 `(("graph" ,two))
6fd1a796
LC
445 #:modules
446 '((guix build store-copy)
447 (guix build utils))))
448 (ok? (built-derivations (list drv)))
449 (out -> (derivation->output-path drv)))
450 (let ((one (derivation->output-path one))
451 (two (derivation->output-path two)))
452 (return (and ok?
453 (file-exists? (string-append out "/" one))
454 (file-exists? (string-append out "/" two))
455 (file-exists? (string-append out "/" two "/two"))
456 (string=? (readlink (string-append out "/" two "/one"))
457 one)))))))
458
aa72d9af
LC
459(test-assertm "imported-files"
460 (mlet* %store-monad
461 ((files -> `(("x" . ,(search-path %load-path "ice-9/q.scm"))
462 ("a/b/c" . ,(search-path %load-path
463 "guix/derivations.scm"))
464 ("p/q" . ,(search-path %load-path "guix.scm"))
465 ("p/z" . ,(search-path %load-path "guix/store.scm"))))
466 (drv (imported-files files)))
467 (mbegin %store-monad
468 (built-derivations (list drv))
469 (let ((dir (derivation->output-path drv)))
470 (return
471 (every (match-lambda
472 ((path . source)
473 (equal? (call-with-input-file (string-append dir "/" path)
474 get-bytevector-all)
475 (call-with-input-file source
476 get-bytevector-all))))
477 files))))))
478
479(test-assertm "gexp->derivation #:modules"
480 (mlet* %store-monad
481 ((build -> #~(begin
482 (use-modules (guix build utils))
483 (mkdir-p (string-append #$output "/guile/guix/nix"))
484 #t))
485 (drv (gexp->derivation "test-with-modules" build
486 #:modules '((guix build utils)))))
487 (mbegin %store-monad
488 (built-derivations (list drv))
489 (let* ((p (derivation->output-path drv))
490 (s (stat (string-append p "/guile/guix/nix"))))
491 (return (eq? (stat:type s) 'directory))))))
492
b53833b2
LC
493(test-assertm "gexp->derivation #:references-graphs"
494 (mlet* %store-monad
495 ((one (text-file "one" "hello, world"))
496 (two (gexp->derivation "two"
497 #~(symlink #$one #$output:chbouib)))
498 (drv (gexp->derivation "ref-graphs"
499 #~(begin
500 (use-modules (guix build store-copy))
501 (with-output-to-file #$output
502 (lambda ()
503 (write (call-with-input-file "guile"
504 read-reference-graph))))
505 (with-output-to-file #$output:one
506 (lambda ()
507 (write (call-with-input-file "one"
508 read-reference-graph))))
509 (with-output-to-file #$output:two
510 (lambda ()
511 (write (call-with-input-file "two"
512 read-reference-graph)))))
513 #:references-graphs `(("one" ,one)
514 ("two" ,two "chbouib")
515 ("guile" ,%bootstrap-guile))
516 #:modules '((guix build store-copy)
517 (guix build utils))))
518 (ok? (built-derivations (list drv)))
519 (guile-drv (package->derivation %bootstrap-guile))
520 (g-one -> (derivation->output-path drv "one"))
521 (g-two -> (derivation->output-path drv "two"))
522 (g-guile -> (derivation->output-path drv)))
523 (return (and ok?
524 (equal? (call-with-input-file g-one read) (list one))
525 (equal? (call-with-input-file g-two read)
526 (list one (derivation->output-path two "chbouib")))
527 (equal? (call-with-input-file g-guile read)
528 (list (derivation->output-path guile-drv)))))))
529
c8351d9a
LC
530(test-assertm "gexp->derivation #:allowed-references"
531 (mlet %store-monad ((drv (gexp->derivation "allowed-refs"
532 #~(begin
533 (mkdir #$output)
534 (chdir #$output)
535 (symlink #$output "self")
536 (symlink #$%bootstrap-guile
537 "guile"))
538 #:allowed-references
539 (list "out" %bootstrap-guile))))
540 (built-derivations (list drv))))
541
accb682c
LC
542(test-assertm "gexp->derivation #:allowed-references, specific output"
543 (mlet* %store-monad ((in (gexp->derivation "thing"
544 #~(begin
545 (mkdir #$output:ok)
546 (mkdir #$output:not-ok))))
547 (drv (gexp->derivation "allowed-refs"
548 #~(begin
549 (pk #$in:not-ok)
550 (mkdir #$output)
551 (chdir #$output)
552 (symlink #$output "self")
553 (symlink #$in:ok "ok"))
554 #:allowed-references
555 (list "out"
556 (gexp-input in "ok")))))
557 (built-derivations (list drv))))
558
c8351d9a
LC
559(test-assert "gexp->derivation #:allowed-references, disallowed"
560 (let ((drv (run-with-store %store
561 (gexp->derivation "allowed-refs"
562 #~(begin
563 (mkdir #$output)
564 (chdir #$output)
565 (symlink #$%bootstrap-guile "guile"))
566 #:allowed-references '()))))
567 (guard (c ((nix-protocol-error? c) #t))
568 (build-derivations %store (list drv))
569 #f)))
570
c17b5ab4 571(define shebang
c1bc358f 572 (string-append "#!" (derivation->output-path (%guile-for-build))
c17b5ab4
LC
573 "/bin/guile --no-auto-compile"))
574
575;; If we're going to hit the silly shebang limit (128 chars on Linux-based
576;; systems), then skip the following test.
577(test-skip (if (> (string-length shebang) 127) 1 0))
578
21b679f6
LC
579(test-assertm "gexp->script"
580 (mlet* %store-monad ((n -> (random (expt 2 50)))
581 (exp -> (gexp
582 (system*
583 (string-append (ungexp %bootstrap-guile)
584 "/bin/guile")
585 "-c" (object->string
586 '(display (expt (ungexp n) 2))))))
587 (drv (gexp->script "guile-thing" exp
588 #:guile %bootstrap-guile))
589 (out -> (derivation->output-path drv))
590 (done (built-derivations (list drv))))
591 (let* ((pipe (open-input-pipe out))
592 (str (get-string-all pipe)))
593 (return (and (zero? (close-pipe pipe))
594 (= (expt n 2) (string->number str)))))))
595
462a3fa3
LC
596(test-assert "text-file*"
597 (let ((references (store-lift references)))
598 (run-with-store %store
599 (mlet* %store-monad
600 ((drv (package->derivation %bootstrap-guile))
601 (guile -> (derivation->output-path drv))
602 (file (text-file "bar" "This is bar."))
603 (text (text-file* "foo"
604 %bootstrap-guile "/bin/guile "
a482cfdc 605 (gexp-input %bootstrap-guile "out") "/bin/guile "
462a3fa3
LC
606 drv "/bin/guile "
607 file))
608 (done (built-derivations (list text)))
609 (out -> (derivation->output-path text))
610 (refs (references out)))
611 ;; Make sure we get the right references and the right content.
612 (return (and (lset= string=? refs (list guile file))
613 (equal? (call-with-input-file out get-string-all)
614 (string-append guile "/bin/guile "
615 guile "/bin/guile "
616 guile "/bin/guile "
617 file)))))
618 #:guile-for-build (package-derivation %store %bootstrap-guile))))
619
2cf0ea0d
LC
620(test-assert "printer"
621 (string-match "^#<gexp \\(string-append .*#<package coreutils.*\
622 \"/bin/uname\"\\) [[:xdigit:]]+>$"
623 (with-output-to-string
624 (lambda ()
625 (write
626 (gexp (string-append (ungexp coreutils)
627 "/bin/uname")))))))
628
629(test-assert "printer vs. ungexp-splicing"
630 (string-match "^#<gexp .* [[:xdigit:]]+>$"
631 (with-output-to-string
632 (lambda ()
633 ;; #~(begin #$@#~())
634 (write
635 (gexp (begin (ungexp-splicing (gexp ())))))))))
636
21b679f6
LC
637(test-equal "sugar"
638 '(gexp (foo (ungexp bar) (ungexp baz "out")
639 (ungexp (chbouib 42))
667b2508
LC
640 (ungexp-splicing (list x y z))
641 (ungexp-native foo) (ungexp-native foo "out")
642 (ungexp-native (chbouib 42))
643 (ungexp-native-splicing (list x y z))))
644 '#~(foo #$bar #$baz:out #$(chbouib 42) #$@(list x y z)
645 #+foo #+foo:out #+(chbouib 42) #+@(list x y z)))
21b679f6
LC
646
647(test-end "gexp")
648
649\f
650(exit (= (test-runner-fail-count (test-runner-current)) 0))
651
652;; Local Variables:
653;; eval: (put 'test-assertm 'scheme-indent-function 1)
654;; End: