import-utils.scm 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2015, 2017, 2022 Ricardo Wurmus <rekado@elephly.net>
  3. ;;; Copyright © 2016 Ben Woodcroft <donttrustben@gmail.com>
  4. ;;; Copyright © 2020 Martin Becze <mjbecze@riseup.net>
  5. ;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
  6. ;;;
  7. ;;; This file is part of GNU Guix.
  8. ;;;
  9. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  10. ;;; under the terms of the GNU General Public License as published by
  11. ;;; the Free Software Foundation; either version 3 of the License, or (at
  12. ;;; your option) any later version.
  13. ;;;
  14. ;;; GNU Guix is distributed in the hope that it will be useful, but
  15. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;;; GNU General Public License for more details.
  18. ;;;
  19. ;;; You should have received a copy of the GNU General Public License
  20. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  21. (define-module (test-import-utils)
  22. #:use-module (guix tests)
  23. #:use-module (guix import utils)
  24. #:use-module ((guix licenses) #:prefix license:)
  25. #:use-module (guix packages)
  26. #:use-module (guix build-system)
  27. #:use-module (gnu packages)
  28. #:use-module (srfi srfi-64)
  29. #:use-module (ice-9 match))
  30. (test-begin "import-utils")
  31. (test-equal "beautify-description: use double spacing"
  32. "\
  33. Trust me Mr. Hendrix, M. Night Shyamalan et al. \
  34. Differences are hard to spot,
  35. e.g. in CLOS vs. GOOPS."
  36. (beautify-description
  37. "
  38. Trust me Mr. Hendrix, M. Night Shyamalan et al. \
  39. Differences are hard to spot, e.g. in CLOS vs. GOOPS."))
  40. (test-equal "beautify-description: transform fragment into sentence"
  41. "This package provides a function to establish world peace"
  42. (beautify-description "A function to establish world peace"))
  43. (test-equal "beautify-description: remove single quotes"
  44. "CRAN likes to quote acronyms and function names."
  45. (beautify-description "CRAN likes to 'quote' acronyms and 'function' names."))
  46. (test-equal "beautify-description: escape @"
  47. "This @@ is not Texinfo syntax. Neither is this %@@>%."
  48. (beautify-description "This @ is not Texinfo syntax. Neither is this %@>%."))
  49. (test-equal "license->symbol"
  50. 'license:lgpl2.0
  51. (license->symbol license:lgpl2.0))
  52. (test-equal "recursive-import"
  53. '((package ;package expressions in topological order
  54. (name "bar"))
  55. (package
  56. (name "foo")
  57. (inputs `(("bar" ,bar)))))
  58. (recursive-import "foo"
  59. #:repo 'repo
  60. #:repo->guix-package
  61. (match-lambda*
  62. (("foo" #:repo 'repo . rest)
  63. (values '(package
  64. (name "foo")
  65. (inputs `(("bar" ,bar))))
  66. '("bar")))
  67. (("bar" #:repo 'repo . rest)
  68. (values '(package
  69. (name "bar"))
  70. '())))
  71. #:guix-name identity))
  72. (test-equal "recursive-import: skip false packages (toplevel)"
  73. '()
  74. (recursive-import "foo"
  75. #:repo 'repo
  76. #:repo->guix-package
  77. (match-lambda*
  78. (("foo" #:repo 'repo . rest)
  79. (values #f '())))
  80. #:guix-name identity))
  81. (test-equal "recursive-import: skip false packages (dependency)"
  82. '((package
  83. (name "foo")
  84. (inputs `(("bar" ,bar)))))
  85. (recursive-import "foo"
  86. #:repo 'repo
  87. #:repo->guix-package
  88. (match-lambda*
  89. (("foo" #:repo 'repo . rest)
  90. (values '(package
  91. (name "foo")
  92. (inputs `(("bar" ,bar))))
  93. '("bar")))
  94. (("bar" #:repo 'repo . rest)
  95. (values #f '())))
  96. #:guix-name identity))
  97. (test-assert "alist->package with simple source"
  98. (let* ((meta '(("name" . "hello")
  99. ("version" . "2.10")
  100. ("source" .
  101. ;; Use a 'file://' URI so that we don't cause a download.
  102. ,(string-append "file://"
  103. (search-path %load-path "guix.scm")))
  104. ("build-system" . "gnu")
  105. ("home-page" . "https://gnu.org")
  106. ("synopsis" . "Say hi")
  107. ("description" . "This package says hi.")
  108. ("license" . "GPL-3.0+")))
  109. (pkg (alist->package meta)))
  110. (and (package? pkg)
  111. (license:license? (package-license pkg))
  112. (build-system? (package-build-system pkg))
  113. (origin? (package-source pkg)))))
  114. (test-assert "alist->package with explicit source"
  115. (let* ((meta '(("name" . "hello")
  116. ("version" . "2.10")
  117. ("source" . (("method" . "url-fetch")
  118. ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
  119. ("sha256" .
  120. (("base32" .
  121. "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
  122. ("build-system" . "gnu")
  123. ("home-page" . "https://gnu.org")
  124. ("synopsis" . "Say hi")
  125. ("description" . "This package says hi.")
  126. ("license" . "GPL-3.0+")))
  127. (pkg (alist->package meta)))
  128. (and (package? pkg)
  129. (license:license? (package-license pkg))
  130. (build-system? (package-build-system pkg))
  131. (origin? (package-source pkg))
  132. (equal? (content-hash-value (origin-hash (package-source pkg)))
  133. (base32 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
  134. (test-equal "alist->package with false license" ;<https://bugs.gnu.org/30470>
  135. 'license-is-false
  136. (let* ((meta '(("name" . "hello")
  137. ("version" . "2.10")
  138. ("source" . (("method" . "url-fetch")
  139. ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
  140. ("sha256" .
  141. (("base32" .
  142. "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
  143. ("build-system" . "gnu")
  144. ("home-page" . "https://gnu.org")
  145. ("synopsis" . "Say hi")
  146. ("description" . "This package says hi.")
  147. ("license" . #f))))
  148. ;; Note: Use 'or' because comparing with #f otherwise succeeds when
  149. ;; there's an exception instead of an actual #f.
  150. (or (package-license (alist->package meta))
  151. 'license-is-false)))
  152. (test-equal "alist->package with SPDX license name 1/2" ;<https://bugs.gnu.org/45453>
  153. license:expat
  154. (let* ((meta '(("name" . "hello")
  155. ("version" . "2.10")
  156. ("source" . (("method" . "url-fetch")
  157. ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
  158. ("sha256" .
  159. (("base32" .
  160. "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
  161. ("build-system" . "gnu")
  162. ("home-page" . "https://gnu.org")
  163. ("synopsis" . "Say hi")
  164. ("description" . "This package says hi.")
  165. ("license" . "expat"))))
  166. (package-license (alist->package meta))))
  167. (test-equal "alist->package with SPDX license name 2/2" ;<https://bugs.gnu.org/45453>
  168. license:expat
  169. (let* ((meta '(("name" . "hello")
  170. ("version" . "2.10")
  171. ("source" . (("method" . "url-fetch")
  172. ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
  173. ("sha256" .
  174. (("base32" .
  175. "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
  176. ("build-system" . "gnu")
  177. ("home-page" . "https://gnu.org")
  178. ("synopsis" . "Say hi")
  179. ("description" . "This package says hi.")
  180. ("license" . "MIT"))))
  181. (package-license (alist->package meta))))
  182. (test-equal "alist->package with dependencies"
  183. `(("gettext" ,(specification->package "gettext")))
  184. (let* ((meta '(("name" . "hello")
  185. ("version" . "2.10")
  186. ("source" . (("method" . "url-fetch")
  187. ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
  188. ("sha256" .
  189. (("base32" .
  190. "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
  191. ("build-system" . "gnu")
  192. ("home-page" . "https://gnu.org")
  193. ("synopsis" . "Say hi")
  194. ("description" . "This package says hi.")
  195. ;
  196. ;; Note: As with Guile-JSON 3.x, JSON arrays are represented
  197. ;; by vectors.
  198. ("native-inputs" . #("gettext"))
  199. ("license" . #f))))
  200. (package-native-inputs (alist->package meta))))
  201. (test-assert "alist->package with properties"
  202. (let* ((meta '(("name" . "hello")
  203. ("version" . "2.10")
  204. ("source" .
  205. ;; Use a 'file://' URI so that we don't cause a download.
  206. ,(string-append "file://"
  207. (search-path %load-path "guix.scm")))
  208. ("build-system" . "gnu")
  209. ("properties" . (("hidden?" . #t)
  210. ("upstream-name" . "hello-upstream")))
  211. ("home-page" . "https://gnu.org")
  212. ("synopsis" . "Say hi")
  213. ("description" . "This package says hi.")
  214. ("license" . "GPL-3.0+")))
  215. (pkg (alist->package meta)))
  216. (and (package? pkg)
  217. (equal? (package-upstream-name pkg) "hello-upstream")
  218. (hidden-package? pkg))))
  219. (test-equal "spdx-string->license"
  220. '(license:gpl3+ license:agpl3 license:gpl2+)
  221. (map spdx-string->license
  222. '("GPL-3.0-oR-LaTeR" "AGPL-3.0" "GPL-2.0+")))
  223. (test-end "import-utils")