union: Rewrite to be faster; handle symlink/directory conflicts.
[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 (gnu packages bootstrap)
29 #:use-module (srfi srfi-1)
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
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-skip (if (and %store
47 (false-if-exception
48 (getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)))
49 0
50 1))
51
52 (test-assert "union-build"
53 (let* ((inputs (map (match-lambda
54 ((name package)
55 `(,name ,(package-derivation %store package))))
56
57 ;; Purposefully leave duplicate entries.
58 (append %bootstrap-inputs
59 (take %bootstrap-inputs 3))))
60 (builder `(begin
61 (use-modules (guix build union))
62 (union-build (assoc-ref %outputs "out")
63 (map cdr %build-inputs))))
64 (drv
65 (build-expression->derivation %store "union-test"
66 builder
67 #:inputs inputs
68 #:modules '((guix build union)))))
69 (and (build-derivations %store (list (pk 'drv drv)))
70 (with-directory-excursion (derivation->output-path drv)
71 (and (file-exists? "bin/touch")
72 (file-exists? "bin/gcc")
73 (file-exists? "bin/ld")
74 (file-exists? "lib/libc.so")
75 (directory-exists? "lib/gcc")
76 (file-exists? "include/unistd.h")
77
78 ;; The 'include/c++' sub-directory is only found in
79 ;; gcc-bootstrap, so it should be unified in a
80 ;; straightforward way, without traversing it.
81 (eq? 'symlink (stat:type (lstat "include/c++")))
82
83 ;; Conversely, several inputs have a 'bin' sub-directory, so
84 ;; unifying it requires traversing them all, and creating a
85 ;; new 'bin' sub-directory in the profile.
86 (eq? 'directory (stat:type (lstat "bin"))))))))
87
88 (test-end)
89
90 \f
91 (exit (= (test-runner-fail-count (test-runner-current)) 0))