gem.scm 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. ;;;
  7. ;;; This file is part of GNU Guix.
  8. ;;;
  9. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  10. ;;; under the terms of the GNU General Public License as published by
  11. ;;; the Free Software Foundation; either version 3 of the License, or (at
  12. ;;; your option) any later version.
  13. ;;;
  14. ;;; GNU Guix is distributed in the hope that it will be useful, but
  15. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;;; GNU General Public License for more details.
  18. ;;;
  19. ;;; You should have received a copy of the GNU General Public License
  20. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  21. (define-module (test-gem)
  22. #:use-module (guix import gem)
  23. #:use-module (guix base32)
  24. #:use-module (gcrypt hash)
  25. #:use-module (guix tests)
  26. #:use-module ((guix build utils) #:select (delete-file-recursively))
  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\": null
  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 ('list 'bundler 'ruby-bar))
  92. ('synopsis "A cool gem")
  93. ('description "This package provides a cool gem")
  94. ('home-page "https://example.com")
  95. ('license ('list 'license:expat 'license:asl2.0)))
  96. #t)
  97. (x
  98. (pk 'fail x #f)))))
  99. (test-assert "gem-recursive-import"
  100. ;; Replace network resources with sample data.
  101. (mock ((guix http-client) http-fetch
  102. (lambda (url . rest)
  103. (match url
  104. ("https://rubygems.org/api/v1/gems/foo.json"
  105. (values (open-input-string test-foo-json)
  106. (string-length test-foo-json)))
  107. ("https://rubygems.org/api/v1/gems/bar.json"
  108. (values (open-input-string test-bar-json)
  109. (string-length test-bar-json)))
  110. ("https://rubygems.org/api/v1/gems/bundler.json"
  111. (values (open-input-string test-bundler-json)
  112. (string-length test-bundler-json)))
  113. (_ (error "Unexpected URL: " url)))))
  114. (match (gem-recursive-import "foo")
  115. ((('package
  116. ('name "ruby-bar")
  117. ('version "1.0.0")
  118. ('source
  119. ('origin
  120. ('method 'url-fetch)
  121. ('uri ('rubygems-uri "bar" 'version))
  122. ('sha256
  123. ('base32
  124. "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk"))))
  125. ('build-system 'ruby-build-system)
  126. ('propagated-inputs ('list 'bundler))
  127. ('synopsis "Another cool gem")
  128. ('description "Another cool gem")
  129. ('home-page "https://example.com")
  130. ('license #f)) ;no licensing info
  131. ('package
  132. ('name "ruby-bundler")
  133. ('version "1.14.2")
  134. ('source
  135. ('origin
  136. ('method 'url-fetch)
  137. ('uri ('rubygems-uri "bundler" 'version))
  138. ('sha256
  139. ('base32
  140. "1446xiz7zg0bz7kgx9jv84y0s4hpsg61dj5l3qb0i00avc1kxd9v"))))
  141. ('build-system 'ruby-build-system)
  142. ('synopsis "Ruby gem bundler")
  143. ('description "Ruby gem bundler")
  144. ('home-page "https://bundler.io/")
  145. ('license 'license:expat))
  146. ('package
  147. ('name "ruby-foo")
  148. ('version "1.0.0")
  149. ('source
  150. ('origin
  151. ('method 'url-fetch)
  152. ('uri ('rubygems-uri "foo" 'version))
  153. ('sha256
  154. ('base32
  155. "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk"))))
  156. ('build-system 'ruby-build-system)
  157. ('propagated-inputs ('list 'bundler 'ruby-bar))
  158. ('synopsis "A cool gem")
  159. ('description "This package provides a cool gem")
  160. ('home-page "https://example.com")
  161. ('license ('list 'license:expat 'license:asl2.0))))
  162. #t)
  163. (x
  164. (pk 'fail x #f)))))
  165. (test-end "gem")