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