Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

182 řádky
6.4 KiB

  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2015 David Thompson <davet@gnu.org>
  3. ;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
  4. ;;; Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com>
  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-gem)
  21. #:use-module (guix import gem)
  22. #:use-module (guix base32)
  23. #:use-module (gcrypt hash)
  24. #:use-module (guix tests)
  25. #:use-module ((guix build utils) #:select (delete-file-recursively))
  26. #:use-module (srfi srfi-41)
  27. #:use-module (srfi srfi-64)
  28. #:use-module (ice-9 match))
  29. (define test-foo-json
  30. "{
  31. \"name\": \"foo\",
  32. \"version\": \"1.0.0\",
  33. \"sha\": \"f3676eafca9987cb5fe263df1edf2538bf6dafc712b30e17be3543a9680547a8\",
  34. \"info\": \"A cool gem\",
  35. \"homepage_uri\": \"https://example.com\",
  36. \"dependencies\": {
  37. \"runtime\": [
  38. { \"name\": \"bundler\" },
  39. { \"name\": \"bar\" }
  40. ]
  41. },
  42. \"licenses\": [\"MIT\", \"Apache 2.0\"]
  43. }")
  44. (define test-bar-json
  45. "{
  46. \"name\": \"bar\",
  47. \"version\": \"1.0.0\",
  48. \"sha\": \"f3676eafca9987cb5fe263df1edf2538bf6dafc712b30e17be3543a9680547a8\",
  49. \"info\": \"Another cool gem\",
  50. \"homepage_uri\": \"https://example.com\",
  51. \"dependencies\": {
  52. \"runtime\": [
  53. { \"name\": \"bundler\" },
  54. ]
  55. },
  56. \"licenses\": [\"MIT\", \"Apache 2.0\"]
  57. }")
  58. (define test-bundler-json
  59. "{
  60. \"name\": \"bundler\",
  61. \"version\": \"1.14.2\",
  62. \"sha\": \"3bb53e03db0a8008161eb4c816ccd317120d3c415ba6fee6f90bbc7f7eec8690\",
  63. \"info\": \"Ruby gem bundler\",
  64. \"homepage_uri\": \"https://bundler.io/\",
  65. \"dependencies\": {
  66. \"runtime\": []
  67. },
  68. \"licenses\": [\"MIT\"]
  69. }")
  70. (test-begin "gem")
  71. (test-assert "gem->guix-package"
  72. ;; Replace network resources with sample data.
  73. (mock ((guix http-client) http-fetch
  74. (lambda (url . rest)
  75. (match url
  76. ("https://rubygems.org/api/v1/gems/foo.json"
  77. (values (open-input-string test-foo-json)
  78. (string-length test-foo-json)))
  79. (_ (error "Unexpected URL: " url)))))
  80. (match (gem->guix-package "foo")
  81. (('package
  82. ('name "ruby-foo")
  83. ('version "1.0.0")
  84. ('source ('origin
  85. ('method 'url-fetch)
  86. ('uri ('rubygems-uri "foo" 'version))
  87. ('sha256
  88. ('base32
  89. "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk"))))
  90. ('build-system 'ruby-build-system)
  91. ('propagated-inputs
  92. ('quasiquote
  93. (("bundler" ('unquote 'bundler))
  94. ("ruby-bar" ('unquote 'ruby-bar)))))
  95. ('synopsis "A cool gem")
  96. ('description "This package provides a cool gem")
  97. ('home-page "https://example.com")
  98. ('license ('list 'license:expat 'license:asl2.0)))
  99. #t)
  100. (x
  101. (pk 'fail x #f)))))
  102. (test-assert "gem-recursive-import"
  103. ;; Replace network resources with sample data.
  104. (mock ((guix http-client) http-fetch
  105. (lambda (url . rest)
  106. (match url
  107. ("https://rubygems.org/api/v1/gems/foo.json"
  108. (values (open-input-string test-foo-json)
  109. (string-length test-foo-json)))
  110. ("https://rubygems.org/api/v1/gems/bar.json"
  111. (values (open-input-string test-bar-json)
  112. (string-length test-bar-json)))
  113. ("https://rubygems.org/api/v1/gems/bundler.json"
  114. (values (open-input-string test-bundler-json)
  115. (string-length test-bundler-json)))
  116. (_ (error "Unexpected URL: " url)))))
  117. (match (stream->list (gem-recursive-import "foo"))
  118. ((('package
  119. ('name "ruby-foo")
  120. ('version "1.0.0")
  121. ('source
  122. ('origin
  123. ('method 'url-fetch)
  124. ('uri ('rubygems-uri "foo" 'version))
  125. ('sha256
  126. ('base32
  127. "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk"))))
  128. ('build-system 'ruby-build-system)
  129. ('propagated-inputs
  130. ('quasiquote
  131. (("bundler" ('unquote 'bundler))
  132. ("ruby-bar" ('unquote 'ruby-bar)))))
  133. ('synopsis "A cool gem")
  134. ('description "This package provides a cool gem")
  135. ('home-page "https://example.com")
  136. ('license ('list 'license:expat 'license:asl2.0)))
  137. ('package
  138. ('name "ruby-bundler")
  139. ('version "1.14.2")
  140. ('source
  141. ('origin
  142. ('method 'url-fetch)
  143. ('uri ('rubygems-uri "bundler" 'version))
  144. ('sha256
  145. ('base32
  146. "1446xiz7zg0bz7kgx9jv84y0s4hpsg61dj5l3qb0i00avc1kxd9v"))))
  147. ('build-system 'ruby-build-system)
  148. ('synopsis "Ruby gem bundler")
  149. ('description "Ruby gem bundler")
  150. ('home-page "https://bundler.io/")
  151. ('license 'license:expat))
  152. ('package
  153. ('name "ruby-bar")
  154. ('version "1.0.0")
  155. ('source
  156. ('origin
  157. ('method 'url-fetch)
  158. ('uri ('rubygems-uri "bar" 'version))
  159. ('sha256
  160. ('base32
  161. "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk"))))
  162. ('build-system 'ruby-build-system)
  163. ('propagated-inputs
  164. ('quasiquote
  165. (('"bundler" ('unquote 'bundler)))))
  166. ('synopsis "Another cool gem")
  167. ('description "Another cool gem")
  168. ('home-page "https://example.com")
  169. ('license ('list 'license:expat 'license:asl2.0))))
  170. #t)
  171. (x
  172. (pk 'fail x #f)))))
  173. (test-end "gem")