packages: Factorize package specification search.
[jackhill/guix/guix.git] / tests / ui.scm
CommitLineData
299112d3 1;;; GNU Guix --- Functional package management for GNU
77ee4a96 2;;; Copyright © 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
299112d3
LC
3;;;
4;;; This file is part of GNU Guix.
5;;;
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.
10;;;
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.
15;;;
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/>.
18
19
20(define-module (test-ui)
21 #:use-module (guix ui)
5d7a8584 22 #:use-module (guix profiles)
52ddf2ae
LC
23 #:use-module (guix store)
24 #:use-module (guix derivations)
08d7e359 25 #:use-module (guix tests)
299112d3 26 #:use-module (srfi srfi-1)
5d7a8584 27 #:use-module (srfi srfi-11)
2cd09108 28 #:use-module (srfi srfi-19)
5d7a8584
AK
29 #:use-module (srfi srfi-64)
30 #:use-module (ice-9 regex))
299112d3
LC
31
32;; Test the (guix ui) module.
33
34(define %paragraph
35 "GNU Guile is an implementation of the Scheme programming language, with
36support for many SRFIs, packaged for use in a wide variety of environments.
37In addition to implementing the R5RS Scheme standard and a large subset of
38R6RS, Guile includes a module system, full access to POSIX system calls,
39networking support, multiple threads, dynamic linking, a foreign function call
40interface, and powerful string processing.")
41
5d7a8584
AK
42(define guile-1.8.8
43 (manifest-entry
44 (name "guile")
45 (version "1.8.8")
46 (item "/gnu/store/...")
47 (output "out")))
48
49(define guile-2.0.9
50 (manifest-entry
51 (name "guile")
52 (version "2.0.9")
53 (item "/gnu/store/...")
54 (output "out")))
55
299112d3
LC
56\f
57(test-begin "ui")
58
59(test-assert "fill-paragraph"
60 (every (lambda (column)
61 (every (lambda (width)
62 (every (lambda (line)
63 (<= (string-length line) width))
64 (string-split (fill-paragraph %paragraph
65 width column)
66 #\newline)))
67 '(15 30 35 40 45 50 60 70 80 90 100)))
68 '(0 5)))
69
70(test-assert "fill-paragraph, consecutive newlines"
71 (every (lambda (width)
72 (any (lambda (line)
73 (string-prefix? "When STR" line))
74 (string-split
75 (fill-paragraph (procedure-documentation fill-paragraph)
76 width)
77 #\newline)))
78 '(15 20 25 30 40 50 60)))
79
80(test-equal "fill-paragraph, large unbreakable word"
81 '("Here is a" "very-very-long-word"
82 "and that's" "it.")
83 (string-split
84 (fill-paragraph "Here is a very-very-long-word and that's it."
85 10)
86 #\newline))
87
3a09e1d2
CS
88(test-equal "fill-paragraph, two spaces after period"
89 "First line. Second line"
90 (fill-paragraph "First line.
91Second line" 24))
92
08d7e359
LC
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")))))
98
2876b989
LC
99(test-equal "package-specification->name+version+output"
100 '(("guile" #f "out")
101 ("guile" "2.0.9" "out")
102 ("guile" #f "debug")
103 ("guile" "2.0.9" "debug")
104 ("guile-cairo" "1.4.1" "out"))
105 (map (lambda (spec)
106 (call-with-values
107 (lambda ()
108 (package-specification->name+version+output spec))
109 list))
110 '("guile"
111 "guile-2.0.9"
112 "guile:debug"
113 "guile-2.0.9:debug"
114 "guile-cairo-1.4.1")))
115
2cd09108
NK
116(test-equal "integer"
117 '(1)
118 (string->generations "1"))
119
120(test-equal "comma-separated integers"
121 '(3 7 1 4 6)
122 (string->generations "3,7,1,4,6"))
123
124(test-equal "closed range"
125 '(4 5 6 7 8 9 10 11 12)
126 (string->generations "4..12"))
127
128(test-equal "closed range, equal endpoints"
129 '(3)
130 (string->generations "3..3"))
131
132(test-equal "indefinite end range"
133 '(>= 7)
134 (string->generations "7.."))
135
136(test-equal "indefinite start range"
137 '(<= 42)
138 (string->generations "..42"))
139
140(test-equal "integer, char"
141 #f
142 (string->generations "a"))
143
144(test-equal "comma-separated integers, consecutive comma"
145 #f
146 (string->generations "1,,2"))
147
148(test-equal "comma-separated integers, trailing comma"
149 #f
150 (string->generations "1,2,"))
151
152(test-equal "comma-separated integers, chars"
153 #f
154 (string->generations "a,b"))
155
156(test-equal "closed range, start > end"
157 #f
158 (string->generations "9..2"))
159
160(test-equal "closed range, chars"
161 #f
162 (string->generations "a..b"))
163
164(test-equal "indefinite end range, char"
165 #f
166 (string->generations "a.."))
167
168(test-equal "indefinite start range, char"
169 #f
170 (string->generations "..a"))
171
172(test-equal "duration, 1 day"
173 (make-time time-duration 0 (* 3600 24))
174 (string->duration "1d"))
175
176(test-equal "duration, 1 week"
177 (make-time time-duration 0 (* 3600 24 7))
178 (string->duration "1w"))
179
180(test-equal "duration, 1 month"
181 (make-time time-duration 0 (* 3600 24 30))
182 (string->duration "1m"))
183
184(test-equal "duration, 1 week == 7 days"
185 (string->duration "1w")
186 (string->duration "7d"))
187
188(test-equal "duration, 1 month == 30 days"
189 (string->duration "1m")
190 (string->duration "30d"))
191
192(test-equal "duration, integer"
193 #f
194 (string->duration "1"))
195
196(test-equal "duration, char"
197 #f
198 (string->duration "d"))
199
1d6243cf
LC
200(test-equal "size->number, bytes"
201 42
202 (size->number "42"))
203
204(test-equal "size->number, MiB"
205 (* 42 (expt 2 20))
206 (size->number "42MiB"))
207
208(test-equal "size->number, GiB"
209 (* 3 (expt 2 30))
210 (size->number "3GiB"))
211
212(test-equal "size->number, 1.2GiB"
213 (inexact->exact (round (* 1.2 (expt 2 30))))
214 (size->number "1.2GiB"))
215
4a44d7bb
LC
216(test-equal "size->number, 1T"
217 (expt 2 40)
218 (size->number "1T"))
219
1d6243cf
LC
220(test-assert "size->number, invalid unit"
221 (catch 'quit
222 (lambda ()
223 (size->number "9X"))
224 (lambda args
225 #t)))
226
52ddf2ae
LC
227(test-equal "show-what-to-build, zero outputs"
228 ""
229 (with-store store
230 (let ((drv (derivation store "zero" "/bin/sh" '()
231 #:outputs '())))
232 (with-error-to-string
233 (lambda ()
234 ;; This should print nothing.
235 (show-what-to-build store (list drv)))))))
236
5d7a8584
AK
237(test-assert "show-manifest-transaction"
238 (let* ((m (manifest (list guile-1.8.8)))
239 (t (manifest-transaction (install (list guile-2.0.9)))))
77ee4a96
LC
240 (with-store store
241 (and (string-match "guile\t1.8.8 → 2.0.9"
242 (with-fluids ((%default-port-encoding "UTF-8"))
243 (with-error-to-string
244 (lambda ()
245 (show-manifest-transaction store m t)))))
246 (string-match "guile\t1.8.8 -> 2.0.9"
247 (with-fluids ((%default-port-encoding "ISO-8859-1"))
248 (with-error-to-string
249 (lambda ()
250 (show-manifest-transaction store m t)))))))))
5d7a8584 251
299112d3
LC
252(test-end "ui")
253
254\f
255(exit (= (test-runner-fail-count (test-runner-current)) 0))