import-utils.scm 6.0 KB

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