1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015 Eric Bavier <bavier@member.fsf.org>
3 ;;; Copyright © 2016 Alex Sassmannshausen <alex@pompo.co>
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-cpan)
21 #:use-module (guix import cpan)
22 #:use-module (guix base32)
23 #:use-module (gcrypt hash)
24 #:use-module (guix tests)
25 #:use-module (guix grafts)
26 #:use-module (srfi srfi-64)
27 #:use-module (ice-9 match))
29 ;; Globally disable grafts because they can trigger early builds.
38 \"Test::Script\" : \"1.05\",
42 \"name\" : \"Foo-Bar\",
45 \"name\" : \"Foo-Bar-0.1\",
46 \"distribution\" : \"Foo-Bar\",
50 \"abstract\" : \"Fizzle Fuzz\",
51 \"download_url\" : \"http://example.com/Foo-Bar-0.1.tar.gz\",
52 \"author\" : \"Guix\",
61 (test-assert "cpan->guix-package"
62 ;; Replace network resources with sample data.
63 (mock ((guix build download) url-fetch
64 (lambda* (url file-name
66 (mirrors '()) verify-certificate?)
67 (with-output-to-file file-name
71 ("http://example.com/Foo-Bar-0.1.tar.gz"
73 (_ (error "Unexpected URL: " url))))))))
74 (mock ((guix http-client) http-fetch
77 ("https://fastapi.metacpan.org/v1/release/Foo-Bar"
78 (values (open-input-string test-json)
79 (string-length test-json)))
80 ("https://fastapi.metacpan.org/v1/module/Test::Script?fields=distribution"
81 (let ((result "{ \"distribution\" : \"Test-Script\" }"))
82 (values (open-input-string result)
83 (string-length result))))
84 (_ (error "Unexpected URL: " url)))))
85 (match (cpan->guix-package "Foo::Bar")
87 ('name "perl-foo-bar")
91 ('uri ('string-append "http://example.com/Foo-Bar-"
96 ('build-system 'perl-build-system)
99 (("perl-test-script" ('unquote 'perl-test-script)))))
100 ('home-page "https://metacpan.org/release/Foo-Bar")
101 ('synopsis "Fizzle Fuzz")
102 ('description 'fill-in-yourself!)
103 ('license 'perl-license))
104 (string=? (bytevector->nix-base32-string
105 (call-with-input-string test-source port-sha256))
110 (test-equal "source-url-http"
111 ((@@ (guix import cpan) cpan-source-url)
113 "http://cpan.metacpan.org/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz")))
114 "mirror://cpan/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz")
116 (test-equal "source-url-https"
117 ((@@ (guix import cpan) cpan-source-url)
119 "https://cpan.metacpan.org/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz")))
120 "mirror://cpan/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz")