gem.scm 6.3 KB

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