| 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 | ;;; |
| 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) |
| 25 | #:use-module (guix grafts) |
| 26 | #:use-module (srfi srfi-64) |
| 27 | #:use-module (ice-9 match)) |
| 28 | |
| 29 | ;; Globally disable grafts because they can trigger early builds. |
| 30 | (%graft? #f) |
| 31 | |
| 32 | (define test-json |
| 33 | "{ |
| 34 | \"metadata\" : { |
| 35 | \"prereqs\" : { |
| 36 | \"runtime\" : { |
| 37 | \"requires\" : { |
| 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\", |
| 52 | \"author\" : \"Guix\", |
| 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 |
| 64 | (lambda* (url file-name #:key (mirrors '())) |
| 65 | (with-output-to-file file-name |
| 66 | (lambda () |
| 67 | (display |
| 68 | (match url |
| 69 | ("http://api.metacpan.org/release/Foo-Bar" |
| 70 | test-json) |
| 71 | ("http://api.metacpan.org/module/Test::Script" |
| 72 | "{ \"distribution\" : \"Test-Script\" }") |
| 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 | ('inputs |
| 89 | ('quasiquote |
| 90 | (("perl-test-script" ('unquote 'perl-test-script))))) |
| 91 | ('home-page "http://search.cpan.org/dist/Foo-Bar") |
| 92 | ('synopsis "Fizzle Fuzz") |
| 93 | ('description 'fill-in-yourself!) |
| 94 | ('license (package-license perl))) |
| 95 | (string=? (bytevector->nix-base32-string |
| 96 | (call-with-input-string test-source port-sha256)) |
| 97 | hash)) |
| 98 | (x |
| 99 | (pk 'fail x #f))))) |
| 100 | |
| 101 | (test-equal "source-url-http" |
| 102 | ((@@ (guix import cpan) fix-source-url) |
| 103 | "http://cpan.metacpan.org/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz") |
| 104 | "mirror://cpan/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz") |
| 105 | |
| 106 | (test-equal "source-url-https" |
| 107 | ((@@ (guix import cpan) fix-source-url) |
| 108 | "https://cpan.metacpan.org/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz") |
| 109 | "mirror://cpan/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz") |
| 110 | |
| 111 | (test-end "cpan") |