build-system: cargo: Make Cargo.toml writeable.
[jackhill/guix/guix.git] / tests / crate.scm
CommitLineData
3e0c0365
DC
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;;;
5;;; This file is part of GNU Guix.
6;;;
7;;; GNU Guix is free software; you can redistribute it and/or modify it
8;;; under the terms of the GNU General Public License as published by
9;;; the Free Software Foundation; either version 3 of the License, or (at
10;;; your option) any later version.
11;;;
12;;; GNU Guix is distributed in the hope that it will be useful, but
13;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;;; GNU General Public License for more details.
16;;;
17;;; You should have received a copy of the GNU General Public License
18;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
20(define-module (test-crate)
21 #:use-module (guix import crate)
22 #:use-module (guix base32)
23 #:use-module (guix build-system cargo)
24 #:use-module (guix hash)
25 #:use-module (guix tests)
26 #:use-module (ice-9 iconv)
27 #:use-module (ice-9 match)
28 #:use-module (srfi srfi-64))
29
30(define test-crate
31 "{
32 \"crate\": {
33 \"max_version\": \"1.0.0\",
34 \"name\": \"foo\",
35 \"license\": \"MIT/Apache-2.0\",
36 \"description\": \"summary\",
37 \"homepage\": \"http://example.com\",
38 }
39}")
40
41(define test-dependencies
42 "{
43 \"dependencies\": [
44 {
45 \"crate_id\": \"bar\",
46 \"kind\": \"normal\",
47 }
48 ]
49}")
50
51(define test-source-hash
52 "")
53
54(test-begin "crate")
55
56(test-equal "guix-package->crate-name"
57 "rustc-serialize"
58 (guix-package->crate-name
59 (dummy-package
60 "rust-rustc-serialize"
61 (source (dummy-origin
62 (uri (crate-uri "rustc-serialize" "1.0")))))))
63
64(test-assert "crate->guix-package"
65 ;; Replace network resources with sample data.
66 (mock ((guix http-client) http-fetch
67 (lambda (url)
68 (match url
69 ("https://crates.io/api/v1/crates/foo"
70 (open-input-string test-crate))
71 ("https://crates.io/api/v1/crates/foo/1.0.0/download"
72 (set! test-source-hash
73 (bytevector->nix-base32-string
74 (sha256 (string->bytevector "empty file\n" "utf-8"))))
75 (open-input-string "empty file\n"))
76 ("https://crates.io/api/v1/crates/foo/1.0.0/dependencies"
77 (open-input-string test-dependencies))
78 (_ (error "Unexpected URL: " url)))))
79 (match (crate->guix-package "foo")
80 (('package
81 ('name "rust-foo")
82 ('version "1.0.0")
83 ('source ('origin
84 ('method 'url-fetch)
85 ('uri ('crate-uri "foo" 'version))
86 ('file-name ('string-append 'name "-" 'version ".tar.gz"))
87 ('sha256
88 ('base32
89 (? string? hash)))))
90 ('build-system 'cargo-build-system)
91 ('inputs
92 ('quasiquote
93 (("rust-bar" ('unquote 'rust-bar)))))
94 ('home-page "http://example.com")
95 ('synopsis "summary")
96 ('description "summary")
97 ('license ('list 'license:expat 'license:asl2.0)))
98 (string=? test-source-hash hash))
99 (x
100 (pk 'fail x #f)))))
101
102(test-end "crate")