import-utils.scm 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2015, 2017, 2022, 2023 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 "beautify-description: wrap PascalCase words in @code"
  50. "The term @code{DelayedMatrix} refers to a class."
  51. (beautify-description "The term DelayedMatrix refers to a class."))
  52. (test-equal "beautify-description: do not wrap acronyms in @code"
  53. "The term API is not code, but @code{myAPI} might be."
  54. (beautify-description "The term API is not code, but myAPI might be."))
  55. (test-equal "beautify-description: do not include punctuation when wrapping in @code"
  56. "Code (@code{DelayedMatrix}, @code{MaMa}, or @code{MeMe}) should be wrapped."
  57. (beautify-description "Code (DelayedMatrix, MaMa, or MeMe) should be wrapped."))
  58. (test-equal "license->symbol"
  59. 'license:lgpl2.0
  60. (license->symbol license:lgpl2.0))
  61. (test-equal "recursive-import"
  62. '((package ;package expressions in topological order
  63. (name "bar"))
  64. (package
  65. (name "foo")
  66. (inputs `(("bar" ,bar)))))
  67. (recursive-import "foo"
  68. #:repo 'repo
  69. #:repo->guix-package
  70. (match-lambda*
  71. (("foo" #:repo 'repo . rest)
  72. (values '(package
  73. (name "foo")
  74. (inputs `(("bar" ,bar))))
  75. '("bar")))
  76. (("bar" #:repo 'repo . rest)
  77. (values '(package
  78. (name "bar"))
  79. '())))
  80. #:guix-name identity))
  81. (test-equal "recursive-import: skip false packages (toplevel)"
  82. '()
  83. (recursive-import "foo"
  84. #:repo 'repo
  85. #:repo->guix-package
  86. (match-lambda*
  87. (("foo" #:repo 'repo . rest)
  88. (values #f '())))
  89. #:guix-name identity))
  90. (test-equal "recursive-import: skip false packages (dependency)"
  91. '((package
  92. (name "foo")
  93. (inputs `(("bar" ,bar)))))
  94. (recursive-import "foo"
  95. #:repo 'repo
  96. #:repo->guix-package
  97. (match-lambda*
  98. (("foo" #:repo 'repo . rest)
  99. (values '(package
  100. (name "foo")
  101. (inputs `(("bar" ,bar))))
  102. '("bar")))
  103. (("bar" #:repo 'repo . rest)
  104. (values #f '())))
  105. #:guix-name identity))
  106. (test-assert "alist->package with simple source"
  107. (let* ((meta '(("name" . "hello")
  108. ("version" . "2.10")
  109. ("source" .
  110. ;; Use a 'file://' URI so that we don't cause a download.
  111. ,(string-append "file://"
  112. (search-path %load-path "guix.scm")))
  113. ("build-system" . "gnu")
  114. ("home-page" . "https://gnu.org")
  115. ("synopsis" . "Say hi")
  116. ("description" . "This package says hi.")
  117. ("license" . "GPL-3.0+")))
  118. (pkg (alist->package meta)))
  119. (and (package? pkg)
  120. (license:license? (package-license pkg))
  121. (build-system? (package-build-system pkg))
  122. (origin? (package-source pkg)))))
  123. (test-assert "alist->package with explicit source"
  124. (let* ((meta '(("name" . "hello")
  125. ("version" . "2.10")
  126. ("source" . (("method" . "url-fetch")
  127. ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
  128. ("sha256" .
  129. (("base32" .
  130. "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
  131. ("build-system" . "gnu")
  132. ("home-page" . "https://gnu.org")
  133. ("synopsis" . "Say hi")
  134. ("description" . "This package says hi.")
  135. ("license" . "GPL-3.0+")))
  136. (pkg (alist->package meta)))
  137. (and (package? pkg)
  138. (license:license? (package-license pkg))
  139. (build-system? (package-build-system pkg))
  140. (origin? (package-source pkg))
  141. (equal? (content-hash-value (origin-hash (package-source pkg)))
  142. (base32 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
  143. (test-equal "alist->package with false license" ;<https://bugs.gnu.org/30470>
  144. 'license-is-false
  145. (let* ((meta '(("name" . "hello")
  146. ("version" . "2.10")
  147. ("source" . (("method" . "url-fetch")
  148. ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
  149. ("sha256" .
  150. (("base32" .
  151. "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
  152. ("build-system" . "gnu")
  153. ("home-page" . "https://gnu.org")
  154. ("synopsis" . "Say hi")
  155. ("description" . "This package says hi.")
  156. ("license" . #f))))
  157. ;; Note: Use 'or' because comparing with #f otherwise succeeds when
  158. ;; there's an exception instead of an actual #f.
  159. (or (package-license (alist->package meta))
  160. 'license-is-false)))
  161. (test-equal "alist->package with SPDX license name 1/2" ;<https://bugs.gnu.org/45453>
  162. license:expat
  163. (let* ((meta '(("name" . "hello")
  164. ("version" . "2.10")
  165. ("source" . (("method" . "url-fetch")
  166. ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
  167. ("sha256" .
  168. (("base32" .
  169. "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
  170. ("build-system" . "gnu")
  171. ("home-page" . "https://gnu.org")
  172. ("synopsis" . "Say hi")
  173. ("description" . "This package says hi.")
  174. ("license" . "expat"))))
  175. (package-license (alist->package meta))))
  176. (test-equal "alist->package with SPDX license name 2/2" ;<https://bugs.gnu.org/45453>
  177. license:expat
  178. (let* ((meta '(("name" . "hello")
  179. ("version" . "2.10")
  180. ("source" . (("method" . "url-fetch")
  181. ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
  182. ("sha256" .
  183. (("base32" .
  184. "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
  185. ("build-system" . "gnu")
  186. ("home-page" . "https://gnu.org")
  187. ("synopsis" . "Say hi")
  188. ("description" . "This package says hi.")
  189. ("license" . "MIT"))))
  190. (package-license (alist->package meta))))
  191. (test-equal "alist->package with dependencies"
  192. `(("gettext" ,(specification->package "gettext")))
  193. (let* ((meta '(("name" . "hello")
  194. ("version" . "2.10")
  195. ("source" . (("method" . "url-fetch")
  196. ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
  197. ("sha256" .
  198. (("base32" .
  199. "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
  200. ("build-system" . "gnu")
  201. ("home-page" . "https://gnu.org")
  202. ("synopsis" . "Say hi")
  203. ("description" . "This package says hi.")
  204. ;
  205. ;; Note: As with Guile-JSON 3.x, JSON arrays are represented
  206. ;; by vectors.
  207. ("native-inputs" . #("gettext"))
  208. ("license" . #f))))
  209. (package-native-inputs (alist->package meta))))
  210. (test-assert "alist->package with properties"
  211. (let* ((meta '(("name" . "hello")
  212. ("version" . "2.10")
  213. ("source" .
  214. ;; Use a 'file://' URI so that we don't cause a download.
  215. ,(string-append "file://"
  216. (search-path %load-path "guix.scm")))
  217. ("build-system" . "gnu")
  218. ("properties" . (("hidden?" . #t)
  219. ("upstream-name" . "hello-upstream")))
  220. ("home-page" . "https://gnu.org")
  221. ("synopsis" . "Say hi")
  222. ("description" . "This package says hi.")
  223. ("license" . "GPL-3.0+")))
  224. (pkg (alist->package meta)))
  225. (and (package? pkg)
  226. (equal? (package-upstream-name pkg) "hello-upstream")
  227. (hidden-package? pkg))))
  228. (test-equal "spdx-string->license"
  229. '(license:gpl3+ license:agpl3 license:gpl2+)
  230. (map spdx-string->license
  231. '("GPL-3.0-oR-LaTeR" "AGPL-3.0" "GPL-2.0+")))
  232. (test-end "import-utils")