1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2018 Julien Lepiller <julien@lepiller.eu>
4 ;;; This file is part of GNU Guix.
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.
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.
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/>.
19 (define-module (test-opam)
20 #:use-module (guix import opam)
21 #:use-module (guix base32)
22 #:use-module (gcrypt 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))
30 "http: \"https://example.org/foo-1.0.0.tar.gz\"
31 checksum: \"ac8920f39a8100b94820659bc2c20817\"")
33 (define test-source-hash
37 "repo ac8920f39a8100b94820659bc2c20817 0o644
38 packages/foo/foo.1.0.0/url ac8920f39a8100b94820659bc2c20817 0o644
39 packages/foo/foo.1.0.0/opam ac8920f39a8100b94820659bc2c20817 0o644
40 packages/foo/foo.1.0.0/descr ac8920f39a8100b94820659bc2c20817 0o644")
42 (define test-opam-file
44 maintainer: \"Alice Doe\"
45 authors: \"Alice Doe, John Doe\"
46 homepage: \"https://example.org/\"
47 bug-reports: \"https://example.org/bugs\"
49 dev-repo: \"https://example.org/git\"
51 \"ocaml\" \"pkg/pkg.ml\" \"build\" \"--pinned\" \"%{pinned}%\"
54 \"ocaml\" \"pkg/pkg.ml\" \"build\" \"--pinned\" \"%{pinned}%\" \"--tests\" \"true\"
57 \"alcotest\" {test & >= \"0.7.2\"}
58 \"ocamlbuild\" {build & >= \"0.9.2\"}
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)
68 ("https://example.org/foo-1.0.0.tar.gz"
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
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
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")
99 ('uri "https://example.org/foo-1.0.0.tar.gz")
103 ('build-system 'ocaml-build-system)
106 (("ocamlbuild" ('unquote 'ocamlbuild))
107 ("ocaml-alcotest" ('unquote 'ocaml-alcotest)))))
108 ('home-page "https://example.org/")
111 ('license 'license:expat))
112 (string=? (bytevector->nix-base32-string
116 (pk 'fail x #f)))))))