Commit | Line | Data |
---|---|---|
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) |
6b1891b0 LC |
29 | #:use-module (srfi srfi-26) |
30 | #:use-module (srfi srfi-64) | |
31 | #:use-module (ice-9 match)) | |
e3ce5d70 LC |
32 | |
33 | ;; Test the high-level packaging layer. | |
34 | ||
35 | (define %store | |
36 | (false-if-exception (open-connection))) | |
37 | ||
14da91e2 LC |
38 | (define %bootstrap-inputs |
39 | ;; Derivations taken from Nixpkgs, so that the initial tests don't | |
40 | ;; take forever. | |
41 | (and (file-exists? (%nixpkgs-directory)) | |
42 | `(("make" ,(nixpkgs-derivation "gnumake")) | |
43 | ("diffutils" ,(nixpkgs-derivation "diffutils")) | |
44 | ,@(@@ (distro packages base) %bootstrap-inputs)))) | |
45 | ||
46 | (define %bootstrap-guile | |
47 | (@@ (distro packages base) %bootstrap-guile)) | |
48 | ||
49 | \f | |
e3ce5d70 LC |
50 | (test-begin "packages") |
51 | ||
a3d73f59 LC |
52 | (define-syntax-rule (dummy-package name* extra-fields ...) |
53 | (package (name name*) (version "0") (source #f) | |
54 | (build-system gnu-build-system) | |
55 | (description #f) (long-description #f) | |
56 | (home-page #f) | |
57 | extra-fields ...)) | |
58 | ||
59 | (test-assert "package-transitive-inputs" | |
60 | (let* ((a (dummy-package "a")) | |
61 | (b (dummy-package "b" | |
62 | (propagated-inputs `(("a" ,a))))) | |
63 | (c (dummy-package "c" | |
64 | (inputs `(("a" ,a))))) | |
65 | (d (dummy-package "d" | |
66 | (propagated-inputs `(("x" "something.drv"))))) | |
67 | (e (dummy-package "e" | |
68 | (inputs `(("b" ,b) ("c" ,c) ("d" ,d)))))) | |
69 | (and (null? (package-transitive-inputs a)) | |
70 | (equal? `(("a" ,a)) (package-transitive-inputs b)) | |
71 | (equal? `(("a" ,a)) (package-transitive-inputs c)) | |
72 | (equal? (package-propagated-inputs d) | |
73 | (package-transitive-inputs d)) | |
74 | (equal? `(("b" ,b) ("b/a" ,a) ("c" ,c) | |
75 | ("d" ,d) ("d/x" "something.drv")) | |
76 | (pk 'x (package-transitive-inputs e)))))) | |
77 | ||
be13fbfa LC |
78 | (test-skip (if (not %store) 2 0)) |
79 | ||
80 | (test-assert "trivial" | |
81 | (let* ((p (package (inherit (dummy-package "trivial")) | |
82 | (build-system trivial-build-system) | |
83 | (source #f) | |
84 | (arguments | |
14da91e2 LC |
85 | `(#:guile ,%bootstrap-guile |
86 | #:builder | |
be13fbfa LC |
87 | (begin |
88 | (mkdir %output) | |
89 | (call-with-output-file (string-append %output "/test") | |
90 | (lambda (p) | |
91 | (display '(hello guix) p)))))))) | |
92 | (d (package-derivation %store p))) | |
93 | (and (build-derivations %store (list d)) | |
94 | (let ((p (pk 'drv d (derivation-path->output-path d)))) | |
95 | (equal? '(hello guix) | |
96 | (call-with-input-file (string-append p "/test") read)))))) | |
e3ce5d70 LC |
97 | |
98 | (test-assert "GNU Hello" | |
14da91e2 LC |
99 | (let ((hello (package-with-explicit-inputs hello %bootstrap-inputs |
100 | #:guile %bootstrap-guile))) | |
101 | (and (package? hello) | |
102 | (or (location? (package-location hello)) | |
103 | (not (package-location hello))) | |
104 | (let* ((drv (package-derivation %store hello)) | |
105 | (out (derivation-path->output-path drv))) | |
106 | (and (build-derivations %store (list drv)) | |
107 | (file-exists? (string-append out "/bin/hello"))))))) | |
e3ce5d70 | 108 | |
6b1891b0 LC |
109 | (test-assert "find-packages-by-name" |
110 | (match (find-packages-by-name "hello") | |
111 | (((? (cut eq? hello <>))) #t) | |
112 | (wrong (pk 'find-packages-by-name wrong #f)))) | |
113 | ||
114 | (test-assert "find-packages-by-name with version" | |
115 | (match (find-packages-by-name "hello" (package-version hello)) | |
116 | (((? (cut eq? hello <>))) #t) | |
117 | (wrong (pk 'find-packages-by-name wrong #f)))) | |
118 | ||
e3ce5d70 LC |
119 | (test-end "packages") |
120 | ||
121 | \f | |
122 | (exit (= (test-runner-fail-count (test-runner-current)) 0)) | |
123 | ||
124 | ;;; Local Variables: | |
125 | ;;; eval: (put 'test-assert 'scheme-indent-function 1) | |
a3d73f59 | 126 | ;;; eval: (put 'dummy-package 'scheme-indent-function 1) |
e3ce5d70 | 127 | ;;; End: |