Add `base16-string->bytevector'.
[jackhill/guix/guix.git] / tests / derivations.scm
CommitLineData
341c6fdd
LC
1;;; Guix --- Nix package management from Guile. -*- coding: utf-8 -*-
2;;; Copyright (C) 2012 Ludovic Courtès <ludo@gnu.org>
3;;;
4;;; This file is part of Guix.
5;;;
6;;; 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;;; 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 Guix. If not, see <http://www.gnu.org/licenses/>.
18
19
20(define-module (test-derivations)
21 #:use-module (guix derivations)
26bbbb95 22 #:use-module (guix store)
de4c3f26 23 #:use-module (guix utils)
fb3eec83 24 #:use-module (srfi srfi-11)
341c6fdd
LC
25 #:use-module (srfi srfi-26)
26 #:use-module (srfi srfi-64)
fb3eec83
LC
27 #:use-module (rnrs io ports)
28 #:use-module (ice-9 rdelim))
341c6fdd 29
26bbbb95
LC
30(define %store
31 (false-if-exception (open-connection)))
32
341c6fdd
LC
33(test-begin "derivations")
34
35(test-assert "parse & export"
33594aa4
LC
36 (let* ((f (search-path %load-path "tests/test.drv"))
37 (b1 (call-with-input-file f get-bytevector-all))
341c6fdd
LC
38 (d1 (read-derivation (open-bytevector-input-port b1)))
39 (b2 (call-with-bytevector-output-port (cut write-derivation d1 <>)))
40 (d2 (read-derivation (open-bytevector-input-port b2))))
41 (and (equal? b1 b2)
42 (equal? d1 d2))))
43
de4c3f26 44(test-skip (if %store 0 3))
26bbbb95
LC
45
46(test-assert "derivation with no inputs"
47 (let ((builder (add-text-to-store %store "my-builder.sh"
48 "#!/bin/sh\necho hello, world\n"
49 '())))
50 (store-path? (derivation %store "foo" "x86_64-linux" builder
51 '() '(("HOME" . "/homeless")) '()))))
52
fb3eec83
LC
53(test-assert "build derivation with 1 source"
54 (let*-values (((builder)
55 (add-text-to-store %store "my-builder.sh"
de4c3f26 56 "echo hello, world > \"$out\"\n"
fb3eec83
LC
57 '()))
58 ((drv-path drv)
59 (derivation %store "foo" "x86_64-linux"
60 "/bin/sh" `(,builder)
61 '(("HOME" . "/homeless"))
62 `((,builder))))
63 ((succeeded?)
64 (build-derivations %store (list drv-path))))
65 (and succeeded?
66 (let ((path (derivation-output-path
67 (assoc-ref (derivation-outputs drv) "out"))))
68 (string=? (call-with-input-file path read-line)
69 "hello, world")))))
70
de4c3f26
LC
71\f
72(define %coreutils
73 (false-if-exception (nixpkgs-derivation "coreutils")))
74
75(test-skip (if %coreutils 0 1))
76
77(test-assert "build derivation with coreutils"
78 (let* ((builder
79 (add-text-to-store %store "build-with-coreutils.sh"
80 "echo $PATH ; mkdir --version ; mkdir $out ; touch $out/good"
81 '()))
82 (drv-path
83 (derivation %store "foo" "x86_64-linux"
84 "/bin/sh" `(,builder)
85 `(("PATH" .
86 ,(string-append
87 (derivation-path->output-path %coreutils)
88 "/bin")))
89 `((,builder)
90 (,%coreutils))))
91 (succeeded?
92 (build-derivations %store (list drv-path))))
93 (and succeeded?
94 (let ((p (derivation-path->output-path drv-path)))
95 (file-exists? (string-append p "/good"))))))
96
d9085c23
LC
97(test-skip (if (%guile-for-build) 0 2))
98
99(test-assert "build-expression->derivation without inputs"
100 (let* ((builder '(begin
101 (mkdir %output)
102 (call-with-output-file (string-append %output "/test")
103 (lambda (p)
104 (display '(hello guix) p)))))
105 (drv-path (build-expression->derivation %store "goo" "x86_64-linux"
106 builder '()))
107 (succeeded? (build-derivations %store (list drv-path))))
108 (and succeeded?
109 (let ((p (derivation-path->output-path drv-path)))
110 (equal? '(hello guix)
111 (call-with-input-file (string-append p "/test") read))))))
112
113(test-assert "build-expression->derivation with one input"
114 (let* ((builder '(call-with-output-file %output
115 (lambda (p)
116 (let ((cu (assoc-ref %build-inputs "cu")))
117 (close 1)
118 (dup2 (port->fdes p) 1)
119 (execl (string-append cu "/bin/uname")
120 "uname" "-a")))))
121 (drv-path (build-expression->derivation %store "uname" "x86_64-linux"
122 builder
123 `(("cu" . ,%coreutils))))
124 (succeeded? (build-derivations %store (list drv-path))))
125 (and succeeded?
126 (let ((p (derivation-path->output-path drv-path)))
127 (string-contains (call-with-input-file p read-line) "GNU")))))
128
341c6fdd
LC
129(test-end)
130
131\f
132(exit (= (test-runner-fail-count (test-runner-current)) 0))
133
134;;; Local Variables:
135;;; eval: (put 'test-assert 'scheme-indent-function 1)
136;;; End: