1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014 David Thompson <davet@gnu.org>
3 ;;; Copyright © 2016 David Craven <david@craven.ch>
5 ;;; This file is part of GNU Guix.
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.
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.
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/>.
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 (gcrypt hash)
25 #:use-module (guix tests)
26 #:use-module (ice-9 iconv)
27 #:use-module (ice-9 match)
28 #:use-module (srfi srfi-64))
33 \"max_version\": \"1.0.0\",
35 \"license\": \"MIT/Apache-2.0\",
36 \"description\": \"summary\",
37 \"homepage\": \"http://example.com\",
38 \"repository\": \"http://example.com\",
42 (define test-dependencies
46 \"crate_id\": \"bar\",
52 (define test-source-hash
57 (test-equal "guix-package->crate-name"
59 (guix-package->crate-name
61 "rust-rustc-serialize"
63 (uri (crate-uri "rustc-serialize" "1.0")))))))
65 (test-assert "crate->guix-package"
66 ;; Replace network resources with sample data.
67 (mock ((guix http-client) http-fetch
70 ("https://crates.io/api/v1/crates/foo"
71 (open-input-string test-crate))
72 ("https://crates.io/api/v1/crates/foo/1.0.0/download"
73 (set! test-source-hash
74 (bytevector->nix-base32-string
75 (sha256 (string->bytevector "empty file\n" "utf-8"))))
76 (open-input-string "empty file\n"))
77 ("https://crates.io/api/v1/crates/foo/1.0.0/dependencies"
78 (open-input-string test-dependencies))
79 (_ (error "Unexpected URL: " url)))))
80 (match (crate->guix-package "foo")
86 ('uri ('crate-uri "foo" 'version))
87 ('file-name ('string-append 'name "-" 'version ".tar.gz"))
91 ('build-system 'cargo-build-system)
94 (("rust-bar" ('unquote 'rust-bar) "src"))))
95 ('home-page "http://example.com")
97 ('description "summary")
98 ('license ('list 'license:expat 'license:asl2.0)))
99 (string=? test-source-hash hash))