Augment `TODO'.
[jackhill/guix/guix.git] / tests / packages.scm
CommitLineData
e3ce5d70
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-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)
6b1891b0 27 #:use-module (distro)
1f455fdc 28 #:use-module (distro packages base)
18633d4f 29 #:use-module (distro packages bootstrap)
6b1891b0
LC
30 #:use-module (srfi srfi-26)
31 #:use-module (srfi srfi-64)
32 #:use-module (ice-9 match))
e3ce5d70
LC
33
34;; Test the high-level packaging layer.
35
36(define %store
37 (false-if-exception (open-connection)))
38
81dbd783
LC
39(when %store
40 ;; Make sure we build everything by ourselves.
41 (set-build-options %store #:use-substitutes? #f))
42
14da91e2 43\f
e3ce5d70
LC
44(test-begin "packages")
45
a3d73f59
LC
46(define-syntax-rule (dummy-package name* extra-fields ...)
47 (package (name name*) (version "0") (source #f)
48 (build-system gnu-build-system)
d45122f5 49 (synopsis #f) (description #f)
a3d73f59
LC
50 (home-page #f)
51 extra-fields ...))
52
53(test-assert "package-transitive-inputs"
54 (let* ((a (dummy-package "a"))
55 (b (dummy-package "b"
56 (propagated-inputs `(("a" ,a)))))
57 (c (dummy-package "c"
58 (inputs `(("a" ,a)))))
59 (d (dummy-package "d"
60 (propagated-inputs `(("x" "something.drv")))))
61 (e (dummy-package "e"
62 (inputs `(("b" ,b) ("c" ,c) ("d" ,d))))))
63 (and (null? (package-transitive-inputs a))
64 (equal? `(("a" ,a)) (package-transitive-inputs b))
65 (equal? `(("a" ,a)) (package-transitive-inputs c))
66 (equal? (package-propagated-inputs d)
67 (package-transitive-inputs d))
68 (equal? `(("b" ,b) ("b/a" ,a) ("c" ,c)
69 ("d" ,d) ("d/x" "something.drv"))
70 (pk 'x (package-transitive-inputs e))))))
71
be13fbfa
LC
72(test-skip (if (not %store) 2 0))
73
74(test-assert "trivial"
75 (let* ((p (package (inherit (dummy-package "trivial"))
76 (build-system trivial-build-system)
77 (source #f)
78 (arguments
14da91e2
LC
79 `(#:guile ,%bootstrap-guile
80 #:builder
be13fbfa
LC
81 (begin
82 (mkdir %output)
83 (call-with-output-file (string-append %output "/test")
84 (lambda (p)
85 (display '(hello guix) p))))))))
86 (d (package-derivation %store p)))
87 (and (build-derivations %store (list d))
88 (let ((p (pk 'drv d (derivation-path->output-path d))))
89 (equal? '(hello guix)
90 (call-with-input-file (string-append p "/test") read))))))
e3ce5d70 91
592ef6c8
LC
92(test-assert "trivial with system-dependent input"
93 (let* ((p (package (inherit (dummy-package "trivial-system-dependent-input"))
94 (build-system trivial-build-system)
95 (source #f)
96 (arguments
97 `(#:guile ,%bootstrap-guile
98 #:builder
99 (let ((out (assoc-ref %outputs "out"))
100 (bash (assoc-ref %build-inputs "bash")))
101 (zero? (system* bash "-c"
102 (format #f "echo hello > ~a" out))))))
103 (inputs `(("bash" ,(lambda (system)
104 (search-bootstrap-binary "bash"
105 system)))))))
106 (d (package-derivation %store p)))
107 (and (build-derivations %store (list d))
108 (let ((p (pk 'drv d (derivation-path->output-path d))))
109 (eq? 'hello (call-with-input-file p read))))))
110
9e782349
LC
111(test-assert "GNU Make, bootstrap"
112 ;; GNU Make is the first program built during bootstrap; we choose it
113 ;; here so that the test doesn't last for too long.
114 (let ((gnu-make (@@ (distro packages base) gnu-make-boot0)))
115 (and (package? gnu-make)
116 (or (location? (package-location gnu-make))
117 (not (package-location gnu-make)))
118 (let* ((drv (package-derivation %store gnu-make))
14da91e2
LC
119 (out (derivation-path->output-path drv)))
120 (and (build-derivations %store (list drv))
9e782349 121 (file-exists? (string-append out "/bin/make")))))))
e3ce5d70 122
ba326ce4
LC
123(test-eq "fold-packages" hello
124 (fold-packages (lambda (p r)
125 (if (string=? (package-name p) "hello")
126 p
127 r))
128 #f))
129
6b1891b0
LC
130(test-assert "find-packages-by-name"
131 (match (find-packages-by-name "hello")
132 (((? (cut eq? hello <>))) #t)
133 (wrong (pk 'find-packages-by-name wrong #f))))
134
135(test-assert "find-packages-by-name with version"
136 (match (find-packages-by-name "hello" (package-version hello))
137 (((? (cut eq? hello <>))) #t)
138 (wrong (pk 'find-packages-by-name wrong #f))))
139
e3ce5d70
LC
140(test-end "packages")
141
142\f
143(exit (= (test-runner-fail-count (test-runner-current)) 0))
144
145;;; Local Variables:
ba326ce4 146;;; eval: (put 'test-equal 'scheme-indent-function 2)
e3ce5d70 147;;; eval: (put 'test-assert 'scheme-indent-function 1)
a3d73f59 148;;; eval: (put 'dummy-package 'scheme-indent-function 1)
e3ce5d70 149;;; End: