import-utils.scm 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2015, 2017 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. "This is a package. It is great. Trust me Mr. Hendrix."
  33. (beautify-description
  34. "This is a package. It is great. Trust me Mr. Hendrix."))
  35. (test-equal "beautify-description: transform fragment into sentence"
  36. "This package provides a function to establish world peace"
  37. (beautify-description "A function to establish world peace"))
  38. (test-equal "license->symbol"
  39. 'license:lgpl2.0
  40. (license->symbol license:lgpl2.0))
  41. (test-equal "recursive-import"
  42. '((package ;package expressions in topological order
  43. (name "bar"))
  44. (package
  45. (name "foo")
  46. (inputs `(("bar" ,bar)))))
  47. (recursive-import "foo"
  48. #:repo 'repo
  49. #:repo->guix-package
  50. (match-lambda*
  51. (("foo" #:version #f #:repo 'repo)
  52. (values '(package
  53. (name "foo")
  54. (inputs `(("bar" ,bar))))
  55. '("bar")))
  56. (("bar" #:version #f #:repo 'repo)
  57. (values '(package
  58. (name "bar"))
  59. '())))
  60. #:guix-name identity))
  61. (test-equal "recursive-import: skip false packages (toplevel)"
  62. '()
  63. (recursive-import "foo"
  64. #:repo 'repo
  65. #:repo->guix-package
  66. (match-lambda*
  67. (("foo" #:version #f #:repo 'repo)
  68. (values #f '())))
  69. #:guix-name identity))
  70. (test-equal "recursive-import: skip false packages (dependency)"
  71. '((package
  72. (name "foo")
  73. (inputs `(("bar" ,bar)))))
  74. (recursive-import "foo"
  75. #:repo 'repo
  76. #:repo->guix-package
  77. (match-lambda*
  78. (("foo" #:version #f #:repo 'repo)
  79. (values '(package
  80. (name "foo")
  81. (inputs `(("bar" ,bar))))
  82. '("bar")))
  83. (("bar" #:version #f #:repo 'repo)
  84. (values #f '())))
  85. #:guix-name identity))
  86. (test-assert "alist->package with simple source"
  87. (let* ((meta '(("name" . "hello")
  88. ("version" . "2.10")
  89. ("source" .
  90. ;; Use a 'file://' URI so that we don't cause a download.
  91. ,(string-append "file://"
  92. (search-path %load-path "guix.scm")))
  93. ("build-system" . "gnu")
  94. ("home-page" . "https://gnu.org")
  95. ("synopsis" . "Say hi")
  96. ("description" . "This package says hi.")
  97. ("license" . "GPL-3.0+")))
  98. (pkg (alist->package meta)))
  99. (and (package? pkg)
  100. (license:license? (package-license pkg))
  101. (build-system? (package-build-system pkg))
  102. (origin? (package-source pkg)))))
  103. (test-assert "alist->package with explicit source"
  104. (let* ((meta '(("name" . "hello")
  105. ("version" . "2.10")
  106. ("source" . (("method" . "url-fetch")
  107. ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
  108. ("sha256" .
  109. (("base32" .
  110. "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
  111. ("build-system" . "gnu")
  112. ("home-page" . "https://gnu.org")
  113. ("synopsis" . "Say hi")
  114. ("description" . "This package says hi.")
  115. ("license" . "GPL-3.0+")))
  116. (pkg (alist->package meta)))
  117. (and (package? pkg)
  118. (license:license? (package-license pkg))
  119. (build-system? (package-build-system pkg))
  120. (origin? (package-source pkg))
  121. (equal? (origin-sha256 (package-source pkg))
  122. (base32 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
  123. (test-equal "alist->package with false license" ;<https://bugs.gnu.org/30470>
  124. 'license-is-false
  125. (let* ((meta '(("name" . "hello")
  126. ("version" . "2.10")
  127. ("source" . (("method" . "url-fetch")
  128. ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
  129. ("sha256" .
  130. (("base32" .
  131. "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
  132. ("build-system" . "gnu")
  133. ("home-page" . "https://gnu.org")
  134. ("synopsis" . "Say hi")
  135. ("description" . "This package says hi.")
  136. ("license" . #f))))
  137. ;; Note: Use 'or' because comparing with #f otherwise succeeds when
  138. ;; there's an exception instead of an actual #f.
  139. (or (package-license (alist->package meta))
  140. 'license-is-false)))
  141. (test-equal "alist->package with SPDX license name 1/2" ;<https://bugs.gnu.org/45453>
  142. license:expat
  143. (let* ((meta '(("name" . "hello")
  144. ("version" . "2.10")
  145. ("source" . (("method" . "url-fetch")
  146. ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
  147. ("sha256" .
  148. (("base32" .
  149. "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
  150. ("build-system" . "gnu")
  151. ("home-page" . "https://gnu.org")
  152. ("synopsis" . "Say hi")
  153. ("description" . "This package says hi.")
  154. ("license" . "expat"))))
  155. (package-license (alist->package meta))))
  156. (test-equal "alist->package with SPDX license name 2/2" ;<https://bugs.gnu.org/45453>
  157. license:expat
  158. (let* ((meta '(("name" . "hello")
  159. ("version" . "2.10")
  160. ("source" . (("method" . "url-fetch")
  161. ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
  162. ("sha256" .
  163. (("base32" .
  164. "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
  165. ("build-system" . "gnu")
  166. ("home-page" . "https://gnu.org")
  167. ("synopsis" . "Say hi")
  168. ("description" . "This package says hi.")
  169. ("license" . "MIT"))))
  170. (package-license (alist->package meta))))
  171. (test-equal "alist->package with dependencies"
  172. `(("gettext" ,(specification->package "gettext")))
  173. (let* ((meta '(("name" . "hello")
  174. ("version" . "2.10")
  175. ("source" . (("method" . "url-fetch")
  176. ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
  177. ("sha256" .
  178. (("base32" .
  179. "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
  180. ("build-system" . "gnu")
  181. ("home-page" . "https://gnu.org")
  182. ("synopsis" . "Say hi")
  183. ("description" . "This package says hi.")
  184. ;
  185. ;; Note: As with Guile-JSON 3.x, JSON arrays are represented
  186. ;; by vectors.
  187. ("native-inputs" . #("gettext"))
  188. ("license" . #f))))
  189. (package-native-inputs (alist->package meta))))
  190. (test-end "import-utils")