Commit | Line | Data |
---|---|---|
d45dc6da EB |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2015 Eric Bavier <bavier@member.fsf.org> | |
5b8e564c | 3 | ;;; Copyright © 2016 Alex Sassmannshausen <alex@pompo.co> |
d45dc6da EB |
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/>. | |
19 | ||
20 | (define-module (test-cpan) | |
21 | #:use-module (guix import cpan) | |
22 | #:use-module (guix base32) | |
23 | #:use-module (guix hash) | |
24 | #:use-module (guix tests) | |
ef8de985 | 25 | #:use-module (guix grafts) |
d45dc6da EB |
26 | #:use-module (srfi srfi-64) |
27 | #:use-module (ice-9 match)) | |
28 | ||
ef8de985 LC |
29 | ;; Globally disable grafts because they can trigger early builds. |
30 | (%graft? #f) | |
31 | ||
d45dc6da EB |
32 | (define test-json |
33 | "{ | |
34 | \"metadata\" : { | |
35 | \"prereqs\" : { | |
d45dc6da EB |
36 | \"runtime\" : { |
37 | \"requires\" : { | |
d45dc6da EB |
38 | \"Test::Script\" : \"1.05\", |
39 | } | |
40 | } | |
41 | } | |
42 | \"name\" : \"Foo-Bar\", | |
43 | \"version\" : \"0.1\" | |
44 | } | |
45 | \"name\" : \"Foo-Bar-0.1\", | |
46 | \"distribution\" : \"Foo-Bar\", | |
47 | \"license\" : [ | |
48 | \"perl_5\" | |
49 | ], | |
50 | \"abstract\" : \"Fizzle Fuzz\", | |
51 | \"download_url\" : \"http://example.com/Foo-Bar-0.1.tar.gz\", | |
ef8de985 | 52 | \"author\" : \"Guix\", |
d45dc6da EB |
53 | \"version\" : \"0.1\" |
54 | }") | |
55 | ||
56 | (define test-source | |
57 | "foobar") | |
58 | ||
59 | (test-begin "cpan") | |
60 | ||
61 | (test-assert "cpan->guix-package" | |
62 | ;; Replace network resources with sample data. | |
63 | (mock ((guix build download) url-fetch | |
324a2ba5 LC |
64 | (lambda* (url file-name |
65 | #:key | |
66 | (mirrors '()) verify-certificate?) | |
d45dc6da EB |
67 | (with-output-to-file file-name |
68 | (lambda () | |
69 | (display | |
70 | (match url | |
d45dc6da EB |
71 | ("http://example.com/Foo-Bar-0.1.tar.gz" |
72 | test-source) | |
73 | (_ (error "Unexpected URL: " url)))))))) | |
662a1aa6 | 74 | (mock ((guix http-client) http-fetch |
ce8963c5 | 75 | (lambda (url . rest) |
662a1aa6 | 76 | (match url |
4679dd69 | 77 | ("https://fastapi.metacpan.org/v1/release/Foo-Bar" |
662a1aa6 RW |
78 | (values (open-input-string test-json) |
79 | (string-length test-json))) | |
4679dd69 | 80 | ("https://fastapi.metacpan.org/v1/module/Test::Script?fields=distribution" |
662a1aa6 RW |
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") | |
86 | (('package | |
87 | ('name "perl-foo-bar") | |
88 | ('version "0.1") | |
89 | ('source ('origin | |
90 | ('method 'url-fetch) | |
91 | ('uri ('string-append "http://example.com/Foo-Bar-" | |
92 | 'version ".tar.gz")) | |
93 | ('sha256 | |
94 | ('base32 | |
95 | (? string? hash))))) | |
96 | ('build-system 'perl-build-system) | |
23055424 | 97 | ('propagated-inputs |
662a1aa6 RW |
98 | ('quasiquote |
99 | (("perl-test-script" ('unquote 'perl-test-script))))) | |
dccd29d1 | 100 | ('home-page "https://metacpan.org/release/Foo-Bar") |
662a1aa6 RW |
101 | ('synopsis "Fizzle Fuzz") |
102 | ('description 'fill-in-yourself!) | |
79e5e00f | 103 | ('license 'perl-license)) |
662a1aa6 RW |
104 | (string=? (bytevector->nix-base32-string |
105 | (call-with-input-string test-source port-sha256)) | |
106 | hash)) | |
107 | (x | |
108 | (pk 'fail x #f)))))) | |
d45dc6da | 109 | |
5b8e564c | 110 | (test-equal "source-url-http" |
e69c1a54 RW |
111 | ((@@ (guix import cpan) cpan-source-url) |
112 | `(("download_url" . | |
113 | "http://cpan.metacpan.org/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz"))) | |
5b8e564c AS |
114 | "mirror://cpan/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz") |
115 | ||
116 | (test-equal "source-url-https" | |
e69c1a54 RW |
117 | ((@@ (guix import cpan) cpan-source-url) |
118 | `(("download_url" . | |
119 | "https://cpan.metacpan.org/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz"))) | |
5b8e564c AS |
120 | "mirror://cpan/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz") |
121 | ||
d45dc6da | 122 | (test-end "cpan") |