substitute-binary: Support decompression from non-file ports.
[jackhill/guix/guix.git] / tests / packages.scm
CommitLineData
233e7676 1;;; GNU Guix --- Functional package management for GNU
e509d152 2;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org>
e3ce5d70 3;;;
233e7676 4;;; This file is part of GNU Guix.
e3ce5d70 5;;;
233e7676 6;;; GNU Guix is free software; you can redistribute it and/or modify it
e3ce5d70
LC
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;;;
233e7676 11;;; GNU Guix is distributed in the hope that it will be useful, but
e3ce5d70
LC
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
233e7676 17;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
e3ce5d70
LC
18
19
20(define-module (test-packages)
21 #:use-module (guix store)
22 #:use-module (guix utils)
23 #:use-module (guix derivations)
24 #:use-module (guix packages)
be13fbfa 25 #:use-module (guix build-system trivial)
a3d73f59 26 #:use-module (guix build-system gnu)
59a43334 27 #:use-module (gnu packages)
1ffa7090
LC
28 #:use-module (gnu packages base)
29 #:use-module (gnu packages bootstrap)
e509d152 30 #:use-module (srfi srfi-11)
6b1891b0
LC
31 #:use-module (srfi srfi-26)
32 #:use-module (srfi srfi-64)
860a6f1a 33 #:use-module (rnrs io ports)
6b1891b0 34 #:use-module (ice-9 match))
e3ce5d70
LC
35
36;; Test the high-level packaging layer.
37
38(define %store
39 (false-if-exception (open-connection)))
40
81dbd783
LC
41(when %store
42 ;; Make sure we build everything by ourselves.
43 (set-build-options %store #:use-substitutes? #f))
44
14da91e2 45\f
e3ce5d70
LC
46(test-begin "packages")
47
a3d73f59
LC
48(define-syntax-rule (dummy-package name* extra-fields ...)
49 (package (name name*) (version "0") (source #f)
50 (build-system gnu-build-system)
d45122f5 51 (synopsis #f) (description #f)
1fb78cb2 52 (home-page #f) (license #f)
a3d73f59
LC
53 extra-fields ...))
54
d66c7096
LC
55(test-assert "package-field-location"
56 (let ()
57 (define (goto port line column)
58 (unless (and (= (port-column port) (- column 1))
59 (= (port-line port) (- line 1)))
60 (unless (eof-object? (get-char port))
61 (goto port line column))))
62
63 (define read-at
64 (match-lambda
65 (($ <location> file line column)
66 (call-with-input-file (search-path %load-path file)
67 (lambda (port)
68 (goto port line column)
69 (read port))))))
70
71 (and (equal? (read-at (package-field-location %bootstrap-guile 'name))
72 (package-name %bootstrap-guile))
73 (equal? (read-at (package-field-location %bootstrap-guile 'version))
f903dc05
LC
74 (package-version %bootstrap-guile))
75 (not (package-field-location %bootstrap-guile 'does-not-exist)))))
d66c7096 76
a3d73f59
LC
77(test-assert "package-transitive-inputs"
78 (let* ((a (dummy-package "a"))
79 (b (dummy-package "b"
80 (propagated-inputs `(("a" ,a)))))
81 (c (dummy-package "c"
82 (inputs `(("a" ,a)))))
83 (d (dummy-package "d"
84 (propagated-inputs `(("x" "something.drv")))))
85 (e (dummy-package "e"
86 (inputs `(("b" ,b) ("c" ,c) ("d" ,d))))))
87 (and (null? (package-transitive-inputs a))
88 (equal? `(("a" ,a)) (package-transitive-inputs b))
89 (equal? `(("a" ,a)) (package-transitive-inputs c))
90 (equal? (package-propagated-inputs d)
91 (package-transitive-inputs d))
92 (equal? `(("b" ,b) ("b/a" ,a) ("c" ,c)
93 ("d" ,d) ("d/x" "something.drv"))
94 (pk 'x (package-transitive-inputs e))))))
95
d510ab46 96(test-skip (if (not %store) 4 0))
e509d152
LC
97
98(test-assert "return values"
99 (let-values (((drv-path drv)
100 (package-derivation %store (dummy-package "p"))))
101 (and (derivation-path? drv-path)
102 (derivation? drv))))
be13fbfa 103
d510ab46
LC
104(test-assert "package-output"
105 (let* ((package (dummy-package "p"))
106 (drv-path (package-derivation %store package)))
107 (and (derivation-path? drv-path)
108 (string=? (derivation-path->output-path drv-path)
109 (package-output %store package "out")))))
110
be13fbfa
LC
111(test-assert "trivial"
112 (let* ((p (package (inherit (dummy-package "trivial"))
113 (build-system trivial-build-system)
114 (source #f)
115 (arguments
14da91e2
LC
116 `(#:guile ,%bootstrap-guile
117 #:builder
be13fbfa
LC
118 (begin
119 (mkdir %output)
120 (call-with-output-file (string-append %output "/test")
121 (lambda (p)
122 (display '(hello guix) p))))))))
123 (d (package-derivation %store p)))
124 (and (build-derivations %store (list d))
125 (let ((p (pk 'drv d (derivation-path->output-path d))))
126 (equal? '(hello guix)
127 (call-with-input-file (string-append p "/test") read))))))
e3ce5d70 128
860a6f1a
LC
129(test-assert "trivial with local file as input"
130 (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
131 (p (package (inherit (dummy-package "trivial-with-input-file"))
132 (build-system trivial-build-system)
133 (source #f)
134 (arguments
135 `(#:guile ,%bootstrap-guile
136 #:builder (copy-file (assoc-ref %build-inputs "input")
137 %output)))
138 (inputs `(("input" ,i)))))
139 (d (package-derivation %store p)))
140 (and (build-derivations %store (list d))
141 (let ((p (pk 'drv d (derivation-path->output-path d))))
142 (equal? (call-with-input-file p get-bytevector-all)
143 (call-with-input-file i get-bytevector-all))))))
144
592ef6c8
LC
145(test-assert "trivial with system-dependent input"
146 (let* ((p (package (inherit (dummy-package "trivial-system-dependent-input"))
147 (build-system trivial-build-system)
148 (source #f)
149 (arguments
150 `(#:guile ,%bootstrap-guile
151 #:builder
152 (let ((out (assoc-ref %outputs "out"))
153 (bash (assoc-ref %build-inputs "bash")))
154 (zero? (system* bash "-c"
155 (format #f "echo hello > ~a" out))))))
dd6b9a37
LC
156 (inputs `(("bash" ,(search-bootstrap-binary "bash"
157 (%current-system)))))))
592ef6c8
LC
158 (d (package-derivation %store p)))
159 (and (build-derivations %store (list d))
160 (let ((p (pk 'drv d (derivation-path->output-path d))))
161 (eq? 'hello (call-with-input-file p read))))))
162
ad1ebab3
LC
163(unless (false-if-exception (getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV))
164 (test-skip 1))
9e782349
LC
165(test-assert "GNU Make, bootstrap"
166 ;; GNU Make is the first program built during bootstrap; we choose it
167 ;; here so that the test doesn't last for too long.
1ffa7090 168 (let ((gnu-make (@@ (gnu packages base) gnu-make-boot0)))
9e782349
LC
169 (and (package? gnu-make)
170 (or (location? (package-location gnu-make))
171 (not (package-location gnu-make)))
172 (let* ((drv (package-derivation %store gnu-make))
14da91e2
LC
173 (out (derivation-path->output-path drv)))
174 (and (build-derivations %store (list drv))
9e782349 175 (file-exists? (string-append out "/bin/make")))))))
e3ce5d70 176
ba326ce4
LC
177(test-eq "fold-packages" hello
178 (fold-packages (lambda (p r)
179 (if (string=? (package-name p) "hello")
180 p
181 r))
182 #f))
183
6b1891b0
LC
184(test-assert "find-packages-by-name"
185 (match (find-packages-by-name "hello")
186 (((? (cut eq? hello <>))) #t)
187 (wrong (pk 'find-packages-by-name wrong #f))))
188
189(test-assert "find-packages-by-name with version"
190 (match (find-packages-by-name "hello" (package-version hello))
191 (((? (cut eq? hello <>))) #t)
192 (wrong (pk 'find-packages-by-name wrong #f))))
193
e3ce5d70
LC
194(test-end "packages")
195
196\f
197(exit (= (test-runner-fail-count (test-runner-current)) 0))
198
199;;; Local Variables:
a3d73f59 200;;; eval: (put 'dummy-package 'scheme-indent-function 1)
e3ce5d70 201;;; End: