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