gnu: plantuml: Update to 1.2020.16.
[jackhill/guix/guix.git] / tests / gem.scm
CommitLineData
a96524cc
DT
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2015 David Thompson <davet@gnu.org>
506abddb 3;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
88388766 4;;; Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com>
a96524cc
DT
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)
ca719424 24 #:use-module (gcrypt hash)
a96524cc
DT
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
88388766 30(define test-foo-json
a96524cc
DT
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
88388766
OP
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\": [
5dfe02c6 55 { \"name\": \"bundler\" }
88388766
OP
56 ]
57 },
c24fe4a5 58 \"licenses\": null
88388766
OP
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
a96524cc
DT
74(test-begin "gem")
75
76(test-assert "gem->guix-package"
77 ;; Replace network resources with sample data.
506abddb 78 (mock ((guix http-client) http-fetch
ce8963c5 79 (lambda (url . rest)
a96524cc
DT
80 (match url
81 ("https://rubygems.org/api/v1/gems/foo.json"
88388766
OP
82 (values (open-input-string test-foo-json)
83 (string-length test-foo-json)))
a96524cc
DT
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")
e88d5fa9 101 ('description "This package provides a cool gem")
a96524cc 102 ('home-page "https://example.com")
a34b236c 103 ('license ('list 'license:expat 'license:asl2.0)))
a96524cc
DT
104 #t)
105 (x
106 (pk 'fail x #f)))))
107
88388766
OP
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)))))
70a8e132 123 (match (gem-recursive-import "foo")
88388766 124 ((('package
ddd59159 125 ('name "ruby-bar")
88388766
OP
126 ('version "1.0.0")
127 ('source
128 ('origin
129 ('method 'url-fetch)
ddd59159 130 ('uri ('rubygems-uri "bar" 'version))
88388766
OP
131 ('sha256
132 ('base32
133 "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk"))))
134 ('build-system 'ruby-build-system)
135 ('propagated-inputs
136 ('quasiquote
ddd59159
LC
137 (('"bundler" ('unquote 'bundler)))))
138 ('synopsis "Another cool gem")
139 ('description "Another cool gem")
88388766 140 ('home-page "https://example.com")
c24fe4a5 141 ('license #f)) ;no licensing info
88388766
OP
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
ddd59159 158 ('name "ruby-foo")
88388766
OP
159 ('version "1.0.0")
160 ('source
161 ('origin
162 ('method 'url-fetch)
ddd59159 163 ('uri ('rubygems-uri "foo" 'version))
88388766
OP
164 ('sha256
165 ('base32
166 "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk"))))
167 ('build-system 'ruby-build-system)
168 ('propagated-inputs
169 ('quasiquote
ddd59159
LC
170 (("bundler" ('unquote 'bundler))
171 ("ruby-bar" ('unquote 'ruby-bar)))))
172 ('synopsis "A cool gem")
173 ('description "This package provides a cool gem")
88388766
OP
174 ('home-page "https://example.com")
175 ('license ('list 'license:expat 'license:asl2.0))))
176 #t)
177 (x
178 (pk 'fail x #f)))))
179
a96524cc 180(test-end "gem")