gnu: python-llvmlite: Build against LLVM 7.
[guix.git] / tests / crate.scm
bloba4a328d5073c64ec3367d80b1d5a71e7d8b78556
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/>.
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))
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     \"repository\": \"http://example.com\",
39   }
40 }")
42 (define test-dependencies
43   "{
44   \"dependencies\": [
45      {
46        \"crate_id\": \"bar\",
47        \"kind\": \"normal\",
48      }
49   ]
50 }")
52 (define test-source-hash
53   "")
55 (test-begin "crate")
57 (test-equal "guix-package->crate-name"
58   "rustc-serialize"
59   (guix-package->crate-name
60    (dummy-package
61     "rust-rustc-serialize"
62     (source (dummy-origin
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
68          (lambda (url . rest)
69            (match url
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")
81       (('package
82          ('name "rust-foo")
83          ('version "1.0.0")
84          ('source ('origin
85                     ('method 'url-fetch)
86                     ('uri ('crate-uri "foo" 'version))
87                     ('file-name ('string-append 'name "-" 'version ".tar.gz"))
88                     ('sha256
89                      ('base32
90                       (? string? hash)))))
91          ('build-system 'cargo-build-system)
92          ('arguments
93           ('quasiquote
94            (('#:cargo-inputs (("rust-bar" ('unquote rust-bar)))))))
95          ('home-page "http://example.com")
96          ('synopsis "summary")
97          ('description "summary")
98          ('license ('list 'license:expat 'license:asl2.0)))
99        (string=? test-source-hash hash))
100       (x
101        (pk 'fail x #f)))))
103 (test-end "crate")