inferior: Add home-page and location package accessors.
[jackhill/guix/guix.git] / tests / opam.scm
CommitLineData
b24443bf
JL
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2018 Julien Lepiller <julien@lepiller.eu>
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-opam)
20 #:use-module (guix import opam)
21 #:use-module (guix base32)
22 #:use-module (guix hash)
23 #:use-module (guix tests)
24 #:use-module ((guix build utils) #:select (delete-file-recursively mkdir-p which))
25 #:use-module (srfi srfi-64)
26 #:use-module (web uri)
27 #:use-module (ice-9 match))
28
29(define test-url-file
30 "http: \"https://example.org/foo-1.0.0.tar.gz\"
31checksum: \"ac8920f39a8100b94820659bc2c20817\"")
32
33(define test-source-hash
34 "")
35
36(define test-urls
37 "repo ac8920f39a8100b94820659bc2c20817 0o644
38packages/foo/foo.1.0.0/url ac8920f39a8100b94820659bc2c20817 0o644
39packages/foo/foo.1.0.0/opam ac8920f39a8100b94820659bc2c20817 0o644
40packages/foo/foo.1.0.0/descr ac8920f39a8100b94820659bc2c20817 0o644")
41
42(define test-opam-file
43"opam-version: 1.2
44maintainer: \"Alice Doe\"
45authors: \"Alice Doe, John Doe\"
46homepage: \"https://example.org/\"
47bug-reports: \"https://example.org/bugs\"
48license: \"MIT\"
49dev-repo: \"https://example.org/git\"
50build: [
51 \"ocaml\" \"pkg/pkg.ml\" \"build\" \"--pinned\" \"%{pinned}%\"
52]
53build-test: [
54 \"ocaml\" \"pkg/pkg.ml\" \"build\" \"--pinned\" \"%{pinned}%\" \"--tests\" \"true\"
55]
56depends: [
57 \"alcotest\" {test & >= \"0.7.2\"}
58 \"ocamlbuild\" {build & >= \"0.9.2\"}
59]")
60
61(test-begin "opam")
62
63(test-assert "opam->guix-package"
64 ;; Replace network resources with sample data.
65 (mock ((guix import utils) url-fetch
66 (lambda (url file-name)
67 (match url
68 ("https://example.org/foo-1.0.0.tar.gz"
69 (begin
70 (mkdir-p "foo-1.0.0")
71 (system* "tar" "czvf" file-name "foo-1.0.0/")
72 (delete-file-recursively "foo-1.0.0")
73 (set! test-source-hash
74 (call-with-input-file file-name port-sha256))))
75 (_ (error "Unexpected URL: " url)))))
76 (mock ((guix http-client) http-fetch/cached
77 (lambda (url . rest)
78 (match (uri->string url)
79 ("https://opam.ocaml.org/urls.txt"
80 (values (open-input-string test-urls)
81 (string-length test-urls)))
82 (_ (error "Unexpected URL: " url)))))
83 (mock ((guix http-client) http-fetch
84 (lambda (url . rest)
85 (match url
86 ("https://opam.ocaml.org/packages/foo/foo.1.0.0/url"
87 (values (open-input-string test-url-file)
88 (string-length test-url-file)))
89 ("https://opam.ocaml.org/packages/foo/foo.1.0.0/opam"
90 (values (open-input-string test-opam-file)
91 (string-length test-opam-file)))
92 (_ (error "Unexpected URL: " url)))))
93 (match (opam->guix-package "foo")
94 (('package
95 ('name "ocaml-foo")
96 ('version "1.0.0")
97 ('source ('origin
98 ('method 'url-fetch)
99 ('uri "https://example.org/foo-1.0.0.tar.gz")
100 ('sha256
101 ('base32
102 (? string? hash)))))
103 ('build-system 'ocaml-build-system)
104 ('inputs
105 ('quasiquote
106 (("ocamlbuild" ('unquote 'ocamlbuild))
107 ("ocaml-alcotest" ('unquote 'ocaml-alcotest)))))
108 ('home-page "https://example.org/")
109 ('synopsis "")
110 ('description "")
111 ('license 'license:expat))
112 (string=? (bytevector->nix-base32-string
113 test-source-hash)
114 hash))
115 (x
116 (pk 'fail x #f)))))))
117
118(test-end "opam")