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