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>
4 ;;; Copyright © 2017 Tobias Geerinckx-Rice <me@tobias.gr>
6 ;;; This file is part of GNU Guix.
8 ;;; GNU Guix is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
13 ;;; GNU Guix is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21 (define-module (test-cpan)
22 #:use-module (guix import cpan)
23 #:use-module (guix base32)
24 #:use-module (guix hash)
25 #:use-module (guix tests)
26 #:use-module (guix grafts)
27 #:use-module (srfi srfi-64)
28 #:use-module (ice-9 match))
30 ;; Globally disable grafts because they can trigger early builds.
39 \"Test::Script\" : \"1.05\",
43 \"name\" : \"Foo-Bar\",
46 \"name\" : \"Foo-Bar-0.1\",
47 \"distribution\" : \"Foo-Bar\",
51 \"abstract\" : \"Fizzle Fuzz\",
52 \"download_url\" : \"http://example.com/Foo-Bar-0.1.tar.gz\",
53 \"author\" : \"Guix\",
62 (test-assert "cpan->guix-package"
63 ;; Replace network resources with sample data.
64 (mock ((guix build download) url-fetch
65 (lambda* (url file-name
67 (mirrors '()) verify-certificate?)
68 (with-output-to-file file-name
72 ("http://example.com/Foo-Bar-0.1.tar.gz"
74 (_ (error "Unexpected URL: " url))))))))
75 (mock ((guix http-client) http-fetch
78 ("https://fastapi.metacpan.org/v1/release/Foo-Bar"
79 (values (open-input-string test-json)
80 (string-length test-json)))
81 ("https://fastapi.metacpan.org/v1/module/Test::Script?fields=distribution"
82 (let ((result "{ \"distribution\" : \"Test-Script\" }"))
83 (values (open-input-string result)
84 (string-length result))))
85 (_ (error "Unexpected URL: " url)))))
86 (match (cpan->guix-package "Foo::Bar")
88 ('name "perl-foo-bar")
92 ('uri ('string-append "http://example.com/Foo-Bar-"
97 ('build-system 'perl-build-system)
100 (("perl-test-script" ('unquote 'perl-test-script)))))
101 ('home-page "https://search.cpan.org/dist/Foo-Bar/")
102 ('synopsis "Fizzle Fuzz")
103 ('description 'fill-in-yourself!)
104 ('license 'perl-license))
105 (string=? (bytevector->nix-base32-string
106 (call-with-input-string test-source port-sha256))
111 (test-equal "source-url-http"
112 ((@@ (guix import cpan) cpan-source-url)
114 "http://cpan.metacpan.org/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz")))
115 "mirror://cpan/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz")
117 (test-equal "source-url-https"
118 ((@@ (guix import cpan) cpan-source-url)
120 "https://cpan.metacpan.org/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz")))
121 "mirror://cpan/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz")