gnu: Switch to GCC 4.8 as the default compiler.
[jackhill/guix/guix.git] / tests / union.scm
CommitLineData
233e7676 1;;; GNU Guix --- Functional package management for GNU
b2d58cd8 2;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org>
c8c88afa 3;;;
233e7676 4;;; This file is part of GNU Guix.
c8c88afa 5;;;
233e7676 6;;; GNU Guix is free software; you can redistribute it and/or modify it
c8c88afa
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
c8c88afa
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/>.
c8c88afa
LC
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?))
1ffa7090 28 #:use-module (gnu packages bootstrap)
97d3998e 29 #:use-module (srfi srfi-1)
c8c88afa
LC
30 #:use-module (srfi srfi-64)
31 #:use-module (ice-9 match))
32
33;; Exercise the (guix build union) module.
34
35(define %store
36 (false-if-exception (open-connection)))
37
c8c88afa
LC
38(when %store
39 ;; By default, use %BOOTSTRAP-GUILE for the current system.
40 (let ((drv (package-derivation %store %bootstrap-guile)))
41 (%guile-for-build drv)))
42
43\f
44(test-begin "union")
45
46(test-equal "tree-union, empty"
47 '()
48 (tree-union '()))
49
50(test-equal "tree-union, leaves only"
51 '(a b c d)
52 (tree-union '(a b c d)))
53
54(test-equal "tree-union, simple"
55 '((bin ls touch make awk gawk))
56 (tree-union '((bin ls touch)
57 (bin make)
58 (bin awk gawk))))
59
60(test-equal "tree-union, several levels"
61 '((share (doc (make README) (coreutils README)))
62 (bin ls touch make))
63 (tree-union '((bin ls touch)
64 (share (doc (coreutils README)))
65 (bin make)
66 (share (doc (make README))))))
67
b2d58cd8
LC
68(test-equal "delete-duplicate-leaves, default"
69 '(bin make touch ls)
70 (delete-duplicate-leaves '(bin ls make touch ls)))
71
72(test-equal "delete-duplicate-leaves, file names"
73 '("doc" ("info"
74 "/binutils/ld.info"
75 "/gcc/gcc.info"
76 "/binutils/standards.info"))
77 (let ((leaf=? (lambda (a b)
78 (string=? (basename a) (basename b)))))
79 (delete-duplicate-leaves '("doc"
80 ("info"
81 "/binutils/ld.info"
82 "/binutils/standards.info"
83 "/gcc/gcc.info"
84 "/gcc/standards.info"))
85 leaf=?)))
86
ad1ebab3
LC
87(test-skip (if (and %store
88 (false-if-exception
89 (getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)))
90 0
91 1))
c8c88afa
LC
92
93(test-assert "union-build"
94 (let* ((inputs (map (match-lambda
95 ((name package)
96 `(,name ,(package-derivation %store package))))
62112230
LC
97
98 ;; Purposefully leave duplicate entries.
99 (append %bootstrap-inputs
100 (take %bootstrap-inputs 3))))
c8c88afa
LC
101 (builder `(begin
102 (use-modules (guix build union))
103 (union-build (assoc-ref %outputs "out")
104 (map cdr %build-inputs))))
105 (drv
106 (build-expression->derivation %store "union-test"
107 (%current-system)
108 builder inputs
109 #:modules '((guix build union)))))
110 (and (build-derivations %store (list (pk 'drv drv)))
59688fc4 111 (with-directory-excursion (derivation->output-path drv)
c8c88afa
LC
112 (and (file-exists? "bin/touch")
113 (file-exists? "bin/gcc")
114 (file-exists? "bin/ld")
115 (file-exists? "lib/libc.so")
116 (directory-exists? "lib/gcc")
43dd9202
LC
117 (file-exists? "include/unistd.h")
118
119 ;; The 'include' sub-directory is only found in
120 ;; glibc-bootstrap, so it should be unified in a
121 ;; straightforward way, without traversing it.
122 (eq? 'symlink (stat:type (lstat "include")))
123
124 ;; Conversely, several inputs have a 'bin' sub-directory, so
125 ;; unifying it requires traversing them all, and creating a
126 ;; new 'bin' sub-directory in the profile.
127 (eq? 'directory (stat:type (lstat "bin"))))))))
c8c88afa
LC
128
129(test-end)
130
131\f
132(exit (= (test-runner-fail-count (test-runner-current)) 0))