gnu: cool-retro-term: Upgrade to 1.1.1.
[jackhill/guix/guix.git] / tests / build-utils.scm
CommitLineData
233e7676 1;;; GNU Guix --- Functional package management for GNU
7370c021 2;;; Copyright © 2012, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
b0e0d0e9 3;;;
233e7676 4;;; This file is part of GNU Guix.
b0e0d0e9 5;;;
233e7676 6;;; GNU Guix is free software; you can redistribute it and/or modify it
b0e0d0e9
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
b0e0d0e9
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/>.
b0e0d0e9
LC
18
19
20(define-module (test-build-utils)
de611138 21 #:use-module (guix tests)
b0e0d0e9 22 #:use-module (guix build utils)
7370c021
LC
23 #:use-module ((guix utils)
24 #:select (%current-system call-with-temporary-directory))
de611138
EB
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))
b0e0d0e9 31
de611138 32\f
b0e0d0e9
LC
33(test-begin "build-utils")
34
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))))
38
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))))
42
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))))
46
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))))
50
51(test-equal "alist-replace"
52 '((a . 1) (b . 77) (c . 3))
53 (alist-replace 'b 77 '((a . 1) (b . 2) (c . 3))))
54
55(test-assert "alist-replace, key not found"
56 (not (false-if-exception
57 (alist-replace 'z 77 '((a . 1) (b . 2) (c . 3))))))
58
91133c2d
LC
59(test-equal "fold-port-matches"
60 (make-list 3 "Guix")
61 (call-with-input-string "Guix is cool, Guix rocks, and it uses Guile, Guix!"
62 (lambda (port)
63 (fold-port-matches cons '() "Guix" port))))
64
65(test-equal "fold-port-matches, trickier"
66 (reverse '("Guix" "guix" "Guix" "guiX" "Guix"))
67 (call-with-input-string "Guix, guix, GuiGuixguiX, Guix"
68 (lambda (port)
69 (fold-port-matches cons '()
70 (list (char-set #\G #\g)
71 (char-set #\u)
72 (char-set #\i)
73 (char-set #\x #\X))
74 port))))
75
76(test-equal "fold-port-matches, with unmatched chars"
77 '("Guix" #\, #\space
78 "guix" #\, #\space
79 #\G #\u #\i "Guix" "guiX" #\, #\space
80 "Guix")
81 (call-with-input-string "Guix, guix, GuiGuixguiX, Guix"
82 (lambda (port)
83 (reverse
84 (fold-port-matches cons '()
85 (list (char-set #\G #\g)
86 (char-set #\u)
87 (char-set #\i)
88 (char-set #\x #\X))
89 port
90 cons)))))
91
7370c021
LC
92(test-equal "wrap-program, one input, multiple calls"
93 "hello world\n"
94 (call-with-temporary-directory
95 (lambda (directory)
96 (let ((bash (search-bootstrap-binary "bash" (%current-system)))
97 (foo (string-append directory "/foo")))
98
99 (call-with-output-file foo
100 (lambda (p)
101 (format p
102 "#!~a~%echo \"${GUIX_FOO} ${GUIX_BAR}\"~%"
103 bash)))
104 (chmod foo #o777)
105
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
109 ;; package's output.
110 (setenv "PATH" (dirname bash))
111 (wrap-program foo `("GUIX_FOO" prefix ("hello")))
112 (wrap-program foo `("GUIX_BAR" prefix ("world")))
113
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.
116 (unsetenv "LOCPATH")
117
118 (let* ((pipe (open-input-pipe foo))
119 (str (get-string-all pipe)))
120 (with-directory-excursion directory
b14a8385 121 (for-each delete-file '("foo" ".foo-real")))
7370c021
LC
122 (and (zero? (close-pipe pipe))
123 str))))))
de611138 124
b0e0d0e9 125(test-end)