projects/guix·blob javascript-team · refs

470 lines · 17.3 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2015 David Thompson <[email protected]>
3;;; Copyright © 2016 Ricardo Wurmus <[email protected]>
4;;; Copyright © 2018 Oleg Pykhalov <[email protected]>
5;;; Copyright © 2021 Sarah Morgensen <[email protected]>
6;;; Copyright © 2022 Taiju HIGASHI <[email protected]>
7;;; Copyright © 2023 Ludovic Courtès <[email protected]>
8;;;
9;;; This file is part of GNU Guix.
10;;;
11;;; GNU Guix is free software; you can redistribute it and/or modify it
12;;; under the terms of the GNU General Public License as published by
13;;; the Free Software Foundation; either version 3 of the License, or (at
14;;; your option) any later version.
15;;;
16;;; GNU Guix is distributed in the hope that it will be useful, but
17;;; WITHOUT ANY WARRANTY; without even the implied warranty of
18;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;;; GNU General Public License for more details.
20;;;
21;;; You should have received a copy of the GNU General Public License
22;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
23
24(define-module (test-gem)
25 #:use-module (guix import gem)
26 #:use-module (guix upstream)
27 #:use-module ((guix download) #:select (url-fetch))
28 #:use-module ((guix build-system ruby) #:select (rubygems-uri))
29 #:use-module (guix base32)
30 #:use-module (gcrypt hash)
31 #:use-module (guix tests)
32 #:use-module ((guix build utils) #:select (delete-file-recursively))
33 #:use-module (srfi srfi-64)
34 #:use-module (ice-9 match))
35
36(define test-foo-json
37 "{
38 \"name\": \"foo\",
39 \"version\": \"1.0.0\",
40 \"sha\": \"f3676eafca9987cb5fe263df1edf2538bf6dafc712b30e17be3543a9680547a8\",
41 \"info\": \"A cool gem\",
42 \"homepage_uri\": \"https://example.com\",
43 \"dependencies\": {
44 \"runtime\": [
45 { \"name\": \"bundler\" },
46 { \"name\": \"bar\" }
47 ]
48 },
49 \"licenses\": [\"MIT\", \"Apache 2.0\"]
50}")
51
52(define test-foo-versions-json
53 "[{\"authors\": \" Maxim \",
54 \"built_at\": \"2012-10-24T00:00:00.000Z\",
55 \"created_at\": \"2012-11-03T07:41:49.007Z\",
56 \"description\": \"test gem\",
57 \"downloads_count\" :9195,
58 \"metadata\": {\"homepage_uri\":\"\"},
59 \"number\": \"1.0.0\",
60 \"summary\": \"foo!!!\",
61 \"platform\": \"ruby\",
62 \"rubygems_version\": \"\u003e= 0\",
63 \"ruby_version\": null,
64 \"priceless\": false,
65 \"licenses\": null,
66 \"requirements\": null,
67 \"sha\": \"523009a5b977f79c8eaa79b521e416f26482bc4fbbcc04bd08580696e303a715\",
68 \"spec_sha\": \"c7cf42bac0d01eb12b68294d1cdb4e20e7cb222ca958ad70ed1e9a686b551819\"
69}]")
70
71(define test-foo-v2-json
72 "{
73 \"name\": \"foo\",
74 \"version\": \"2.0.0\",
75 \"sha\": \"f3676eafca9987cb5fe263df1edf2538bf6dafc712b30e17be3543a9680547a8\",
76 \"info\": \"A cool gem\",
77 \"homepage_uri\": \"https://example.com\",
78 \"dependencies\": {
79 \"runtime\": [
80 { \"name\": \"bundler\" },
81 { \"name\": \"bar\" }
82 ]
83 },
84 \"licenses\": [\"MIT\", \"Apache 2.0\"]
85}")
86
87(define test-bar-json
88 "{
89 \"name\": \"bar\",
90 \"version\": \"1.0.0\",
91 \"sha\": \"f3676eafca9987cb5fe263df1edf2538bf6dafc712b30e17be3543a9680547a8\",
92 \"info\": \"Another cool gem\",
93 \"homepage_uri\": \"https://example.com\",
94 \"dependencies\": {
95 \"runtime\": [
96 { \"name\": \"bundler\" }
97 ]
98 },
99 \"licenses\": null
100}")
101
102(define test-bundler-json
103 "{
104 \"name\": \"bundler\",
105 \"version\": \"1.14.2\",
106 \"sha\": \"3bb53e03db0a8008161eb4c816ccd317120d3c415ba6fee6f90bbc7f7eec8690\",
107 \"info\": \"Ruby gem bundler\",
108 \"homepage_uri\": \"https://bundler.io/\",
109 \"dependencies\": {
110 \"runtime\": []
111 },
112 \"licenses\": [\"MIT\"]
113}")
114
115(define test-no-homepage-json
116 "{
117 \"name\": \"no-homepage\",
118 \"version\": \"1.0.0\",
119 \"sha\": \"f3676eafca9987cb5fe263df1edf2538bf6dafc712b30e17be3543a9680547a8\",
120 \"info\": \"A gem with no homepage\",
121 \"homepage_uri\": null,
122 \"dependencies\": {
123 \"runtime\": []
124 },
125 \"licenses\": [\"MIT\"]
126}")
127
128(define test-spdx-json
129 "{
130 \"name\": \"spdx-gem\",
131 \"version\": \"1.0.0\",
132 \"sha\": \"f3676eafca9987cb5fe263df1edf2538bf6dafc712b30e17be3543a9680547a8\",
133 \"info\": \"A gem with SPDX licenses\",
134 \"homepage_uri\": \"https://example.com\",
135 \"dependencies\": {
136 \"runtime\": []
137 },
138 \"licenses\": [\"Ruby\", \"BSD-2-Clause\"]
139}")
140
141(define test-gibberish-licenses-json
142 "{
143 \"name\": \"gibberish-license-gem\",
144 \"version\": \"1.0.0\",
145 \"sha\": \"f3676eafca9987cb5fe263df1edf2538bf6dafc712b30e17be3543a9680547a8\",
146 \"info\": \"A gem with gibberish licenses\",
147 \"homepage_uri\": \"https://example.com\",
148 \"dependencies\": {
149 \"runtime\": []
150 },
151 \"licenses\": [\"foo\", \"bar\"]
152}")
153
154(define test-mixed-licenses-json
155 "{
156 \"name\": \"mixed-license-gem\",
157 \"version\": \"1.0.0\",
158 \"sha\": \"f3676eafca9987cb5fe263df1edf2538bf6dafc712b30e17be3543a9680547a8\",
159 \"info\": \"A gem with one valid and one gibberish license\",
160 \"homepage_uri\": \"https://example.com\",
161 \"dependencies\": {
162 \"runtime\": []
163 },
164 \"licenses\": [\"MIT\", \"nonsense\"]
165}")
166
167(test-begin "gem")
168
169(test-assert "gem->guix-package"
170 ;; Replace network resources with sample data.
171 (mock ((guix http-client) http-fetch
172 (lambda (url . rest)
173 (match url
174 ("https://rubygems.org/api/v1/gems/foo.json"
175 (values (open-input-string test-foo-json)
176 (string-length test-foo-json)))
177 (_ (error "Unexpected URL: " url)))))
178 (match (gem->guix-package "foo")
179 (`(package
180 (name "ruby-foo")
181 (version "1.0.0")
182 (source (origin
183 (method url-fetch)
184 (uri (rubygems-uri "foo" version))
185 (sha256
186 (base32
187 "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk"))))
188 (build-system ruby-build-system)
189 (propagated-inputs (list bundler ruby-bar))
190 (synopsis "A cool gem")
191 (description "This package provides a cool gem.")
192 (home-page "https://example.com")
193 (license (list license:expat license:asl2.0)))
194 #t)
195 (x
196 (pk 'fail x #f)))))
197
198(test-assert "gem->guix-package with a specific version"
199 ;; Replace network resources with sample data.
200 (mock ((guix http-client) http-fetch
201 (lambda (url . rest)
202 (match url
203 ("https://rubygems.org/api/v2/rubygems/foo/versions/2.0.0.json"
204 (values (open-input-string test-foo-v2-json)
205 (string-length test-foo-v2-json)))
206 (_ (error "Unexpected URL: " url)))))
207 (match (gem->guix-package "foo" #:version "2.0.0")
208 (`(package
209 (name "ruby-foo")
210 (version "2.0.0")
211 (source (origin
212 (method url-fetch)
213 (uri (rubygems-uri "foo" version))
214 (sha256
215 (base32
216 "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk"))))
217 (build-system ruby-build-system)
218 (propagated-inputs (list bundler ruby-bar))
219 (synopsis "A cool gem")
220 (description "This package provides a cool gem.")
221 (home-page "https://example.com")
222 (license (list license:expat license:asl2.0)))
223 #t)
224 (x
225 (pk 'fail x #f)))))
226
227(test-assert "gem-recursive-import"
228 ;; Replace network resources with sample data.
229 (mock ((guix http-client) http-fetch
230 (lambda (url . rest)
231 (match url
232 ("https://rubygems.org/api/v1/gems/foo.json"
233 (values (open-input-string test-foo-json)
234 (string-length test-foo-json)))
235 ("https://rubygems.org/api/v1/gems/bar.json"
236 (values (open-input-string test-bar-json)
237 (string-length test-bar-json)))
238 ("https://rubygems.org/api/v1/gems/bundler.json"
239 (values (open-input-string test-bundler-json)
240 (string-length test-bundler-json)))
241 (_ (error "Unexpected URL: " url)))))
242 (match (gem-recursive-import "foo")
243 (`((package
244 (name "ruby-bar")
245 (version "1.0.0")
246 (source
247 (origin
248 (method url-fetch)
249 (uri (rubygems-uri "bar" version))
250 (sha256
251 (base32
252 "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk"))))
253 (build-system ruby-build-system)
254 (propagated-inputs (list bundler))
255 (synopsis "Another cool gem")
256 (description "Another cool gem.")
257 (home-page "https://example.com")
258 (license #f)) ;no licensing info
259 (package
260 (name "ruby-foo")
261 (version "1.0.0")
262 (source
263 (origin
264 (method url-fetch)
265 (uri (rubygems-uri "foo" version))
266 (sha256
267 (base32
268 "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk"))))
269 (build-system ruby-build-system)
270 (propagated-inputs (list bundler ruby-bar))
271 (synopsis "A cool gem")
272 (description "This package provides a cool gem.")
273 (home-page "https://example.com")
274 (license (list license:expat license:asl2.0))))
275 #t)
276 (x
277 (pk 'fail x #f)))))
278
279(test-assert "gem-recursive-import with a specific version"
280 ;; Replace network resources with sample data.
281 (mock ((guix http-client) http-fetch
282 (lambda (url . rest)
283 (match url
284 ("https://rubygems.org/api/v2/rubygems/foo/versions/2.0.0.json"
285 (values (open-input-string test-foo-v2-json)
286 (string-length test-foo-v2-json)))
287 ("https://rubygems.org/api/v1/gems/bar.json"
288 (values (open-input-string test-bar-json)
289 (string-length test-bar-json)))
290 ("https://rubygems.org/api/v1/gems/bundler.json"
291 (values (open-input-string test-bundler-json)
292 (string-length test-bundler-json)))
293 (_ (error "Unexpected URL: " url)))))
294 (match (gem-recursive-import "foo" "2.0.0")
295 (`((package
296 (name "ruby-bar")
297 (version "1.0.0")
298 (source
299 (origin
300 (method url-fetch)
301 (uri (rubygems-uri "bar" version))
302 (sha256
303 (base32
304 "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk"))))
305 (build-system ruby-build-system)
306 (propagated-inputs (list bundler))
307 (synopsis "Another cool gem")
308 (description "Another cool gem.")
309 (home-page "https://example.com")
310 (license #f)) ;no licensing info
311 (package
312 (name "ruby-foo")
313 (version "2.0.0")
314 (source
315 (origin
316 (method url-fetch)
317 (uri (rubygems-uri "foo" version))
318 (sha256
319 (base32
320 "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk"))))
321 (build-system ruby-build-system)
322 (propagated-inputs (list bundler ruby-bar))
323 (synopsis "A cool gem")
324 (description "This package provides a cool gem.")
325 (home-page "https://example.com")
326 (license (list license:expat license:asl2.0))))
327 #t)
328 (x
329 (pk 'fail x #f)))))
330
331(test-equal "package-latest-release"
332 (list '("https://rubygems.org/downloads/foo-1.0.0.gem")
333 (list (upstream-input
334 (name "bundler")
335 (downstream-name name)
336 (type 'propagated))
337 (upstream-input
338 (name "bar")
339 (downstream-name "ruby-bar")
340 (type 'propagated))))
341 (mock ((guix http-client) http-fetch
342 (lambda (url . rest)
343 (match url
344 ("https://rubygems.org/api/v1/gems/foo.json"
345 (values (open-input-string test-foo-json)
346 (string-length test-foo-json)))
347 ("https://rubygems.org/api/v1/versions/foo.json"
348 (values (open-input-string test-foo-versions-json)
349 (string-length test-foo-versions-json)))
350 (_ (error "Unexpected URL: " url)))))
351 (let ((source (package-latest-release
352 (dummy-package "ruby-foo"
353 (version "0.1.2")
354 (source (dummy-origin
355 (method url-fetch)
356 (uri (rubygems-uri "foo"
357 version))))))))
358 (list (upstream-source-urls source)
359 (upstream-source-inputs source)))))
360
361(test-assert "gem->guix-package, bald homepage_uri"
362 (mock ((guix http-client) http-fetch
363 (lambda (url . rest)
364 (match url
365 ("https://rubygems.org/api/v1/gems/no-homepage.json"
366 (values (open-input-string test-no-homepage-json)
367 (string-length test-no-homepage-json)))
368 (_ (error "Unexpected URL: " url)))))
369 (match (gem->guix-package "no-homepage")
370 (`(package
371 (name "ruby-no-homepage")
372 (version "1.0.0")
373 (source (origin
374 (method url-fetch)
375 (uri (rubygems-uri "no-homepage" version))
376 (sha256
377 (base32
378 "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk"))))
379 (build-system ruby-build-system)
380 (synopsis "A gem with no homepage")
381 (description "This package provides a gem with no homepage.")
382 (home-page #f)
383 (license license:expat))
384 #t)
385 (x
386 (pk 'fail x #f)))))
387
388(test-assert "gem->guix-package with SPDX license identifiers"
389 (mock ((guix http-client) http-fetch
390 (lambda (url . rest)
391 (match url
392 ("https://rubygems.org/api/v1/gems/spdx-gem.json"
393 (values (open-input-string test-spdx-json)
394 (string-length test-spdx-json)))
395 (_ (error "Unexpected URL: " url)))))
396 (match (gem->guix-package "spdx-gem")
397 (`(package
398 (name "ruby-spdx-gem")
399 (version "1.0.0")
400 (source (origin
401 (method url-fetch)
402 (uri (rubygems-uri "spdx-gem" version))
403 (sha256
404 (base32
405 "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk"))))
406 (build-system ruby-build-system)
407 (synopsis "A gem with SPDX licenses")
408 (description "This package provides a gem with SPDX licenses.")
409 (home-page "https://example.com")
410 (license (list license:ruby license:bsd-2)))
411 #t)
412 (x
413 (pk 'fail x #f)))))
414
415(test-assert "gem->guix-package with gibberish license identifiers"
416 (mock ((guix http-client) http-fetch
417 (lambda (url . rest)
418 (match url
419 ("https://rubygems.org/api/v1/gems/gibberish-license-gem.json"
420 (values (open-input-string test-gibberish-licenses-json)
421 (string-length test-gibberish-licenses-json)))
422 (_ (error "Unexpected URL: " url)))))
423 (match (gem->guix-package "gibberish-license-gem")
424 (`(package
425 (name "ruby-gibberish-license-gem")
426 (version "1.0.0")
427 (source (origin
428 (method url-fetch)
429 (uri (rubygems-uri "gibberish-license-gem" version))
430 (sha256
431 (base32
432 "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk"))))
433 (build-system ruby-build-system)
434 (synopsis "A gem with gibberish licenses")
435 (description "This package provides a gem with gibberish licenses.")
436 (home-page "https://example.com")
437 (license (list unknown-license! unknown-license!)))
438 #t)
439 (x
440 (pk 'fail x #f)))))
441
442(test-assert "gem->guix-package with mixed valid and gibberish licenses"
443 (mock ((guix http-client) http-fetch
444 (lambda (url . rest)
445 (match url
446 ("https://rubygems.org/api/v1/gems/mixed-license-gem.json"
447 (values (open-input-string test-mixed-licenses-json)
448 (string-length test-mixed-licenses-json)))
449 (_ (error "Unexpected URL: " url)))))
450 (match (gem->guix-package "mixed-license-gem")
451 (`(package
452 (name "ruby-mixed-license-gem")
453 (version "1.0.0")
454 (source (origin
455 (method url-fetch)
456 (uri (rubygems-uri "mixed-license-gem" version))
457 (sha256
458 (base32
459 "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk"))))
460 (build-system ruby-build-system)
461 (synopsis "A gem with one valid and one gibberish license")
462 (description "This package provides a gem with one valid \
463and one gibberish license.")
464 (home-page "https://example.com")
465 (license (list license:expat unknown-license!)))
466 #t)
467 (x
468 (pk 'fail x #f)))))
469
470(test-end "gem")