tests: Adjust to not rely on /bin/sh.
[jackhill/guix/guix.git] / tests / union.scm
1 ;;; Guix --- Nix package management from Guile. -*- coding: utf-8 -*-
2 ;;; Copyright (C) 2012, 2013 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-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-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-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
68 (test-skip (if (and %store
69 (false-if-exception
70 (getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)))
71 0
72 1))
73
74 (test-assert "union-build"
75 (let* ((inputs (map (match-lambda
76 ((name package)
77 `(,name ,(package-derivation %store package))))
78 (delete-duplicates %bootstrap-inputs
79 (lambda (i1 i2)
80 (eq? (second i1) (second i2))))))
81 (builder `(begin
82 (use-modules (guix build union))
83 (union-build (assoc-ref %outputs "out")
84 (map cdr %build-inputs))))
85 (drv
86 (build-expression->derivation %store "union-test"
87 (%current-system)
88 builder inputs
89 #:modules '((guix build union)))))
90 (and (build-derivations %store (list (pk 'drv drv)))
91 (with-directory-excursion (derivation-path->output-path drv)
92 (and (file-exists? "bin/touch")
93 (file-exists? "bin/gcc")
94 (file-exists? "bin/ld")
95 (file-exists? "lib/libc.so")
96 (directory-exists? "lib/gcc")
97 (file-exists? "include/unistd.h"))))))
98
99 (test-end)
100
101 \f
102 (exit (= (test-runner-fail-count (test-runner-current)) 0))
103
104 ;;; Local Variables:
105 ;;; eval: (put 'test-assert 'scheme-indent-function 1)
106 ;;; eval: (put 'test-equal 'scheme-indent-function 1)
107 ;;; eval: (put 'call-with-input-string 'scheme-indent-function 1)
108 ;;; End: