build: Pass the appropriate flags when building `libstore.a'.
[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
55(test-assert "package-transitive-inputs"
56 (let* ((a (dummy-package "a"))
57 (b (dummy-package "b"
58 (propagated-inputs `(("a" ,a)))))
59 (c (dummy-package "c"
60 (inputs `(("a" ,a)))))
61 (d (dummy-package "d"
62 (propagated-inputs `(("x" "something.drv")))))
63 (e (dummy-package "e"
64 (inputs `(("b" ,b) ("c" ,c) ("d" ,d))))))
65 (and (null? (package-transitive-inputs a))
66 (equal? `(("a" ,a)) (package-transitive-inputs b))
67 (equal? `(("a" ,a)) (package-transitive-inputs c))
68 (equal? (package-propagated-inputs d)
69 (package-transitive-inputs d))
70 (equal? `(("b" ,b) ("b/a" ,a) ("c" ,c)
71 ("d" ,d) ("d/x" "something.drv"))
72 (pk 'x (package-transitive-inputs e))))))
73
d510ab46 74(test-skip (if (not %store) 4 0))
e509d152
LC
75
76(test-assert "return values"
77 (let-values (((drv-path drv)
78 (package-derivation %store (dummy-package "p"))))
79 (and (derivation-path? drv-path)
80 (derivation? drv))))
be13fbfa 81
d510ab46
LC
82(test-assert "package-output"
83 (let* ((package (dummy-package "p"))
84 (drv-path (package-derivation %store package)))
85 (and (derivation-path? drv-path)
86 (string=? (derivation-path->output-path drv-path)
87 (package-output %store package "out")))))
88
be13fbfa
LC
89(test-assert "trivial"
90 (let* ((p (package (inherit (dummy-package "trivial"))
91 (build-system trivial-build-system)
92 (source #f)
93 (arguments
14da91e2
LC
94 `(#:guile ,%bootstrap-guile
95 #:builder
be13fbfa
LC
96 (begin
97 (mkdir %output)
98 (call-with-output-file (string-append %output "/test")
99 (lambda (p)
100 (display '(hello guix) p))))))))
101 (d (package-derivation %store p)))
102 (and (build-derivations %store (list d))
103 (let ((p (pk 'drv d (derivation-path->output-path d))))
104 (equal? '(hello guix)
105 (call-with-input-file (string-append p "/test") read))))))
e3ce5d70 106
860a6f1a
LC
107(test-assert "trivial with local file as input"
108 (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
109 (p (package (inherit (dummy-package "trivial-with-input-file"))
110 (build-system trivial-build-system)
111 (source #f)
112 (arguments
113 `(#:guile ,%bootstrap-guile
114 #:builder (copy-file (assoc-ref %build-inputs "input")
115 %output)))
116 (inputs `(("input" ,i)))))
117 (d (package-derivation %store p)))
118 (and (build-derivations %store (list d))
119 (let ((p (pk 'drv d (derivation-path->output-path d))))
120 (equal? (call-with-input-file p get-bytevector-all)
121 (call-with-input-file i get-bytevector-all))))))
122
592ef6c8
LC
123(test-assert "trivial with system-dependent input"
124 (let* ((p (package (inherit (dummy-package "trivial-system-dependent-input"))
125 (build-system trivial-build-system)
126 (source #f)
127 (arguments
128 `(#:guile ,%bootstrap-guile
129 #:builder
130 (let ((out (assoc-ref %outputs "out"))
131 (bash (assoc-ref %build-inputs "bash")))
132 (zero? (system* bash "-c"
133 (format #f "echo hello > ~a" out))))))
dd6b9a37
LC
134 (inputs `(("bash" ,(search-bootstrap-binary "bash"
135 (%current-system)))))))
592ef6c8
LC
136 (d (package-derivation %store p)))
137 (and (build-derivations %store (list d))
138 (let ((p (pk 'drv d (derivation-path->output-path d))))
139 (eq? 'hello (call-with-input-file p read))))))
140
ad1ebab3
LC
141(unless (false-if-exception (getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV))
142 (test-skip 1))
9e782349
LC
143(test-assert "GNU Make, bootstrap"
144 ;; GNU Make is the first program built during bootstrap; we choose it
145 ;; here so that the test doesn't last for too long.
1ffa7090 146 (let ((gnu-make (@@ (gnu packages base) gnu-make-boot0)))
9e782349
LC
147 (and (package? gnu-make)
148 (or (location? (package-location gnu-make))
149 (not (package-location gnu-make)))
150 (let* ((drv (package-derivation %store gnu-make))
14da91e2
LC
151 (out (derivation-path->output-path drv)))
152 (and (build-derivations %store (list drv))
9e782349 153 (file-exists? (string-append out "/bin/make")))))))
e3ce5d70 154
ba326ce4
LC
155(test-eq "fold-packages" hello
156 (fold-packages (lambda (p r)
157 (if (string=? (package-name p) "hello")
158 p
159 r))
160 #f))
161
6b1891b0
LC
162(test-assert "find-packages-by-name"
163 (match (find-packages-by-name "hello")
164 (((? (cut eq? hello <>))) #t)
165 (wrong (pk 'find-packages-by-name wrong #f))))
166
167(test-assert "find-packages-by-name with version"
168 (match (find-packages-by-name "hello" (package-version hello))
169 (((? (cut eq? hello <>))) #t)
170 (wrong (pk 'find-packages-by-name wrong #f))))
171
e3ce5d70
LC
172(test-end "packages")
173
174\f
175(exit (= (test-runner-fail-count (test-runner-current)) 0))
176
177;;; Local Variables:
a3d73f59 178;;; eval: (put 'dummy-package 'scheme-indent-function 1)
e3ce5d70 179;;; End: