ui.scm 7.4 KB

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