union: Detect collisions, and delete duplicate leaves.
[jackhill/guix/guix.git] / tests / union.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org>
3 ;;;
4 ;;; This file is part of GNU Guix.
5 ;;;
6 ;;; GNU 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 ;;; GNU 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 GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19
20 (define-module (test-union)
21 #:use-module (guix store)
22 #:use-module (guix utils)
23 #:use-module (guix derivations)
24 #:use-module (guix packages)
25 #:use-module (guix build union)
26 #:use-module ((guix build utils)
27 #:select (with-directory-excursion directory-exists?))
28 #:use-module (distro packages bootstrap)
29 #:use-module (srfi srfi-64)
30 #:use-module (ice-9 match))
31
32 ;; Exercise the (guix build union) module.
33
34 (define %store
35 (false-if-exception (open-connection)))
36
37 (when %store
38 ;; By default, use %BOOTSTRAP-GUILE for the current system.
39 (let ((drv (package-derivation %store %bootstrap-guile)))
40 (%guile-for-build drv)))
41
42 \f
43 (test-begin "union")
44
45 (test-equal "tree-union, empty"
46 '()
47 (tree-union '()))
48
49 (test-equal "tree-union, leaves only"
50 '(a b c d)
51 (tree-union '(a b c d)))
52
53 (test-equal "tree-union, simple"
54 '((bin ls touch make awk gawk))
55 (tree-union '((bin ls touch)
56 (bin make)
57 (bin awk gawk))))
58
59 (test-equal "tree-union, several levels"
60 '((share (doc (make README) (coreutils README)))
61 (bin ls touch make))
62 (tree-union '((bin ls touch)
63 (share (doc (coreutils README)))
64 (bin make)
65 (share (doc (make README))))))
66
67 (test-equal "delete-duplicate-leaves, default"
68 '(bin make touch ls)
69 (delete-duplicate-leaves '(bin ls make touch ls)))
70
71 (test-equal "delete-duplicate-leaves, file names"
72 '("doc" ("info"
73 "/binutils/ld.info"
74 "/gcc/gcc.info"
75 "/binutils/standards.info"))
76 (let ((leaf=? (lambda (a b)
77 (string=? (basename a) (basename b)))))
78 (delete-duplicate-leaves '("doc"
79 ("info"
80 "/binutils/ld.info"
81 "/binutils/standards.info"
82 "/gcc/gcc.info"
83 "/gcc/standards.info"))
84 leaf=?)))
85
86 (test-skip (if (and %store
87 (false-if-exception
88 (getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)))
89 0
90 1))
91
92 (test-assert "union-build"
93 (let* ((inputs (map (match-lambda
94 ((name package)
95 `(,name ,(package-derivation %store package))))
96 %bootstrap-inputs))
97 (builder `(begin
98 (use-modules (guix build union))
99 (union-build (assoc-ref %outputs "out")
100 (map cdr %build-inputs))))
101 (drv
102 (build-expression->derivation %store "union-test"
103 (%current-system)
104 builder inputs
105 #:modules '((guix build union)))))
106 (and (build-derivations %store (list (pk 'drv drv)))
107 (with-directory-excursion (derivation-path->output-path drv)
108 (and (file-exists? "bin/touch")
109 (file-exists? "bin/gcc")
110 (file-exists? "bin/ld")
111 (file-exists? "lib/libc.so")
112 (directory-exists? "lib/gcc")
113 (file-exists? "include/unistd.h"))))))
114
115 (test-end)
116
117 \f
118 (exit (= (test-runner-fail-count (test-runner-current)) 0))
119
120 ;;; Local Variables:
121 ;;; eval: (put 'test-assert 'scheme-indent-function 1)
122 ;;; eval: (put 'test-equal 'scheme-indent-function 1)
123 ;;; eval: (put 'call-with-input-string 'scheme-indent-function 1)
124 ;;; End: