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>
5 ;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
7 ;;; This file is part of GNU Guix.
9 ;;; GNU Guix is free software; you can redistribute it and/or modify it
10 ;;; under the terms of the GNU General Public License as published by
11 ;;; the Free Software Foundation; either version 3 of the License, or (at
12 ;;; your option) any later version.
14 ;;; GNU Guix is distributed in the hope that it will be useful, but
15 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;;; GNU General Public License for more details.
19 ;;; You should have received a copy of the GNU General Public License
20 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
22 (define-module (test-import-utils)
23 #:use-module (guix tests)
24 #:use-module (guix import utils)
25 #:use-module ((guix licenses) #:prefix license:)
26 #:use-module (guix packages)
27 #:use-module (guix build-system)
28 #:use-module (gnu packages)
29 #:use-module (srfi srfi-64)
30 #:use-module (ice-9 match))
32 (test-begin "import-utils")
34 (test-equal "beautify-description: use double spacing"
35 "This is a package. It is great. Trust me Mr. Hendrix."
37 "This is a package. It is great. Trust me Mr. Hendrix."))
39 (test-equal "beautify-description: transform fragment into sentence"
40 "This package provides a function to establish world peace"
41 (beautify-description "A function to establish world peace"))
43 (test-equal "license->symbol"
45 (license->symbol license:lgpl2.0))
47 (test-equal "recursive-import"
48 '((package ;package expressions in topological order
52 (inputs `(("bar" ,bar)))))
53 (recursive-import "foo"
57 (("foo" #:version #f #:repo 'repo)
60 (inputs `(("bar" ,bar))))
62 (("bar" #:version #f #:repo 'repo)
66 #:guix-name identity))
68 (test-equal "recursive-import: skip false packages (toplevel)"
70 (recursive-import "foo"
74 (("foo" #:version #f #:repo 'repo)
76 #:guix-name identity))
78 (test-equal "recursive-import: skip false packages (dependency)"
81 (inputs `(("bar" ,bar)))))
82 (recursive-import "foo"
86 (("foo" #:version #f #:repo 'repo)
89 (inputs `(("bar" ,bar))))
91 (("bar" #:version #f #:repo 'repo)
93 #:guix-name identity))
95 (test-assert "alist->package with simple source"
96 (let* ((meta '(("name" . "hello")
99 ;; Use a 'file://' URI so that we don't cause a download.
100 ,(string-append "file://"
101 (search-path %load-path "guix.scm")))
102 ("build-system" . "gnu")
103 ("home-page" . "https://gnu.org")
104 ("synopsis" . "Say hi")
105 ("description" . "This package says hi.")
106 ("license" . "GPL-3.0+")))
107 (pkg (alist->package meta)))
109 (license:license? (package-license pkg))
110 (build-system? (package-build-system pkg))
111 (origin? (package-source pkg)))))
113 (test-assert "alist->package with explicit source"
114 (let* ((meta '(("name" . "hello")
116 ("source" . (("method" . "url-fetch")
117 ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
120 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
121 ("build-system" . "gnu")
122 ("home-page" . "https://gnu.org")
123 ("synopsis" . "Say hi")
124 ("description" . "This package says hi.")
125 ("license" . "GPL-3.0+")))
126 (pkg (alist->package meta)))
128 (license:license? (package-license pkg))
129 (build-system? (package-build-system pkg))
130 (origin? (package-source pkg))
131 (equal? (origin-sha256 (package-source pkg))
132 (base32 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
134 (test-equal "alist->package with false license" ;<https://bugs.gnu.org/30470>
136 (let* ((meta '(("name" . "hello")
138 ("source" . (("method" . "url-fetch")
139 ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
142 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
143 ("build-system" . "gnu")
144 ("home-page" . "https://gnu.org")
145 ("synopsis" . "Say hi")
146 ("description" . "This package says hi.")
148 ;; Note: Use 'or' because comparing with #f otherwise succeeds when
149 ;; there's an exception instead of an actual #f.
150 (or (package-license (alist->package meta))
153 (test-equal "alist->package with SPDX license name 1/2" ;<https://bugs.gnu.org/45453>
155 (let* ((meta '(("name" . "hello")
157 ("source" . (("method" . "url-fetch")
158 ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
161 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
162 ("build-system" . "gnu")
163 ("home-page" . "https://gnu.org")
164 ("synopsis" . "Say hi")
165 ("description" . "This package says hi.")
166 ("license" . "expat"))))
167 (package-license (alist->package meta))))
169 (test-equal "alist->package with SPDX license name 2/2" ;<https://bugs.gnu.org/45453>
171 (let* ((meta '(("name" . "hello")
173 ("source" . (("method" . "url-fetch")
174 ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
177 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
178 ("build-system" . "gnu")
179 ("home-page" . "https://gnu.org")
180 ("synopsis" . "Say hi")
181 ("description" . "This package says hi.")
182 ("license" . "MIT"))))
183 (package-license (alist->package meta))))
185 (test-equal "alist->package with dependencies"
186 `(("gettext" ,(specification->package "gettext")))
187 (let* ((meta '(("name" . "hello")
189 ("source" . (("method" . "url-fetch")
190 ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
193 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
194 ("build-system" . "gnu")
195 ("home-page" . "https://gnu.org")
196 ("synopsis" . "Say hi")
197 ("description" . "This package says hi.")
199 ;; Note: As with Guile-JSON 3.x, JSON arrays are represented
201 ("native-inputs" . #("gettext"))
204 (package-native-inputs (alist->package meta))))
206 (test-end "import-utils")