epiphany w/ gtk4 and webkitgtk 2.38
[jackhill/guix/guix.git] / tests / crate.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014 David Thompson <davet@gnu.org>
3 ;;; Copyright © 2016 David Craven <david@craven.ch>
4 ;;; Copyright © 2019, 2020, 2022 Ludovic Courtès <ludo@gnu.org>
5 ;;; Copyright © 2020 Martin Becze <mjbecze@riseup.net>
6 ;;;
7 ;;; This file is part of GNU Guix.
8 ;;;
9 ;;; GNU Guix is free software; you can redistribute it and/or modify it
10 ;;; under the terms of the GNU General Public License as published by
11 ;;; the Free Software Foundation; either version 3 of the License, or (at
12 ;;; your option) any later version.
13 ;;;
14 ;;; GNU Guix is distributed in the hope that it will be useful, but
15 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;;; GNU General Public License for more details.
18 ;;;
19 ;;; You should have received a copy of the GNU General Public License
20 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21
22 (define-module (test-crate)
23 #:use-module (guix import crate)
24 #:use-module (guix base32)
25 #:use-module (guix build-system cargo)
26 #:use-module (gcrypt hash)
27 #:use-module (guix tests)
28 #:use-module (gnu packages)
29 #:use-module (ice-9 iconv)
30 #:use-module (ice-9 match)
31 #:use-module (srfi srfi-64))
32
33
34 ;; crate versions and dependencies used here
35 ;; foo-0.8.1
36 ;; foo-1.0.0
37 ;; foo-1.0.3
38 ;; leaf-alice 0.7.5
39 ;;
40 ;; root-1.0.0
41 ;; root-1.0.4
42 ;; intermediate-a 1.0.42
43 ;; intermeidate-b ^1.0.0
44 ;; leaf-alice ^0.7
45 ;; leaf-bob ^3
46 ;;
47 ;; intermediate-a-1.0.40
48 ;; intermediate-a-1.0.42
49 ;; intermediate-a-1.1.0-alpha.1
50 ;; intermediate-a 1.2.3
51 ;; leaf-alice 0.7.5
52 ;; leaf-bob ^3
53 ;;
54 ;; intermediate-b-1.2.3
55 ;; leaf-bob 3.0.1
56 ;;
57 ;; leaf-alice-0.7.3
58 ;; leaf-alice-0.7.5
59 ;;
60 ;; leaf-bob-3.0.1
61
62
63 (define test-foo-crate
64 "{
65 \"crate\": {
66 \"max_version\": \"1.0.3\",
67 \"name\": \"foo\",
68 \"description\": \"summary\",
69 \"homepage\": \"http://example.com\",
70 \"repository\": \"http://example.com\",
71 \"keywords\": [\"dummy\", \"test\"],
72 \"categories\": [\"test\"],
73 \"actual_versions\": [
74 { \"id\": 234210,
75 \"num\": \"0.8.1\",
76 \"license\": \"MIT OR Apache-2.0\",
77 \"links\": {
78 \"dependencies\": \"/api/v1/crates/foo/0.8.1/dependencies\"
79 }
80 },
81 { \"id\": 234212,
82 \"num\": \"1.0.0\",
83 \"license\": \"MIT OR Apache-2.0\",
84 \"links\": {
85 \"dependencies\": \"/api/v1/crates/foo/1.0.0/dependencies\"
86 }
87 },
88 { \"id\": 234214,
89 \"num\": \"1.0.3\",
90 \"license\": \"MIT OR Apache-2.0\",
91 \"links\": {
92 \"dependencies\": \"/api/v1/crates/foo/1.0.3/dependencies\"
93 }
94 }
95 ]
96 }
97 }")
98
99 (define test-foo-dependencies
100 "{
101 \"dependencies\": [
102 {
103 \"crate_id\": \"leaf-alice\",
104 \"kind\": \"normal\",
105 \"req\": \"0.7.5\"
106 }
107 ]
108 }")
109
110 (define test-root-crate
111 "{
112 \"crate\": {
113 \"max_version\": \"1.0.4\",
114 \"name\": \"root\",
115 \"description\": \"summary\",
116 \"homepage\": \"http://example.com\",
117 \"repository\": \"http://example.com\",
118 \"keywords\": [\"dummy\", \"test\"],
119 \"categories\": [\"test\"],
120 \"actual_versions\": [
121 { \"id\": 234240,
122 \"num\": \"1.0.0\",
123 \"license\": \"MIT OR Apache-2.0\",
124 \"links\": {
125 \"dependencies\": \"/api/v1/crates/root/1.0.0/dependencies\"
126 }
127 },
128 { \"id\": 234242,
129 \"num\": \"1.0.4\",
130 \"license\": \"MIT OR Apache-2.0\",
131 \"links\": {
132 \"dependencies\": \"/api/v1/crates/root/1.0.4/dependencies\"
133 }
134 }
135 ]
136 }
137 }")
138
139 (define test-root-dependencies
140 "{
141 \"dependencies\": [
142 {
143 \"crate_id\": \"intermediate-a\",
144 \"kind\": \"normal\",
145 \"req\": \"1.0.42\"
146 },
147 {
148 \"crate_id\": \"intermediate-b\",
149 \"kind\": \"normal\",
150 \"req\": \"^1.0.0\"
151 },
152 {
153 \"crate_id\": \"leaf-alice\",
154 \"kind\": \"normal\",
155 \"req\": \"^0.7\"
156 },
157 {
158 \"crate_id\": \"leaf-bob\",
159 \"kind\": \"normal\",
160 \"req\": \"^3\"
161 }
162 ]
163 }")
164
165 (define test-intermediate-a-crate
166 "{
167 \"crate\": {
168 \"max_version\": \"1.1.0-alpha.1\",
169 \"name\": \"intermediate-a\",
170 \"description\": \"summary\",
171 \"homepage\": \"http://example.com\",
172 \"repository\": \"http://example.com\",
173 \"keywords\": [\"dummy\", \"test\"],
174 \"categories\": [\"test\"],
175 \"actual_versions\": [
176 { \"id\": 234251,
177 \"num\": \"1.0.40\",
178 \"license\": \"MIT OR Apache-2.0\",
179 \"links\": {
180 \"dependencies\": \"/api/v1/crates/intermediate-a/1.0.40/dependencies\"
181 }
182 },
183 { \"id\": 234250,
184 \"num\": \"1.0.42\",
185 \"license\": \"MIT OR Apache-2.0\",
186 \"links\": {
187 \"dependencies\": \"/api/v1/crates/intermediate-a/1.0.42/dependencies\"
188 }
189 },
190 { \"id\": 234252,
191 \"num\": \"1.1.0-alpha.1\",
192 \"license\": \"MIT OR Apache-2.0\",
193 \"links\": {
194 \"dependencies\": \"/api/v1/crates/intermediate-a/1.1.0-alpha.1/dependencies\"
195 }
196 }
197 ]
198 }
199 }")
200
201 (define test-intermediate-a-dependencies
202 "{
203 \"dependencies\": [
204 {
205 \"crate_id\": \"intermediate-b\",
206 \"kind\": \"normal\",
207 \"req\": \"1.2.3\"
208 },
209 {
210 \"crate_id\": \"leaf-alice\",
211 \"kind\": \"normal\",
212 \"req\": \"0.7.5\"
213 },
214 {
215 \"crate_id\": \"leaf-bob\",
216 \"kind\": \"normal\",
217 \"req\": \"^3\"
218 }
219 ]
220 }")
221
222 (define test-intermediate-b-crate
223 "{
224 \"crate\": {
225 \"max_version\": \"1.2.3\",
226 \"name\": \"intermediate-b\",
227 \"description\": \"summary\",
228 \"homepage\": \"http://example.com\",
229 \"repository\": \"http://example.com\",
230 \"keywords\": [\"dummy\", \"test\"],
231 \"categories\": [\"test\"],
232 \"actual_versions\": [
233 { \"id\": 234260,
234 \"num\": \"1.2.3\",
235 \"license\": \"MIT OR Apache-2.0\",
236 \"links\": {
237 \"dependencies\": \"/api/v1/crates/intermediate-b/1.2.3/dependencies\"
238 }
239 }
240 ]
241 }
242 }")
243
244 (define test-intermediate-b-dependencies
245 "{
246 \"dependencies\": [
247 {
248 \"crate_id\": \"leaf-bob\",
249 \"kind\": \"normal\",
250 \"req\": \"3.0.1\"
251 }
252 ]
253 }")
254
255 (define test-leaf-alice-crate
256 "{
257 \"crate\": {
258 \"max_version\": \"0.7.5\",
259 \"name\": \"leaf-alice\",
260 \"description\": \"summary\",
261 \"homepage\": \"http://example.com\",
262 \"repository\": \"http://example.com\",
263 \"keywords\": [\"dummy\", \"test\"],
264 \"categories\": [\"test\"],
265 \"actual_versions\": [
266 { \"id\": 234270,
267 \"num\": \"0.7.3\",
268 \"license\": \"MIT OR Apache-2.0\",
269 \"links\": {
270 \"dependencies\": \"/api/v1/crates/leaf-alice/0.7.3/dependencies\"
271 }
272 },
273 { \"id\": 234272,
274 \"num\": \"0.7.5\",
275 \"license\": \"MIT OR Apache-2.0\",
276 \"links\": {
277 \"dependencies\": \"/api/v1/crates/leaf-alice/0.7.5/dependencies\"
278 }
279 }
280 ]
281 }
282 }")
283
284 (define test-leaf-alice-dependencies
285 "{
286 \"dependencies\": []
287 }")
288
289 (define test-leaf-bob-crate
290 "{
291 \"crate\": {
292 \"max_version\": \"3.0.1\",
293 \"name\": \"leaf-bob\",
294 \"description\": \"summary\",
295 \"homepage\": \"http://example.com\",
296 \"repository\": \"http://example.com\",
297 \"keywords\": [\"dummy\", \"test\"],
298 \"categories\": [\"test\"]
299 \"actual_versions\": [
300 { \"id\": 234280,
301 \"num\": \"3.0.1\",
302 \"license\": \"MIT OR Apache-2.0\",
303 \"links\": {
304 \"dependencies\": \"/api/v1/crates/leaf-bob/3.0.1/dependencies\"
305 }
306 }
307 ]
308 }
309 }")
310
311 (define test-leaf-bob-dependencies
312 "{
313 \"dependencies\": []
314 }")
315
316
317 (define test-source-hash
318 "")
319
320 (define have-guile-semver?
321 (false-if-exception (resolve-interface '(semver))))
322
323 \f
324 (test-begin "crate")
325
326 (test-equal "guix-package->crate-name"
327 "rustc-serialize"
328 (guix-package->crate-name
329 (dummy-package
330 "rust-rustc-serialize"
331 (source (dummy-origin
332 (uri (crate-uri "rustc-serialize" "1.0")))))))
333
334 (unless have-guile-semver? (test-skip 1))
335 (test-assert "crate->guix-package"
336 ;; Replace network resources with sample data.
337 (mock ((guix http-client) http-fetch
338 (lambda (url . rest)
339 (match url
340 ("https://crates.io/api/v1/crates/foo"
341 (open-input-string test-foo-crate))
342 ("https://crates.io/api/v1/crates/foo/1.0.3/download"
343 (set! test-source-hash
344 (bytevector->nix-base32-string
345 (sha256 (string->bytevector "empty file\n" "utf-8"))))
346 (open-input-string "empty file\n"))
347 ("https://crates.io/api/v1/crates/foo/1.0.3/dependencies"
348 (open-input-string test-foo-dependencies))
349 ("https://crates.io/api/v1/crates/leaf-alice"
350 (open-input-string test-leaf-alice-crate))
351 ("https://crates.io/api/v1/crates/leaf-alice/0.7.5/download"
352 (set! test-source-hash
353 (bytevector->nix-base32-string
354 (sha256 (string->bytevector "empty file\n" "utf-8"))))
355 (open-input-string "empty file\n"))
356 ("https://crates.io/api/v1/crates/leaf-alice/0.7.5/dependencies"
357 (open-input-string test-leaf-alice-dependencies))
358 (_ (error "Unexpected URL: " url)))))
359
360 (match (crate->guix-package "foo")
361 ((define-public 'rust-foo-1
362 (package (name "rust-foo")
363 (version "1.0.3")
364 (source
365 (origin
366 (method url-fetch)
367 (uri (crate-uri "foo" 'version))
368 (file-name (string-append name "-" version ".tar.gz"))
369 (sha256
370 (base32
371 (? string? hash)))))
372 (build-system 'cargo-build-system)
373 (arguments
374 ('quasiquote
375 (#:skip-build? #t
376 #:cargo-inputs
377 (("rust-leaf-alice" ('unquote 'rust-leaf-alice-0.7))))))
378 (home-page "http://example.com")
379 (synopsis "summary")
380 (description "summary")
381 (license (list license:expat license:asl2.0))))
382
383 (string=? test-source-hash hash))
384 (x
385 (pk 'fail x #f)))))
386
387 (unless have-guile-semver? (test-skip 1))
388 (test-assert "cargo-recursive-import"
389 ;; Replace network resources with sample data.
390 (mock ((guix http-client) http-fetch
391 (lambda (url . rest)
392 (match url
393 ("https://crates.io/api/v1/crates/root"
394 (open-input-string test-root-crate))
395 ("https://crates.io/api/v1/crates/root/1.0.4/download"
396 (set! test-source-hash
397 (bytevector->nix-base32-string
398 (sha256 (string->bytevector "empty file\n" "utf-8"))))
399 (open-input-string "empty file\n"))
400 ("https://crates.io/api/v1/crates/root/1.0.4/dependencies"
401 (open-input-string test-root-dependencies))
402 ("https://crates.io/api/v1/crates/intermediate-a"
403 (open-input-string test-intermediate-a-crate))
404 ("https://crates.io/api/v1/crates/intermediate-a/1.0.42/download"
405 (set! test-source-hash
406 (bytevector->nix-base32-string
407 (sha256 (string->bytevector "empty file\n" "utf-8"))))
408 (open-input-string "empty file\n"))
409 ("https://crates.io/api/v1/crates/intermediate-a/1.0.42/dependencies"
410 (open-input-string test-intermediate-a-dependencies))
411 ("https://crates.io/api/v1/crates/intermediate-b"
412 (open-input-string test-intermediate-b-crate))
413 ("https://crates.io/api/v1/crates/intermediate-b/1.2.3/download"
414 (set! test-source-hash
415 (bytevector->nix-base32-string
416 (sha256 (string->bytevector "empty file\n" "utf-8"))))
417 (open-input-string "empty file\n"))
418 ("https://crates.io/api/v1/crates/intermediate-b/1.2.3/dependencies"
419 (open-input-string test-intermediate-b-dependencies))
420 ("https://crates.io/api/v1/crates/leaf-alice"
421 (open-input-string test-leaf-alice-crate))
422 ("https://crates.io/api/v1/crates/leaf-alice/0.7.5/download"
423 (set! test-source-hash
424 (bytevector->nix-base32-string
425 (sha256 (string->bytevector "empty file\n" "utf-8"))))
426 (open-input-string "empty file\n"))
427 ("https://crates.io/api/v1/crates/leaf-alice/0.7.5/dependencies"
428 (open-input-string test-leaf-alice-dependencies))
429 ("https://crates.io/api/v1/crates/leaf-bob"
430 (open-input-string test-leaf-bob-crate))
431 ("https://crates.io/api/v1/crates/leaf-bob/3.0.1/download"
432 (set! test-source-hash
433 (bytevector->nix-base32-string
434 (sha256 (string->bytevector "empty file\n" "utf-8"))))
435 (open-input-string "empty file\n"))
436 ("https://crates.io/api/v1/crates/leaf-bob/3.0.1/dependencies"
437 (open-input-string test-leaf-bob-dependencies))
438 (_ (error "Unexpected URL: " url)))))
439 (match (crate-recursive-import "root")
440 ;; rust-intermediate-b has no dependency on the rust-leaf-alice
441 ;; package, so this is a valid ordering
442 (((define-public 'rust-leaf-alice-0.7
443 (package
444 (name "rust-leaf-alice")
445 (version "0.7.5")
446 (source
447 (origin
448 (method url-fetch)
449 (uri (crate-uri "leaf-alice" version))
450 (file-name
451 (string-append name "-" version ".tar.gz"))
452 (sha256
453 (base32
454 (? string? hash)))))
455 (build-system cargo-build-system)
456 (arguments ('quasiquote (#:skip-build? #t)))
457 (home-page "http://example.com")
458 (synopsis "summary")
459 (description "summary")
460 (license (list license:expat license:asl2.0))))
461 (define-public 'rust-leaf-bob-3
462 (package
463 (name "rust-leaf-bob")
464 (version "3.0.1")
465 (source
466 (origin
467 (method url-fetch)
468 (uri (crate-uri "leaf-bob" version))
469 (file-name
470 (string-append name "-" version ".tar.gz"))
471 (sha256
472 (base32
473 (? string? hash)))))
474 (build-system cargo-build-system)
475 (arguments ('quasiquote (#:skip-build? #t)))
476 (home-page "http://example.com")
477 (synopsis "summary")
478 (description "summary")
479 (license (list license:expat license:asl2.0))))
480 (define-public 'rust-intermediate-b-1
481 (package
482 (name "rust-intermediate-b")
483 (version "1.2.3")
484 (source
485 (origin
486 (method url-fetch)
487 (uri (crate-uri "intermediate-b" version))
488 (file-name
489 (string-append name "-" version ".tar.gz"))
490 (sha256
491 (base32
492 (? string? hash)))))
493 (build-system cargo-build-system)
494 (arguments
495 ('quasiquote (#:skip-build? #t
496 #:cargo-inputs
497 (("rust-leaf-bob"
498 ('unquote rust-leaf-bob-3))))))
499 (home-page "http://example.com")
500 (synopsis "summary")
501 (description "summary")
502 (license (list license:expat license:asl2.0))))
503 (define-public 'rust-intermediate-a-1
504 (package
505 (name "rust-intermediate-a")
506 (version "1.0.42")
507 (source
508 (origin
509 (method url-fetch)
510 (uri (crate-uri "intermediate-a" version))
511 (file-name
512 (string-append name "-" version ".tar.gz"))
513 (sha256
514 (base32
515 (? string? hash)))))
516 (build-system cargo-build-system)
517 (arguments
518 ('quasiquote (#:skip-build? #t
519 #:cargo-inputs
520 (("rust-intermediate-b"
521 ('unquote rust-intermediate-b-1))
522 ("rust-leaf-alice"
523 ('unquote 'rust-leaf-alice-0.7))
524 ("rust-leaf-bob"
525 ('unquote rust-leaf-bob-3))))))
526 (home-page "http://example.com")
527 (synopsis "summary")
528 (description "summary")
529 (license (list license:expat license:asl2.0))))
530 (define-public 'rust-root-1
531 (package
532 (name "rust-root")
533 (version "1.0.4")
534 (source
535 (origin
536 (method url-fetch)
537 (uri (crate-uri "root" version))
538 (file-name
539 (string-append name "-" version ".tar.gz"))
540 (sha256
541 (base32
542 (? string? hash)))))
543 (build-system cargo-build-system)
544 (arguments
545 ('quasiquote (#:cargo-inputs
546 (("rust-intermediate-a"
547 ('unquote rust-intermediate-a-1))
548 ("rust-intermediate-b"
549 ('unquote rust-intermediate-b-1))
550 ("rust-leaf-alice"
551 ('unquote 'rust-leaf-alice-0.7))
552 ("rust-leaf-bob"
553 ('unquote rust-leaf-bob-3))))))
554 (home-page "http://example.com")
555 (synopsis "summary")
556 (description "summary")
557 (license (list license:expat license:asl2.0)))))
558 #t)
559 (x
560 (pk 'fail x #f)))))
561
562 (test-equal "licenses: MIT OR Apache-2.0"
563 '(license:expat license:asl2.0)
564 (string->license "MIT OR Apache-2.0"))
565
566 (test-equal "licenses: Apache-2.0 / MIT"
567 '(license:asl2.0 license:expat)
568 (string->license "Apache-2.0 / MIT"))
569
570 (test-equal "licenses: Apache-2.0 WITH LLVM-exception"
571 '(license:asl2.0 unknown-license!)
572 (string->license "Apache-2.0 WITH LLVM-exception"))
573
574 (test-equal "licenses: MIT/Apache-2.0 AND BSD-2-Clause"
575 '(license:expat license:asl2.0 license:bsd-2)
576 (string->license "MIT/Apache-2.0 AND BSD-2-Clause"))
577
578 (test-equal "licenses: MIT/Apache-2.0"
579 '(license:expat license:asl2.0)
580 (string->license "MIT/Apache-2.0"))
581
582
583 \f
584 (define test-doctool-crate
585 "{
586 \"crate\": {
587 \"max_version\": \"2.2.2\",
588 \"name\": \"leaf-bob\",
589 \"description\": \"summary\",
590 \"homepage\": \"http://example.com\",
591 \"repository\": \"http://example.com\",
592 \"keywords\": [\"dummy\", \"test\"],
593 \"categories\": [\"test\"]
594 \"actual_versions\": [
595 { \"id\": 234280,
596 \"num\": \"2.2.2\",
597 \"license\": \"MIT OR Apache-2.0\",
598 \"links\": {
599 \"dependencies\": \"/api/v1/crates/doctool/2.2.2/dependencies\"
600 }
601 }
602 ]
603 }
604 }")
605
606 ;; FIXME: This test depends on some existing packages
607 (define test-doctool-dependencies
608 "{
609 \"dependencies\": [
610 {
611 \"crate_id\": \"docopt\",
612 \"kind\": \"normal\",
613 \"req\": \"^0.8.1\"
614 }
615 ]
616 }")
617
618
619 (test-assert "self-test: rust-docopt 0.8.x is gone, please adjust the test case"
620 (not (null? (find-packages-by-name "rust-docopt" "0.8"))))
621
622 (unless have-guile-semver? (test-skip 1))
623 (test-assert "cargo-recursive-import-hoors-existing-packages"
624 (mock ((guix http-client) http-fetch
625 (lambda (url . rest)
626 (match url
627 ("https://crates.io/api/v1/crates/doctool"
628 (open-input-string test-doctool-crate))
629 ("https://crates.io/api/v1/crates/doctool/2.2.2/download"
630 (set! test-source-hash
631 (bytevector->nix-base32-string
632 (sha256 (string->bytevector "empty file\n" "utf-8"))))
633 (open-input-string "empty file\n"))
634 ("https://crates.io/api/v1/crates/doctool/2.2.2/dependencies"
635 (open-input-string test-doctool-dependencies))
636 (_ (error "Unexpected URL: " url)))))
637 (match (crate-recursive-import "doctool")
638 (((define-public 'rust-doctool-2
639 (package
640 (name "rust-doctool")
641 (version "2.2.2")
642 (source
643 (origin
644 (method url-fetch)
645 (uri (crate-uri "doctool" version))
646 (file-name
647 (string-append name "-" version ".tar.gz"))
648 (sha256
649 (base32
650 (? string? hash)))))
651 (build-system cargo-build-system)
652 (arguments
653 ('quasiquote (#:cargo-inputs
654 (("rust-docopt"
655 ('unquote 'rust-docopt-0.8))))))
656 (home-page "http://example.com")
657 (synopsis "summary")
658 (description "summary")
659 (license (list license:expat license:asl2.0)))))
660 #t)
661 (x
662 (pk 'fail x #f)))))
663
664 (test-end "crate")