Merge branch 'master' into core-updates
[jackhill/guix/guix.git] / tests / cpan.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015 Eric Bavier <bavier@member.fsf.org>
3 ;;;
4 ;;; This file is part of GNU Guix.
5 ;;;
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
10 ;;;
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
15 ;;;
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19 (define-module (test-cpan)
20 #:use-module (guix import cpan)
21 #:use-module (guix base32)
22 #:use-module (guix hash)
23 #:use-module (guix tests)
24 #:use-module (guix grafts)
25 #:use-module (srfi srfi-64)
26 #:use-module (ice-9 match))
27
28 ;; Globally disable grafts because they can trigger early builds.
29 (%graft? #f)
30
31 (define test-json
32 "{
33 \"metadata\" : {
34 \"prereqs\" : {
35 \"runtime\" : {
36 \"requires\" : {
37 \"Test::Script\" : \"1.05\",
38 }
39 }
40 }
41 \"name\" : \"Foo-Bar\",
42 \"version\" : \"0.1\"
43 }
44 \"name\" : \"Foo-Bar-0.1\",
45 \"distribution\" : \"Foo-Bar\",
46 \"license\" : [
47 \"perl_5\"
48 ],
49 \"abstract\" : \"Fizzle Fuzz\",
50 \"download_url\" : \"http://example.com/Foo-Bar-0.1.tar.gz\",
51 \"author\" : \"Guix\",
52 \"version\" : \"0.1\"
53 }")
54
55 (define test-source
56 "foobar")
57
58 (test-begin "cpan")
59
60 (test-assert "cpan->guix-package"
61 ;; Replace network resources with sample data.
62 (mock ((guix build download) url-fetch
63 (lambda* (url file-name #:key (mirrors '()))
64 (with-output-to-file file-name
65 (lambda ()
66 (display
67 (match url
68 ("http://api.metacpan.org/release/Foo-Bar"
69 test-json)
70 ("http://api.metacpan.org/module/Test::Script"
71 "{ \"distribution\" : \"Test-Script\" }")
72 ("http://example.com/Foo-Bar-0.1.tar.gz"
73 test-source)
74 (_ (error "Unexpected URL: " url))))))))
75 (match (cpan->guix-package "Foo::Bar")
76 (('package
77 ('name "perl-foo-bar")
78 ('version "0.1")
79 ('source ('origin
80 ('method 'url-fetch)
81 ('uri ('string-append "http://example.com/Foo-Bar-"
82 'version ".tar.gz"))
83 ('sha256
84 ('base32
85 (? string? hash)))))
86 ('build-system 'perl-build-system)
87 ('inputs
88 ('quasiquote
89 (("perl-test-script" ('unquote 'perl-test-script)))))
90 ('home-page "http://search.cpan.org/dist/Foo-Bar")
91 ('synopsis "Fizzle Fuzz")
92 ('description 'fill-in-yourself!)
93 ('license (package-license perl)))
94 (string=? (bytevector->nix-base32-string
95 (call-with-input-string test-source port-sha256))
96 hash))
97 (x
98 (pk 'fail x #f)))))
99
100 (test-end "cpan")