1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2016, 2017 Ludovic Courtès <ludo@gnu.org>
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-scripts-build)
20 #:use-module (guix tests)
21 #:use-module (guix store)
22 #:use-module (guix packages)
23 #:use-module (guix scripts build)
24 #:use-module (guix ui)
25 #:use-module (guix utils)
26 #:use-module (gnu packages)
27 #:use-module (gnu packages base)
28 #:use-module (gnu packages busybox)
29 #:use-module (ice-9 match)
30 #:use-module (srfi srfi-64))
33 (test-begin "scripts-build")
35 (test-assert "options->transformation, no transformations"
36 (let ((p (dummy-package "foo"))
37 (t (options->transformation '())))
39 (eq? (t store p) p))))
41 (test-assert "options->transformation, with-source"
42 ;; Our pseudo-package is called 'guix.scm' so the 'guix.scm' source should
44 (let* ((p (dummy-package "guix.scm"))
45 (s (search-path %load-path "guix.scm"))
46 (t (options->transformation `((with-source . ,s)))))
48 (let ((new (t store p)))
49 (and (not (eq? new p))
50 (string=? (package-source new)
51 (add-to-store store "guix.scm" #t
54 (test-assert "options->transformation, with-source, replacement"
55 ;; Same, but this time the original package has a 'replacement' field. We
56 ;; expect that replacement to be set to #f in the new package.
57 (let* ((p (dummy-package "guix.scm" (replacement coreutils)))
58 (s (search-path %load-path "guix.scm"))
59 (t (options->transformation `((with-source . ,s)))))
61 (let ((new (t store p)))
62 (and (not (eq? new p))
63 (string=? (package-source new)
64 (add-to-store store "guix.scm" #t "sha256" s))
65 (not (package-replacement new)))))))
67 (test-assert "options->transformation, with-source, with version"
68 ;; Our pseudo-package is called 'guix.scm' so the 'guix.scm-2.0' source
69 ;; should be applicable, and its version should be extracted.
70 (let ((p (dummy-package "foo"))
71 (s (search-path %load-path "guix.scm")))
72 (call-with-temporary-directory
74 (let* ((f (string-append directory "/foo-42.0.tar.gz"))
75 (t (options->transformation `((with-source . ,f)))))
78 (let ((new (t store p)))
79 (and (not (eq? new p))
80 (string=? (package-name new) (package-name p))
81 (string=? (package-version new) "42.0")
82 (string=? (package-source new)
83 (add-to-store store (basename f) #t
86 (test-assert "options->transformation, with-source, no matches"
87 ;; When a transformation in not applicable, a warning must be raised.
88 (let* ((p (dummy-package "foobar"))
89 (s (search-path %load-path "guix.scm"))
90 (t (options->transformation `((with-source . ,s)))))
92 (let* ((port (open-output-string))
93 (new (parameterize ((guix-warning-port port))
96 (string-contains (get-output-string port)
99 (test-assert "options->transformation, with-input"
100 (let* ((p (dummy-package "guix.scm"
101 (inputs `(("foo" ,(specification->package "coreutils"))
102 ("bar" ,(specification->package "grep"))
103 ("baz" ,(dummy-package "chbouib"
104 (native-inputs `(("x" ,grep)))))))))
105 (t (options->transformation '((with-input . "coreutils=busybox")
106 (with-input . "grep=findutils")))))
108 (let ((new (t store p)))
109 (and (not (eq? new p))
110 (match (package-inputs new)
111 ((("foo" dep1) ("bar" dep2) ("baz" dep3))
112 (and (eq? dep1 busybox)
114 (string=? (package-name dep3) "chbouib")
115 (match (package-native-inputs dep3)
117 (eq? dep findutils)))))))))))
119 (test-assert "options->transformation, with-graft"
120 (let* ((p (dummy-package "guix.scm"
121 (inputs `(("foo" ,grep)
122 ("bar" ,(dummy-package "chbouib"
123 (native-inputs `(("x" ,grep)))))))))
124 (t (options->transformation '((with-graft . "grep=findutils")))))
126 (let ((new (t store p)))
127 (and (not (eq? new p))
128 (match (package-inputs new)
129 ((("foo" dep1) ("bar" dep2))
130 (and (string=? (package-full-name dep1)
131 (package-full-name grep))
132 (eq? (package-replacement dep1) findutils)
133 (string=? (package-name dep2) "chbouib")
134 (match (package-native-inputs dep2)
136 (eq? (package-replacement dep) findutils)))))))))))