import: Add CPAN importer.
[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 (srfi srfi-64)
25 #:use-module (ice-9 match))
26
27 (define test-json
28 "{
29 \"metadata\" : {
30 \"prereqs\" : {
31 \"configure\" : {
32 \"requires\" : {
33 \"ExtUtils::MakeMaker\" : \"0\",
34 \"Module::Build\" : \"0.28\"
35 }
36 },
37 \"runtime\" : {
38 \"requires\" : {
39 \"Getopt::Std\" : \"0\",
40 \"Test::Script\" : \"1.05\",
41 }
42 }
43 }
44 \"name\" : \"Foo-Bar\",
45 \"version\" : \"0.1\"
46 }
47 \"name\" : \"Foo-Bar-0.1\",
48 \"distribution\" : \"Foo-Bar\",
49 \"license\" : [
50 \"perl_5\"
51 ],
52 \"abstract\" : \"Fizzle Fuzz\",
53 \"download_url\" : \"http://example.com/Foo-Bar-0.1.tar.gz\",
54 \"author\" : \"GUIX\",
55 \"version\" : \"0.1\"
56 }")
57
58 (define test-source
59 "foobar")
60
61 (test-begin "cpan")
62
63 (test-assert "cpan->guix-package"
64 ;; Replace network resources with sample data.
65 (mock ((guix build download) url-fetch
66 (lambda* (url file-name #:key (mirrors '()))
67 (with-output-to-file file-name
68 (lambda ()
69 (display
70 (match url
71 ("http://api.metacpan.org/release/Foo-Bar"
72 test-json)
73 ("http://example.com/Foo-Bar-0.1.tar.gz"
74 test-source)
75 (_ (error "Unexpected URL: " url))))))))
76 (match (cpan->guix-package "Foo::Bar")
77 (('package
78 ('name "perl-foo-bar")
79 ('version "0.1")
80 ('source ('origin
81 ('method 'url-fetch)
82 ('uri ('string-append "http://example.com/Foo-Bar-"
83 'version ".tar.gz"))
84 ('sha256
85 ('base32
86 (? string? hash)))))
87 ('build-system 'perl-build-system)
88 ('native-inputs
89 ('quasiquote
90 (("perl-module-build" ('unquote 'perl-module-build)))))
91 ('inputs
92 ('quasiquote
93 (("perl-test-script" ('unquote 'perl-test-script)))))
94 ('home-page "http://search.cpan.org/dist/Foo-Bar")
95 ('synopsis "Fizzle Fuzz")
96 ('description 'fill-in-yourself!)
97 ('license 'gpl1+))
98 (string=? (bytevector->nix-base32-string
99 (call-with-input-string test-source port-sha256))
100 hash))
101 (x
102 (pk 'fail x #f)))))
103
104 (test-end "cpan")
105
106 \f
107 (exit (= (test-runner-fail-count (test-runner-current)) 0))