gem.scm 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. ;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
  6. ;;; Copyright © 2022 Taiju HIGASHI <higashi@taiju.info>
  7. ;;; Copyright © 2023 Ludovic Courtès <ludo@gnu.org>
  8. ;;;
  9. ;;; This file is part of GNU Guix.
  10. ;;;
  11. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  12. ;;; under the terms of the GNU General Public License as published by
  13. ;;; the Free Software Foundation; either version 3 of the License, or (at
  14. ;;; your option) any later version.
  15. ;;;
  16. ;;; GNU Guix is distributed in the hope that it will be useful, but
  17. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. ;;; GNU General Public License for more details.
  20. ;;;
  21. ;;; You should have received a copy of the GNU General Public License
  22. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  23. (define-module (test-gem)
  24. #:use-module (guix import gem)
  25. #:use-module (guix upstream)
  26. #:use-module ((guix download) #:select (url-fetch))
  27. #:use-module ((guix build-system ruby) #:select (rubygems-uri))
  28. #:use-module (guix base32)
  29. #:use-module (gcrypt hash)
  30. #:use-module (guix tests)
  31. #:use-module ((guix build utils) #:select (delete-file-recursively))
  32. #:use-module (srfi srfi-64)
  33. #:use-module (ice-9 match))
  34. (define test-foo-json
  35. "{
  36. \"name\": \"foo\",
  37. \"version\": \"1.0.0\",
  38. \"sha\": \"f3676eafca9987cb5fe263df1edf2538bf6dafc712b30e17be3543a9680547a8\",
  39. \"info\": \"A cool gem\",
  40. \"homepage_uri\": \"https://example.com\",
  41. \"dependencies\": {
  42. \"runtime\": [
  43. { \"name\": \"bundler\" },
  44. { \"name\": \"bar\" }
  45. ]
  46. },
  47. \"licenses\": [\"MIT\", \"Apache 2.0\"]
  48. }")
  49. (define test-foo-v2-json
  50. "{
  51. \"name\": \"foo\",
  52. \"version\": \"2.0.0\",
  53. \"sha\": \"f3676eafca9987cb5fe263df1edf2538bf6dafc712b30e17be3543a9680547a8\",
  54. \"info\": \"A cool gem\",
  55. \"homepage_uri\": \"https://example.com\",
  56. \"dependencies\": {
  57. \"runtime\": [
  58. { \"name\": \"bundler\" },
  59. { \"name\": \"bar\" }
  60. ]
  61. },
  62. \"licenses\": [\"MIT\", \"Apache 2.0\"]
  63. }")
  64. (define test-bar-json
  65. "{
  66. \"name\": \"bar\",
  67. \"version\": \"1.0.0\",
  68. \"sha\": \"f3676eafca9987cb5fe263df1edf2538bf6dafc712b30e17be3543a9680547a8\",
  69. \"info\": \"Another cool gem\",
  70. \"homepage_uri\": \"https://example.com\",
  71. \"dependencies\": {
  72. \"runtime\": [
  73. { \"name\": \"bundler\" }
  74. ]
  75. },
  76. \"licenses\": null
  77. }")
  78. (define test-bundler-json
  79. "{
  80. \"name\": \"bundler\",
  81. \"version\": \"1.14.2\",
  82. \"sha\": \"3bb53e03db0a8008161eb4c816ccd317120d3c415ba6fee6f90bbc7f7eec8690\",
  83. \"info\": \"Ruby gem bundler\",
  84. \"homepage_uri\": \"https://bundler.io/\",
  85. \"dependencies\": {
  86. \"runtime\": []
  87. },
  88. \"licenses\": [\"MIT\"]
  89. }")
  90. (test-begin "gem")
  91. (test-assert "gem->guix-package"
  92. ;; Replace network resources with sample data.
  93. (mock ((guix http-client) http-fetch
  94. (lambda (url . rest)
  95. (match url
  96. ("https://rubygems.org/api/v1/gems/foo.json"
  97. (values (open-input-string test-foo-json)
  98. (string-length test-foo-json)))
  99. (_ (error "Unexpected URL: " url)))))
  100. (match (gem->guix-package "foo")
  101. (`(package
  102. (name "ruby-foo")
  103. (version "1.0.0")
  104. (source (origin
  105. (method url-fetch)
  106. (uri (rubygems-uri "foo" version))
  107. (sha256
  108. (base32
  109. "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk"))))
  110. (build-system ruby-build-system)
  111. (propagated-inputs (list bundler ruby-bar))
  112. (synopsis "A cool gem")
  113. (description "This package provides a cool gem")
  114. (home-page "https://example.com")
  115. (license (list license:expat license:asl2.0)))
  116. #t)
  117. (x
  118. (pk 'fail x #f)))))
  119. (test-assert "gem->guix-package with a specific version"
  120. ;; Replace network resources with sample data.
  121. (mock ((guix http-client) http-fetch
  122. (lambda (url . rest)
  123. (match url
  124. ("https://rubygems.org/api/v2/rubygems/foo/versions/2.0.0.json"
  125. (values (open-input-string test-foo-v2-json)
  126. (string-length test-foo-v2-json)))
  127. (_ (error "Unexpected URL: " url)))))
  128. (match (gem->guix-package "foo" #:version "2.0.0")
  129. (`(package
  130. (name "ruby-foo")
  131. (version "2.0.0")
  132. (source (origin
  133. (method url-fetch)
  134. (uri (rubygems-uri "foo" version))
  135. (sha256
  136. (base32
  137. "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk"))))
  138. (build-system ruby-build-system)
  139. (propagated-inputs (list bundler ruby-bar))
  140. (synopsis "A cool gem")
  141. (description "This package provides a cool gem")
  142. (home-page "https://example.com")
  143. (license (list license:expat license:asl2.0)))
  144. #t)
  145. (x
  146. (pk 'fail x #f)))))
  147. (test-assert "gem-recursive-import"
  148. ;; Replace network resources with sample data.
  149. (mock ((guix http-client) http-fetch
  150. (lambda (url . rest)
  151. (match url
  152. ("https://rubygems.org/api/v1/gems/foo.json"
  153. (values (open-input-string test-foo-json)
  154. (string-length test-foo-json)))
  155. ("https://rubygems.org/api/v1/gems/bar.json"
  156. (values (open-input-string test-bar-json)
  157. (string-length test-bar-json)))
  158. ("https://rubygems.org/api/v1/gems/bundler.json"
  159. (values (open-input-string test-bundler-json)
  160. (string-length test-bundler-json)))
  161. (_ (error "Unexpected URL: " url)))))
  162. (match (gem-recursive-import "foo")
  163. (`((package
  164. (name "ruby-bar")
  165. (version "1.0.0")
  166. (source
  167. (origin
  168. (method url-fetch)
  169. (uri (rubygems-uri "bar" version))
  170. (sha256
  171. (base32
  172. "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk"))))
  173. (build-system ruby-build-system)
  174. (propagated-inputs (list bundler))
  175. (synopsis "Another cool gem")
  176. (description "Another cool gem")
  177. (home-page "https://example.com")
  178. (license #f)) ;no licensing info
  179. (package
  180. (name "ruby-foo")
  181. (version "1.0.0")
  182. (source
  183. (origin
  184. (method url-fetch)
  185. (uri (rubygems-uri "foo" version))
  186. (sha256
  187. (base32
  188. "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk"))))
  189. (build-system ruby-build-system)
  190. (propagated-inputs (list bundler ruby-bar))
  191. (synopsis "A cool gem")
  192. (description "This package provides a cool gem")
  193. (home-page "https://example.com")
  194. (license (list license:expat license:asl2.0))))
  195. #t)
  196. (x
  197. (pk 'fail x #f)))))
  198. (test-assert "gem-recursive-import with a specific version"
  199. ;; Replace network resources with sample data.
  200. (mock ((guix http-client) http-fetch
  201. (lambda (url . rest)
  202. (match url
  203. ("https://rubygems.org/api/v2/rubygems/foo/versions/2.0.0.json"
  204. (values (open-input-string test-foo-v2-json)
  205. (string-length test-foo-v2-json)))
  206. ("https://rubygems.org/api/v1/gems/bar.json"
  207. (values (open-input-string test-bar-json)
  208. (string-length test-bar-json)))
  209. ("https://rubygems.org/api/v1/gems/bundler.json"
  210. (values (open-input-string test-bundler-json)
  211. (string-length test-bundler-json)))
  212. (_ (error "Unexpected URL: " url)))))
  213. (match (gem-recursive-import "foo" "2.0.0")
  214. (`((package
  215. (name "ruby-bar")
  216. (version "1.0.0")
  217. (source
  218. (origin
  219. (method url-fetch)
  220. (uri (rubygems-uri "bar" version))
  221. (sha256
  222. (base32
  223. "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk"))))
  224. (build-system ruby-build-system)
  225. (propagated-inputs (list bundler))
  226. (synopsis "Another cool gem")
  227. (description "Another cool gem")
  228. (home-page "https://example.com")
  229. (license #f)) ;no licensing info
  230. (package
  231. (name "ruby-foo")
  232. (version "2.0.0")
  233. (source
  234. (origin
  235. (method url-fetch)
  236. (uri (rubygems-uri "foo" version))
  237. (sha256
  238. (base32
  239. "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk"))))
  240. (build-system ruby-build-system)
  241. (propagated-inputs (list bundler ruby-bar))
  242. (synopsis "A cool gem")
  243. (description "This package provides a cool gem")
  244. (home-page "https://example.com")
  245. (license (list license:expat license:asl2.0))))
  246. #t)
  247. (x
  248. (pk 'fail x #f)))))
  249. (test-equal "package-latest-release"
  250. (list '("https://rubygems.org/downloads/foo-1.0.0.gem")
  251. (list (upstream-input
  252. (name "bundler")
  253. (downstream-name name)
  254. (type 'propagated))
  255. (upstream-input
  256. (name "bar")
  257. (downstream-name "ruby-bar")
  258. (type 'propagated))))
  259. (mock ((guix http-client) http-fetch
  260. (lambda (url . rest)
  261. (match url
  262. ("https://rubygems.org/api/v1/gems/foo.json"
  263. (values (open-input-string test-foo-json)
  264. (string-length test-foo-json)))
  265. (_ (error "Unexpected URL: " url)))))
  266. (let ((source (package-latest-release
  267. (dummy-package "ruby-foo"
  268. (version "0.1.2")
  269. (source (dummy-origin
  270. (method url-fetch)
  271. (uri (rubygems-uri "foo"
  272. version))))))))
  273. (list (upstream-source-urls source)
  274. (upstream-source-inputs source)))))
  275. (test-end "gem")