gnu: Add bsnes.
[jackhill/guix/guix.git] / tests / import-utils.scm
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 ;;;
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-import-utils)
21 #:use-module (guix tests)
22 #:use-module (guix import utils)
23 #:use-module ((guix licenses) #:prefix license:)
24 #:use-module (guix packages)
25 #:use-module (guix build-system)
26 #:use-module (gnu packages)
27 #:use-module (srfi srfi-64)
28 #:use-module (ice-9 match))
29
30 (test-begin "import-utils")
31
32 (test-equal "beautify-description: use double spacing"
33 "This is a package. It is great. Trust me Mr. Hendrix."
34 (beautify-description
35 "This is a package. It is great. Trust me Mr. Hendrix."))
36
37 (test-equal "beautify-description: transform fragment into sentence"
38 "This package provides a function to establish world peace"
39 (beautify-description "A function to establish world peace"))
40
41 (test-equal "license->symbol"
42 'license:lgpl2.0
43 (license->symbol license:lgpl2.0))
44
45 (test-equal "recursive-import"
46 '((package ;package expressions in topological order
47 (name "bar"))
48 (package
49 (name "foo")
50 (inputs `(("bar" ,bar)))))
51 (recursive-import "foo" 'repo
52 #:repo->guix-package
53 (match-lambda*
54 (("foo" 'repo)
55 (values '(package
56 (name "foo")
57 (inputs `(("bar" ,bar))))
58 '("bar")))
59 (("bar" 'repo)
60 (values '(package
61 (name "bar"))
62 '())))
63 #:guix-name identity))
64
65 (test-assert "alist->package with simple source"
66 (let* ((meta '(("name" . "hello")
67 ("version" . "2.10")
68 ("source" .
69 ;; Use a 'file://' URI so that we don't cause a download.
70 ,(string-append "file://"
71 (search-path %load-path "guix.scm")))
72 ("build-system" . "gnu")
73 ("home-page" . "https://gnu.org")
74 ("synopsis" . "Say hi")
75 ("description" . "This package says hi.")
76 ("license" . "GPL-3.0+")))
77 (pkg (alist->package meta)))
78 (and (package? pkg)
79 (license:license? (package-license pkg))
80 (build-system? (package-build-system pkg))
81 (origin? (package-source pkg)))))
82
83 (test-assert "alist->package with explicit source"
84 (let* ((meta '(("name" . "hello")
85 ("version" . "2.10")
86 ("source" . (("method" . "url-fetch")
87 ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
88 ("sha256" .
89 (("base32" .
90 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
91 ("build-system" . "gnu")
92 ("home-page" . "https://gnu.org")
93 ("synopsis" . "Say hi")
94 ("description" . "This package says hi.")
95 ("license" . "GPL-3.0+")))
96 (pkg (alist->package meta)))
97 (and (package? pkg)
98 (license:license? (package-license pkg))
99 (build-system? (package-build-system pkg))
100 (origin? (package-source pkg))
101 (equal? (origin-sha256 (package-source pkg))
102 (base32 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
103
104 (test-equal "alist->package with false license" ;<https://bugs.gnu.org/30470>
105 'license-is-false
106 (let* ((meta '(("name" . "hello")
107 ("version" . "2.10")
108 ("source" . (("method" . "url-fetch")
109 ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
110 ("sha256" .
111 (("base32" .
112 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
113 ("build-system" . "gnu")
114 ("home-page" . "https://gnu.org")
115 ("synopsis" . "Say hi")
116 ("description" . "This package says hi.")
117 ("license" . #f))))
118 ;; Note: Use 'or' because comparing with #f otherwise succeeds when
119 ;; there's an exception instead of an actual #f.
120 (or (package-license (alist->package meta))
121 'license-is-false)))
122
123 (test-equal "alist->package with dependencies"
124 `(("gettext" ,(specification->package "gettext")))
125 (let* ((meta '(("name" . "hello")
126 ("version" . "2.10")
127 ("source" . (("method" . "url-fetch")
128 ("uri" . "mirror://gnu/hello/hello-2.10.tar.gz")
129 ("sha256" .
130 (("base32" .
131 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))))
132 ("build-system" . "gnu")
133 ("home-page" . "https://gnu.org")
134 ("synopsis" . "Say hi")
135 ("description" . "This package says hi.")
136 ;
137 ;; Note: As with Guile-JSON 3.x, JSON arrays are represented
138 ;; by vectors.
139 ("native-inputs" . #("gettext"))
140
141 ("license" . #f))))
142 (package-native-inputs (alist->package meta))))
143
144 (test-end "import-utils")