1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2019 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-ui)
21 #:use-module (guix ui)
22 #:use-module (guix profiles)
23 #:use-module (guix store)
24 #:use-module (guix derivations)
25 #:use-module ((gnu packages) #:select (specification->package))
26 #:use-module (guix tests)
27 #:use-module (srfi srfi-1)
28 #:use-module (srfi srfi-11)
29 #:use-module (srfi srfi-19)
30 #:use-module (srfi srfi-26)
31 #:use-module (srfi srfi-64)
32 #:use-module (ice-9 regex))
34 ;; Test the (guix ui) module.
37 "GNU Guile is an implementation of the Scheme programming language, with
38 support for many SRFIs, packaged for use in a wide variety of environments.
39 In addition to implementing the R5RS Scheme standard and a large subset of
40 R6RS, Guile includes a module system, full access to POSIX system calls,
41 networking support, multiple threads, dynamic linking, a foreign function call
42 interface, and powerful string processing.")
48 (item "/gnu/store/...")
55 (item "/gnu/store/...")
61 (test-assert "fill-paragraph"
62 (every (lambda (column)
63 (every (lambda (width)
65 (<= (string-length line) width))
66 (string-split (fill-paragraph %paragraph
69 '(15 30 35 40 45 50 60 70 80 90 100)))
72 (test-assert "fill-paragraph, consecutive newlines"
73 (every (lambda (width)
75 (string-prefix? "When STR" line))
77 (fill-paragraph (procedure-documentation fill-paragraph)
80 '(15 20 25 30 40 50 60)))
82 (test-equal "fill-paragraph, large unbreakable word"
83 '("Here is a" "very-very-long-word"
86 (fill-paragraph "Here is a very-very-long-word and that's it."
90 (test-equal "fill-paragraph, two spaces after period"
91 "First line. Second line"
92 (fill-paragraph "First line.
95 (test-equal "package-description-string vs. Unicode"
96 "b•ll•t\n\n" ;see <http://bugs.gnu.org/21536>
97 (with-fluids ((%default-port-encoding "ISO-8859-1"))
98 (package-description-string
99 (dummy-package "foo" (description "b•ll•t")))))
101 (test-equal "package-specification->name+version+output"
103 ("guile" "2.0.9" "out")
105 ("guile" "2.0.9" "debug")
106 ("guile-cairo" "1.4.1" "out"))
110 (package-specification->name+version+output spec))
116 "guile-cairo@1.4.1")))
118 (test-equal "integer"
120 (string->generations "1"))
122 (test-equal "comma-separated integers"
124 (string->generations "3,7,1,4,6"))
126 (test-equal "closed range"
127 '(4 5 6 7 8 9 10 11 12)
128 (string->generations "4..12"))
130 (test-equal "closed range, equal endpoints"
132 (string->generations "3..3"))
134 (test-equal "indefinite end range"
136 (string->generations "7.."))
138 (test-equal "indefinite start range"
140 (string->generations "..42"))
142 (test-equal "integer, char"
144 (string->generations "a"))
146 (test-equal "comma-separated integers, consecutive comma"
148 (string->generations "1,,2"))
150 (test-equal "comma-separated integers, trailing comma"
152 (string->generations "1,2,"))
154 (test-equal "comma-separated integers, chars"
156 (string->generations "a,b"))
158 (test-equal "closed range, start > end"
160 (string->generations "9..2"))
162 (test-equal "closed range, chars"
164 (string->generations "a..b"))
166 (test-equal "indefinite end range, char"
168 (string->generations "a.."))
170 (test-equal "indefinite start range, char"
172 (string->generations "..a"))
174 (test-equal "duration, 1 day"
175 (make-time time-duration 0 (* 3600 24))
176 (string->duration "1d"))
178 (test-equal "duration, 1 week"
179 (make-time time-duration 0 (* 3600 24 7))
180 (string->duration "1w"))
182 (test-equal "duration, 1 month"
183 (make-time time-duration 0 (* 3600 24 30))
184 (string->duration "1m"))
186 (test-equal "duration, 1 week == 7 days"
187 (string->duration "1w")
188 (string->duration "7d"))
190 (test-equal "duration, 1 month == 30 days"
191 (string->duration "1m")
192 (string->duration "30d"))
194 (test-equal "duration, 2 hours"
196 (time-second (string->duration "2h")))
198 (test-equal "duration, 1 second"
199 (make-time time-duration 0 1)
200 (string->duration "1s"))
202 (test-equal "duration, integer"
204 (string->duration "1"))
206 (test-equal "duration, char"
208 (string->duration "d"))
210 (test-equal "size->number, bytes"
214 (test-equal "size->number, MiB"
216 (size->number "42MiB"))
218 (test-equal "size->number, GiB"
220 (size->number "3GiB"))
222 (test-equal "size->number, 1.2GiB"
223 (inexact->exact (round (* 1.2 (expt 2 30))))
224 (size->number "1.2GiB"))
226 (test-equal "size->number, 1T"
230 (test-assert "size->number, invalid unit"
237 (test-equal "show-what-to-build, zero outputs"
240 (let ((drv (derivation store "zero" "/bin/sh" '()
242 (with-error-to-string
244 ;; This should print nothing.
245 (show-what-to-build store (list drv)))))))
247 (test-assert "show-manifest-transaction"
248 (let* ((m (manifest (list guile-1.8.8)))
249 (t (manifest-transaction (install (list guile-2.0.9)))))
251 (and (string-match "guile\t1.8.8 → 2.0.9"
252 (with-fluids ((%default-port-encoding "UTF-8"))
253 (with-error-to-string
255 (show-manifest-transaction store m t)))))
256 (string-match "guile\t1.8.8 -> 2.0.9"
257 (with-error-to-string
259 ;; In Guile 2.2, %DEFAULT-PORT-ENCODING doesn't
260 ;; influence the encoding of string ports.
261 (set-port-encoding! (current-error-port)
263 (show-manifest-transaction store m t))))))))
265 (test-assert "package-relevance"
266 (let ((guile (specification->package "guile"))
267 (gcrypt (specification->package "guile-gcrypt"))
268 (go (specification->package "go"))
269 (gnugo (specification->package "gnugo"))
270 (libb2 (specification->package "libb2"))
271 (rx (cut make-regexp <> regexp/icase))
274 (and (>0 (package-relevance guile
275 (map rx '("scheme"))))
276 (>0 (package-relevance guile
277 (map rx '("scheme" "implementation"))))
278 (>0 (package-relevance gcrypt
279 (map rx '("guile" "crypto"))))
280 (=0 (package-relevance guile
281 (map rx '("guile" "crypto"))))
282 (>0 (package-relevance go
284 (=0 (package-relevance go
285 (map rx '("go" "game"))))
286 (>0 (package-relevance gnugo
287 (map rx '("go" "game"))))
288 (>0 (package-relevance libb2
289 (map rx '("crypto" "library")))))))