| 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 | |
| 20 | (define-module (test-gem) |
| 21 | #:use-module (guix import gem) |
| 22 | #:use-module (guix base32) |
| 23 | #:use-module (guix 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 | |
| 29 | (define test-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 | |
| 45 | (test-begin "gem") |
| 46 | |
| 47 | (test-assert "gem->guix-package" |
| 48 | ;; Replace network resources with sample data. |
| 49 | (mock ((guix http-client) http-fetch |
| 50 | (lambda (url . rest) |
| 51 | (match url |
| 52 | ("https://rubygems.org/api/v1/gems/foo.json" |
| 53 | (values (open-input-string test-json) |
| 54 | (string-length test-json))) |
| 55 | (_ (error "Unexpected URL: " url))))) |
| 56 | (match (gem->guix-package "foo") |
| 57 | (('package |
| 58 | ('name "ruby-foo") |
| 59 | ('version "1.0.0") |
| 60 | ('source ('origin |
| 61 | ('method 'url-fetch) |
| 62 | ('uri ('rubygems-uri "foo" 'version)) |
| 63 | ('sha256 |
| 64 | ('base32 |
| 65 | "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk")))) |
| 66 | ('build-system 'ruby-build-system) |
| 67 | ('propagated-inputs |
| 68 | ('quasiquote |
| 69 | (("bundler" ('unquote 'bundler)) |
| 70 | ("ruby-bar" ('unquote 'ruby-bar))))) |
| 71 | ('synopsis "A cool gem") |
| 72 | ('description "This package provides a cool gem") |
| 73 | ('home-page "https://example.com") |
| 74 | ('license ('list 'license:expat 'license:asl2.0))) |
| 75 | #t) |
| 76 | (x |
| 77 | (pk 'fail x #f))))) |
| 78 | |
| 79 | (test-end "gem") |