import-utils.scm 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. ;;;
  6. ;;; This file is part of GNU Guix.
  7. ;;;
  8. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  9. ;;; under the terms of the GNU General Public License as published by
  10. ;;; the Free Software Foundation; either version 3 of the License, or (at
  11. ;;; your option) any later version.
  12. ;;;
  13. ;;; GNU Guix is distributed in the hope that it will be useful, but
  14. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;;; GNU General Public License for more details.
  17. ;;;
  18. ;;; You should have received a copy of the GNU General Public License
  19. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  20. (define-module (test-import-utils)
  21. #:use-module (guix tests)
  22. #:use-module (guix import utils)
  23. #:use-module ((guix licenses) #:prefix license:)
  24. #:use-module (guix packages)
  25. #:use-module (guix build-system)
  26. #:use-module (gnu packages)
  27. #:use-module (srfi srfi-64)
  28. #:use-module (ice-9 match))
  29. (test-begin "import-utils")
  30. (test-equal "beautify-description: use double spacing"
  31. "This is a package. It is great. Trust me Mr. Hendrix."
  32. (beautify-description
  33. "This is a package. It is great. Trust me Mr. Hendrix."))
  34. (test-equal "beautify-description: transform fragment into sentence"
  35. "This package provides a function to establish world peace"
  36. (beautify-description "A function to establish world peace"))
  37. (test-equal "license->symbol"
  38. 'license:lgpl2.0
  39. (license->symbol license:lgpl2.0))
  40. (test-equal "recursive-import"
  41. '((package ;package expressions in topological order
  42. (name "bar"))
  43. (package
  44. (name "foo")
  45. (inputs `(("bar" ,bar)))))
  46. (recursive-import "foo"
  47. #:repo 'repo
  48. #:repo->guix-package
  49. (match-lambda*
  50. (("foo" #:version #f #:repo 'repo)
  51. (values '(package
  52. (name "foo")
  53. (inputs `(("bar" ,bar))))
  54. '("bar")))
  55. (("bar" #:version #f #:repo 'repo)
  56. (values '(package
  57. (name "bar"))
  58. '())))
  59. #:guix-name identity))
  60. (test-assert "alist->package with simple source"
  61. (let* ((meta '(("name" . "hello")
  62. ("version" . "2.10")
  63. ("source" .
  64. ;; Use a 'file://' URI so that we don't cause a download.
  65. ,(string-append "file://"
  66. (search-path %load-path "guix.scm")))
  67. ("build-system" . "gnu")
  68. ("home-page" . "https://gnu.org")
  69. ("synopsis" . "Say hi")
  70. ("description" . "This package says hi.")
  71. ("license" . "GPL-3.0+")))
  72. (pkg (alist->package meta)))
  73. (and (package? pkg)
  74. (license:license? (package-license pkg))
  75. (build-system? (package-build-system pkg))
  76. (origin? (package-source pkg)))))
  77. (test-assert "alist->package with explicit source"
  78. (let* ((meta '(("name" . "hello")
  79. ("version" . "2.10")
  80. ("source" . (("method" . "url-fetch")
  81. ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
  82. ("sha256" .
  83. (("base32" .
  84. "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
  85. ("build-system" . "gnu")
  86. ("home-page" . "https://gnu.org")
  87. ("synopsis" . "Say hi")
  88. ("description" . "This package says hi.")
  89. ("license" . "GPL-3.0+")))
  90. (pkg (alist->package meta)))
  91. (and (package? pkg)
  92. (license:license? (package-license pkg))
  93. (build-system? (package-build-system pkg))
  94. (origin? (package-source pkg))
  95. (equal? (origin-sha256 (package-source pkg))
  96. (base32 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
  97. (test-equal "alist->package with false license" ;<https://bugs.gnu.org/30470>
  98. 'license-is-false
  99. (let* ((meta '(("name" . "hello")
  100. ("version" . "2.10")
  101. ("source" . (("method" . "url-fetch")
  102. ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
  103. ("sha256" .
  104. (("base32" .
  105. "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
  106. ("build-system" . "gnu")
  107. ("home-page" . "https://gnu.org")
  108. ("synopsis" . "Say hi")
  109. ("description" . "This package says hi.")
  110. ("license" . #f))))
  111. ;; Note: Use 'or' because comparing with #f otherwise succeeds when
  112. ;; there's an exception instead of an actual #f.
  113. (or (package-license (alist->package meta))
  114. 'license-is-false)))
  115. (test-equal "alist->package with SPDX license name 1/2" ;<https://bugs.gnu.org/45453>
  116. license:expat
  117. (let* ((meta '(("name" . "hello")
  118. ("version" . "2.10")
  119. ("source" . (("method" . "url-fetch")
  120. ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
  121. ("sha256" .
  122. (("base32" .
  123. "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
  124. ("build-system" . "gnu")
  125. ("home-page" . "https://gnu.org")
  126. ("synopsis" . "Say hi")
  127. ("description" . "This package says hi.")
  128. ("license" . "expat"))))
  129. (package-license (alist->package meta))))
  130. (test-equal "alist->package with SPDX license name 2/2" ;<https://bugs.gnu.org/45453>
  131. license:expat
  132. (let* ((meta '(("name" . "hello")
  133. ("version" . "2.10")
  134. ("source" . (("method" . "url-fetch")
  135. ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
  136. ("sha256" .
  137. (("base32" .
  138. "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
  139. ("build-system" . "gnu")
  140. ("home-page" . "https://gnu.org")
  141. ("synopsis" . "Say hi")
  142. ("description" . "This package says hi.")
  143. ("license" . "MIT"))))
  144. (package-license (alist->package meta))))
  145. (test-equal "alist->package with dependencies"
  146. `(("gettext" ,(specification->package "gettext")))
  147. (let* ((meta '(("name" . "hello")
  148. ("version" . "2.10")
  149. ("source" . (("method" . "url-fetch")
  150. ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
  151. ("sha256" .
  152. (("base32" .
  153. "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
  154. ("build-system" . "gnu")
  155. ("home-page" . "https://gnu.org")
  156. ("synopsis" . "Say hi")
  157. ("description" . "This package says hi.")
  158. ;
  159. ;; Note: As with Guile-JSON 3.x, JSON arrays are represented
  160. ;; by vectors.
  161. ("native-inputs" . #("gettext"))
  162. ("license" . #f))))
  163. (package-native-inputs (alist->package meta))))
  164. (test-end "import-utils")