1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
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.
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.
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/>.
20 (define-module (test-build-utils)
21 #:use-module (guix tests)
22 #:use-module (guix build utils)
23 #:use-module ((guix utils)
24 #:select (%current-system call-with-temporary-directory))
25 #:use-module (gnu packages)
26 #:use-module (gnu packages bootstrap)
27 #:use-module (srfi srfi-34)
28 #:use-module (srfi srfi-64)
29 #:use-module (rnrs io ports)
30 #:use-module (ice-9 popen))
33 (test-begin "build-utils")
35 (test-equal "alist-cons-before"
36 '((a . 1) (x . 42) (b . 2) (c . 3))
37 (alist-cons-before 'b 'x 42 '((a . 1) (b . 2) (c . 3))))
39 (test-equal "alist-cons-before, reference not found"
40 '((a . 1) (b . 2) (c . 3) (x . 42))
41 (alist-cons-before 'z 'x 42 '((a . 1) (b . 2) (c . 3))))
43 (test-equal "alist-cons-after"
44 '((a . 1) (b . 2) (x . 42) (c . 3))
45 (alist-cons-after 'b 'x 42 '((a . 1) (b . 2) (c . 3))))
47 (test-equal "alist-cons-after, reference not found"
48 '((a . 1) (b . 2) (c . 3) (x . 42))
49 (alist-cons-after 'z 'x 42 '((a . 1) (b . 2) (c . 3))))
51 (test-equal "alist-replace"
52 '((a . 1) (b . 77) (c . 3))
53 (alist-replace 'b 77 '((a . 1) (b . 2) (c . 3))))
55 (test-assert "alist-replace, key not found"
56 (not (false-if-exception
57 (alist-replace 'z 77 '((a . 1) (b . 2) (c . 3))))))
59 (test-equal "fold-port-matches"
61 (call-with-input-string "Guix is cool, Guix rocks, and it uses Guile, Guix!"
63 (fold-port-matches cons '() "Guix" port))))
65 (test-equal "fold-port-matches, trickier"
66 (reverse '("Guix" "guix" "Guix" "guiX" "Guix"))
67 (call-with-input-string "Guix, guix, GuiGuixguiX, Guix"
69 (fold-port-matches cons '()
70 (list (char-set #\G #\g)
76 (test-equal "fold-port-matches, with unmatched chars"
79 #\G #\u #\i "Guix" "guiX" #\, #\space
81 (call-with-input-string "Guix, guix, GuiGuixguiX, Guix"
84 (fold-port-matches cons '()
85 (list (char-set #\G #\g)
92 (test-equal "wrap-program, one input, multiple calls"
94 (call-with-temporary-directory
96 (let ((bash (search-bootstrap-binary "bash" (%current-system)))
97 (foo (string-append directory "/foo")))
99 (call-with-output-file foo
102 "#!~a~%echo \"${GUIX_FOO} ${GUIX_BAR}\"~%"
106 ;; wrap-program uses `which' to find bash for the wrapper shebang, but
107 ;; it can't know about the bootstrap bash in the store, since it's not
108 ;; named "bash". Help it out a bit by providing a symlink it this
110 (setenv "PATH" (dirname bash))
111 (wrap-program foo `("GUIX_FOO" prefix ("hello")))
112 (wrap-program foo `("GUIX_BAR" prefix ("world")))
114 ;; The bootstrap Bash is linked against an old libc and would abort with
115 ;; an assertion failure when trying to load incompatible locale data.
118 (let* ((pipe (open-input-pipe foo))
119 (str (get-string-all pipe)))
120 (with-directory-excursion directory
121 (for-each delete-file '("foo" ".foo-real")))
122 (and (zero? (close-pipe pipe))