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