1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012 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 build utils)
22 #:use-module (srfi srfi-64))
24 (test-begin "build-utils")
26 (test-equal "alist-cons-before"
27 '((a . 1) (x . 42) (b . 2) (c . 3))
28 (alist-cons-before 'b 'x 42 '((a . 1) (b . 2) (c . 3))))
30 (test-equal "alist-cons-before, reference not found"
31 '((a . 1) (b . 2) (c . 3) (x . 42))
32 (alist-cons-before 'z 'x 42 '((a . 1) (b . 2) (c . 3))))
34 (test-equal "alist-cons-after"
35 '((a . 1) (b . 2) (x . 42) (c . 3))
36 (alist-cons-after 'b 'x 42 '((a . 1) (b . 2) (c . 3))))
38 (test-equal "alist-cons-after, reference not found"
39 '((a . 1) (b . 2) (c . 3) (x . 42))
40 (alist-cons-after 'z 'x 42 '((a . 1) (b . 2) (c . 3))))
42 (test-equal "alist-replace"
43 '((a . 1) (b . 77) (c . 3))
44 (alist-replace 'b 77 '((a . 1) (b . 2) (c . 3))))
46 (test-assert "alist-replace, key not found"
47 (not (false-if-exception
48 (alist-replace 'z 77 '((a . 1) (b . 2) (c . 3))))))
50 (test-equal "fold-port-matches"
52 (call-with-input-string "Guix is cool, Guix rocks, and it uses Guile, Guix!"
54 (fold-port-matches cons '() "Guix" port))))
56 (test-equal "fold-port-matches, trickier"
57 (reverse '("Guix" "guix" "Guix" "guiX" "Guix"))
58 (call-with-input-string "Guix, guix, GuiGuixguiX, Guix"
60 (fold-port-matches cons '()
61 (list (char-set #\G #\g)
67 (test-equal "fold-port-matches, with unmatched chars"
70 #\G #\u #\i "Guix" "guiX" #\, #\space
72 (call-with-input-string "Guix, guix, GuiGuixguiX, Guix"
75 (fold-port-matches cons '()
76 (list (char-set #\G #\g)
86 (exit (= (test-runner-fail-count (test-runner-current)) 0))