1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013, 2014, 2015, 2016, 2017 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 (guix tests)
26 #:use-module (srfi srfi-1)
27 #:use-module (srfi srfi-11)
28 #:use-module (srfi srfi-19)
29 #:use-module (srfi srfi-64)
30 #:use-module (ice-9 regex))
32 ;; Test the (guix ui) module.
35 "GNU Guile is an implementation of the Scheme programming language, with
36 support for many SRFIs, packaged for use in a wide variety of environments.
37 In addition to implementing the R5RS Scheme standard and a large subset of
38 R6RS, Guile includes a module system, full access to POSIX system calls,
39 networking support, multiple threads, dynamic linking, a foreign function call
40 interface, and powerful string processing.")
46 (item "/gnu/store/...")
53 (item "/gnu/store/...")
59 (test-assert "fill-paragraph"
60 (every (lambda (column)
61 (every (lambda (width)
63 (<= (string-length line) width))
64 (string-split (fill-paragraph %paragraph
67 '(15 30 35 40 45 50 60 70 80 90 100)))
70 (test-assert "fill-paragraph, consecutive newlines"
71 (every (lambda (width)
73 (string-prefix? "When STR" line))
75 (fill-paragraph (procedure-documentation fill-paragraph)
78 '(15 20 25 30 40 50 60)))
80 (test-equal "fill-paragraph, large unbreakable word"
81 '("Here is a" "very-very-long-word"
84 (fill-paragraph "Here is a very-very-long-word and that's it."
88 (test-equal "fill-paragraph, two spaces after period"
89 "First line. Second line"
90 (fill-paragraph "First line.
93 (test-equal "package-description-string vs. Unicode"
94 "b•ll•t\n\n" ;see <http://bugs.gnu.org/21536>
95 (with-fluids ((%default-port-encoding "ISO-8859-1"))
96 (package-description-string
97 (dummy-package "foo" (description "b•ll•t")))))
99 (test-equal "package-specification->name+version+output"
101 ("guile" "2.0.9" "out")
103 ("guile" "2.0.9" "debug")
104 ("guile-cairo" "1.4.1" "out"))
108 (package-specification->name+version+output spec))
114 "guile-cairo@1.4.1")))
116 (test-equal "integer"
118 (string->generations "1"))
120 (test-equal "comma-separated integers"
122 (string->generations "3,7,1,4,6"))
124 (test-equal "closed range"
125 '(4 5 6 7 8 9 10 11 12)
126 (string->generations "4..12"))
128 (test-equal "closed range, equal endpoints"
130 (string->generations "3..3"))
132 (test-equal "indefinite end range"
134 (string->generations "7.."))
136 (test-equal "indefinite start range"
138 (string->generations "..42"))
140 (test-equal "integer, char"
142 (string->generations "a"))
144 (test-equal "comma-separated integers, consecutive comma"
146 (string->generations "1,,2"))
148 (test-equal "comma-separated integers, trailing comma"
150 (string->generations "1,2,"))
152 (test-equal "comma-separated integers, chars"
154 (string->generations "a,b"))
156 (test-equal "closed range, start > end"
158 (string->generations "9..2"))
160 (test-equal "closed range, chars"
162 (string->generations "a..b"))
164 (test-equal "indefinite end range, char"
166 (string->generations "a.."))
168 (test-equal "indefinite start range, char"
170 (string->generations "..a"))
172 (test-equal "duration, 1 day"
173 (make-time time-duration 0 (* 3600 24))
174 (string->duration "1d"))
176 (test-equal "duration, 1 week"
177 (make-time time-duration 0 (* 3600 24 7))
178 (string->duration "1w"))
180 (test-equal "duration, 1 month"
181 (make-time time-duration 0 (* 3600 24 30))
182 (string->duration "1m"))
184 (test-equal "duration, 1 week == 7 days"
185 (string->duration "1w")
186 (string->duration "7d"))
188 (test-equal "duration, 1 month == 30 days"
189 (string->duration "1m")
190 (string->duration "30d"))
192 (test-equal "duration, 2 hours"
194 (time-second (string->duration "2h")))
196 (test-equal "duration, 1 second"
197 (make-time time-duration 0 1)
198 (string->duration "1s"))
200 (test-equal "duration, integer"
202 (string->duration "1"))
204 (test-equal "duration, char"
206 (string->duration "d"))
208 (test-equal "size->number, bytes"
212 (test-equal "size->number, MiB"
214 (size->number "42MiB"))
216 (test-equal "size->number, GiB"
218 (size->number "3GiB"))
220 (test-equal "size->number, 1.2GiB"
221 (inexact->exact (round (* 1.2 (expt 2 30))))
222 (size->number "1.2GiB"))
224 (test-equal "size->number, 1T"
228 (test-assert "size->number, invalid unit"
235 (test-equal "show-what-to-build, zero outputs"
238 (let ((drv (derivation store "zero" "/bin/sh" '()
240 (with-error-to-string
242 ;; This should print nothing.
243 (show-what-to-build store (list drv)))))))
245 (test-assert "show-manifest-transaction"
246 (let* ((m (manifest (list guile-1.8.8)))
247 (t (manifest-transaction (install (list guile-2.0.9)))))
249 (and (string-match "guile\t1.8.8 → 2.0.9"
250 (with-fluids ((%default-port-encoding "UTF-8"))
251 (with-error-to-string
253 (show-manifest-transaction store m t)))))
254 (string-match "guile\t1.8.8 -> 2.0.9"
255 (with-error-to-string
257 ;; In Guile 2.2, %DEFAULT-PORT-ENCODING doesn't
258 ;; influence the encoding of string ports.
259 (set-port-encoding! (current-error-port)
261 (show-manifest-transaction store m t))))))))