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