gem.scm 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. ;;;
  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-gem)
  20. #:use-module (guix import gem)
  21. #:use-module (guix base32)
  22. #:use-module (guix hash)
  23. #:use-module (guix tests)
  24. #:use-module ((guix build utils) #:select (delete-file-recursively))
  25. #:use-module (srfi srfi-64)
  26. #:use-module (ice-9 match))
  27. (define test-json
  28. "{
  29. \"name\": \"foo\",
  30. \"version\": \"1.0.0\",
  31. \"sha\": \"f3676eafca9987cb5fe263df1edf2538bf6dafc712b30e17be3543a9680547a8\",
  32. \"info\": \"A cool gem\",
  33. \"homepage_uri\": \"https://example.com\",
  34. \"dependencies\": {
  35. \"runtime\": [
  36. { \"name\": \"bundler\" },
  37. { \"name\": \"bar\" }
  38. ]
  39. },
  40. \"licenses\": [\"MIT\", \"Apache 2.0\"]
  41. }")
  42. (test-begin "gem")
  43. (test-assert "gem->guix-package"
  44. ;; Replace network resources with sample data.
  45. (mock ((guix http-client) http-fetch
  46. (lambda (url . rest)
  47. (match url
  48. ("https://rubygems.org/api/v1/gems/foo.json"
  49. (values (open-input-string test-json)
  50. (string-length test-json)))
  51. (_ (error "Unexpected URL: " url)))))
  52. (match (gem->guix-package "foo")
  53. (('package
  54. ('name "ruby-foo")
  55. ('version "1.0.0")
  56. ('source ('origin
  57. ('method 'url-fetch)
  58. ('uri ('rubygems-uri "foo" 'version))
  59. ('sha256
  60. ('base32
  61. "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk"))))
  62. ('build-system 'ruby-build-system)
  63. ('propagated-inputs
  64. ('quasiquote
  65. (("bundler" ('unquote 'bundler))
  66. ("ruby-bar" ('unquote 'ruby-bar)))))
  67. ('synopsis "A cool gem")
  68. ('description "This package provides a cool gem")
  69. ('home-page "https://example.com")
  70. ('license ('list 'license:expat 'license:asl2.0)))
  71. #t)
  72. (x
  73. (pk 'fail x #f)))))
  74. (test-end "gem")