1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015, 2017 Ricardo Wurmus <rekado@elephly.net>
3 ;;; Copyright © 2016 Ben Woodcroft <donttrustben@gmail.com>
4 ;;; Copyright © 2020 Martin Becze <mjbecze@riseup.net>
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-import-utils)
22 #:use-module (guix tests)
23 #:use-module (guix import utils)
24 #:use-module ((guix licenses) #:prefix license:)
25 #:use-module (guix packages)
26 #:use-module (guix build-system)
27 #:use-module (gnu packages)
28 #:use-module (srfi srfi-64)
29 #:use-module (ice-9 match))
31 (test-begin "import-utils")
33 (test-equal "beautify-description: use double spacing"
34 "This is a package. It is great. Trust me Mr. Hendrix."
36 "This is a package. It is great. Trust me Mr. Hendrix."))
38 (test-equal "beautify-description: transform fragment into sentence"
39 "This package provides a function to establish world peace"
40 (beautify-description "A function to establish world peace"))
42 (test-equal "license->symbol"
44 (license->symbol license:lgpl2.0))
46 (test-equal "recursive-import"
47 '((package ;package expressions in topological order
51 (inputs `(("bar" ,bar)))))
52 (recursive-import "foo"
56 (("foo" #:version #f #:repo 'repo)
59 (inputs `(("bar" ,bar))))
61 (("bar" #:version #f #:repo 'repo)
65 #:guix-name identity))
67 (test-assert "alist->package with simple source"
68 (let* ((meta '(("name" . "hello")
71 ;; Use a 'file://' URI so that we don't cause a download.
72 ,(string-append "file://"
73 (search-path %load-path "guix.scm")))
74 ("build-system" . "gnu")
75 ("home-page" . "https://gnu.org")
76 ("synopsis" . "Say hi")
77 ("description" . "This package says hi.")
78 ("license" . "GPL-3.0+")))
79 (pkg (alist->package meta)))
81 (license:license? (package-license pkg))
82 (build-system? (package-build-system pkg))
83 (origin? (package-source pkg)))))
85 (test-assert "alist->package with explicit source"
86 (let* ((meta '(("name" . "hello")
88 ("source" . (("method" . "url-fetch")
89 ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
92 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
93 ("build-system" . "gnu")
94 ("home-page" . "https://gnu.org")
95 ("synopsis" . "Say hi")
96 ("description" . "This package says hi.")
97 ("license" . "GPL-3.0+")))
98 (pkg (alist->package meta)))
100 (license:license? (package-license pkg))
101 (build-system? (package-build-system pkg))
102 (origin? (package-source pkg))
103 (equal? (origin-sha256 (package-source pkg))
104 (base32 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
106 (test-equal "alist->package with false license" ;<https://bugs.gnu.org/30470>
108 (let* ((meta '(("name" . "hello")
110 ("source" . (("method" . "url-fetch")
111 ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
114 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
115 ("build-system" . "gnu")
116 ("home-page" . "https://gnu.org")
117 ("synopsis" . "Say hi")
118 ("description" . "This package says hi.")
120 ;; Note: Use 'or' because comparing with #f otherwise succeeds when
121 ;; there's an exception instead of an actual #f.
122 (or (package-license (alist->package meta))
125 (test-equal "alist->package with SPDX license name 1/2" ;<https://bugs.gnu.org/45453>
127 (let* ((meta '(("name" . "hello")
129 ("source" . (("method" . "url-fetch")
130 ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
133 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
134 ("build-system" . "gnu")
135 ("home-page" . "https://gnu.org")
136 ("synopsis" . "Say hi")
137 ("description" . "This package says hi.")
138 ("license" . "expat"))))
139 (package-license (alist->package meta))))
141 (test-equal "alist->package with SPDX license name 2/2" ;<https://bugs.gnu.org/45453>
143 (let* ((meta '(("name" . "hello")
145 ("source" . (("method" . "url-fetch")
146 ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
149 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
150 ("build-system" . "gnu")
151 ("home-page" . "https://gnu.org")
152 ("synopsis" . "Say hi")
153 ("description" . "This package says hi.")
154 ("license" . "MIT"))))
155 (package-license (alist->package meta))))
157 (test-equal "alist->package with dependencies"
158 `(("gettext" ,(specification->package "gettext")))
159 (let* ((meta '(("name" . "hello")
161 ("source" . (("method" . "url-fetch")
162 ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
165 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
166 ("build-system" . "gnu")
167 ("home-page" . "https://gnu.org")
168 ("synopsis" . "Say hi")
169 ("description" . "This package says hi.")
171 ;; Note: As with Guile-JSON 3.x, JSON arrays are represented
173 ("native-inputs" . #("gettext"))
176 (package-native-inputs (alist->package meta))))
178 (test-end "import-utils")