gnu: perl-scalar-list-utils: Update to 1.47.
[jackhill/guix/guix.git] / tests / union.scm
CommitLineData
233e7676 1;;; GNU Guix --- Functional package management for GNU
12d720fd 2;;; Copyright © 2012, 2013, 2014, 2015 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 18
c8c88afa 19(define-module (test-union)
c1bc358f 20 #:use-module (guix tests)
c8c88afa
LC
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 30 #:use-module (srfi srfi-64)
a53a9aed 31 #:use-module (rnrs io ports)
c8c88afa
LC
32 #:use-module (ice-9 match))
33
34;; Exercise the (guix build union) module.
35
36(define %store
c1bc358f 37 (open-connection-for-tests))
c8c88afa
LC
38
39\f
40(test-begin "union")
41
a53a9aed
LC
42(test-assert "union-build with symlink to directory"
43 ;; http://bugs.gnu.org/17083
44 ;; Here both ONE and TWO provide an element called 'foo', but in ONE it's a
45 ;; directory whereas in TWO it's a symlink to a directory.
46 (let* ((one (build-expression->derivation
47 %store "one"
48 '(begin
49 (use-modules (guix build utils) (srfi srfi-26))
50 (let ((foo (string-append %output "/foo")))
51 (mkdir-p foo)
52 (call-with-output-file (string-append foo "/one")
53 (cut display "one" <>))))
54 #:modules '((guix build utils))))
55 (two (build-expression->derivation
56 %store "two"
57 '(begin
58 (use-modules (guix build utils) (srfi srfi-26))
59 (let ((foo (string-append %output "/foo"))
60 (bar (string-append %output "/bar")))
61 (mkdir-p bar)
62 (call-with-output-file (string-append bar "/two")
63 (cut display "two" <>))
64 (symlink "bar" foo)))
65 #:modules '((guix build utils))))
66 (builder '(begin
67 (use-modules (guix build union))
68
69 (union-build (assoc-ref %outputs "out")
70 (list (assoc-ref %build-inputs "one")
71 (assoc-ref %build-inputs "two")))))
72 (drv
73 (build-expression->derivation %store "union-collision-symlink"
74 builder
75 #:inputs `(("one" ,one) ("two" ,two))
76 #:modules '((guix build union)))))
77 (and (build-derivations %store (list drv))
78 (with-directory-excursion (pk (derivation->output-path drv))
79 (and (string=? "one"
80 (call-with-input-file "foo/one" get-string-all))
81 (string=? "two"
82 (call-with-input-file "foo/two" get-string-all))
83 (string=? "two"
84 (call-with-input-file "bar/two" get-string-all))
85 (not (file-exists? "bar/one")))))))
86
12d720fd 87(test-skip (if (and %store (network-reachable?))
ad1ebab3
LC
88 0
89 1))
c8c88afa
LC
90
91(test-assert "union-build"
92 (let* ((inputs (map (match-lambda
93 ((name package)
94 `(,name ,(package-derivation %store package))))
62112230
LC
95
96 ;; Purposefully leave duplicate entries.
97 (append %bootstrap-inputs
98 (take %bootstrap-inputs 3))))
c8c88afa
LC
99 (builder `(begin
100 (use-modules (guix build union))
101 (union-build (assoc-ref %outputs "out")
102 (map cdr %build-inputs))))
103 (drv
104 (build-expression->derivation %store "union-test"
dd1a5a15
LC
105 builder
106 #:inputs inputs
c8c88afa
LC
107 #:modules '((guix build union)))))
108 (and (build-derivations %store (list (pk 'drv drv)))
59688fc4 109 (with-directory-excursion (derivation->output-path drv)
c8c88afa
LC
110 (and (file-exists? "bin/touch")
111 (file-exists? "bin/gcc")
112 (file-exists? "bin/ld")
113 (file-exists? "lib/libc.so")
114 (directory-exists? "lib/gcc")
43dd9202
LC
115 (file-exists? "include/unistd.h")
116
127ed6a9
LC
117 ;; The 'include/c++' sub-directory is only found in
118 ;; gcc-bootstrap, so it should be unified in a
43dd9202 119 ;; straightforward way, without traversing it.
127ed6a9 120 (eq? 'symlink (stat:type (lstat "include/c++")))
43dd9202
LC
121
122 ;; Conversely, several inputs have a 'bin' sub-directory, so
123 ;; unifying it requires traversing them all, and creating a
124 ;; new 'bin' sub-directory in the profile.
125 (eq? 'directory (stat:type (lstat "bin"))))))))
c8c88afa
LC
126
127(test-end)