derivations: Restore UTF-8 encoding of build scripts.
[jackhill/guix/guix.git] / tests / scripts-build.scm
CommitLineData
629a064f
LC
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2016 Ludovic Courtès <ludo@gnu.org>
3;;;
4;;; This file is part of GNU Guix.
5;;;
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.
10;;;
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.
15;;;
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/>.
18
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)
9a2a2005 25 #:use-module (guix utils)
47c0f92c
LC
26 #:use-module (gnu packages base)
27 #:use-module (gnu packages busybox)
28 #:use-module (ice-9 match)
629a064f
LC
29 #:use-module (srfi srfi-64))
30
31\f
32(test-begin "scripts-build")
33
34(test-assert "options->transformation, no transformations"
35 (let ((p (dummy-package "foo"))
36 (t (options->transformation '())))
37 (with-store store
38 (eq? (t store p) p))))
39
40(test-assert "options->transformation, with-source"
41 ;; Our pseudo-package is called 'guix.scm' so the 'guix.scm' source should
42 ;; be applicable.
43 (let* ((p (dummy-package "guix.scm"))
44 (s (search-path %load-path "guix.scm"))
45 (t (options->transformation `((with-source . ,s)))))
46 (with-store store
47 (let ((new (t store p)))
48 (and (not (eq? new p))
49 (string=? (package-source new)
50 (add-to-store store "guix.scm" #t
51 "sha256" s)))))))
52
7c247809
LC
53(test-assert "options->transformation, with-source, replacement"
54 ;; Same, but this time the original package has a 'replacement' field. We
55 ;; expect that replacement to be set to #f in the new package.
56 (let* ((p (dummy-package "guix.scm" (replacement coreutils)))
57 (s (search-path %load-path "guix.scm"))
58 (t (options->transformation `((with-source . ,s)))))
59 (with-store store
60 (let ((new (t store p)))
61 (and (not (eq? new p))
62 (string=? (package-source new)
63 (add-to-store store "guix.scm" #t "sha256" s))
64 (not (package-replacement new)))))))
65
9a2a2005
LC
66(test-assert "options->transformation, with-source, with version"
67 ;; Our pseudo-package is called 'guix.scm' so the 'guix.scm-2.0' source
68 ;; should be applicable, and its version should be extracted.
69 (let ((p (dummy-package "foo"))
70 (s (search-path %load-path "guix.scm")))
71 (call-with-temporary-directory
72 (lambda (directory)
73 (let* ((f (string-append directory "/foo-42.0.tar.gz"))
74 (t (options->transformation `((with-source . ,f)))))
75 (copy-file s f)
76 (with-store store
77 (let ((new (t store p)))
78 (and (not (eq? new p))
79 (string=? (package-name new) (package-name p))
80 (string=? (package-version new) "42.0")
81 (string=? (package-source new)
82 (add-to-store store (basename f) #t
83 "sha256" f))))))))))
84
629a064f
LC
85(test-assert "options->transformation, with-source, no matches"
86 ;; When a transformation in not applicable, a warning must be raised.
87 (let* ((p (dummy-package "foobar"))
88 (s (search-path %load-path "guix.scm"))
89 (t (options->transformation `((with-source . ,s)))))
90 (with-store store
91 (let* ((port (open-output-string))
92 (new (parameterize ((guix-warning-port port))
93 (t store p))))
94 (and (eq? new p)
95 (string-contains (get-output-string port)
96 "had no effect"))))))
97
47c0f92c
LC
98(test-assert "options->transformation, with-input"
99 (let* ((p (dummy-package "guix.scm"
100 (inputs `(("foo" ,coreutils)
101 ("bar" ,grep)
102 ("baz" ,(dummy-package "chbouib"
103 (native-inputs `(("x" ,grep)))))))))
104 (t (options->transformation '((with-input . "coreutils=busybox")
105 (with-input . "grep=findutils")))))
106 (with-store store
107 (let ((new (t store p)))
108 (and (not (eq? new p))
109 (match (package-inputs new)
110 ((("foo" dep1) ("bar" dep2) ("baz" dep3))
111 (and (eq? dep1 busybox)
112 (eq? dep2 findutils)
113 (string=? (package-name dep3) "chbouib")
114 (match (package-native-inputs dep3)
115 ((("x" dep))
116 (eq? dep findutils)))))))))))
117
645b9df8
LC
118(test-assert "options->transformation, with-graft"
119 (let* ((p (dummy-package "guix.scm"
120 (inputs `(("foo" ,grep)
121 ("bar" ,(dummy-package "chbouib"
122 (native-inputs `(("x" ,grep)))))))))
0d7034ca 123 (t (options->transformation '((with-graft . "grep=findutils")))))
645b9df8
LC
124 (with-store store
125 (let ((new (t store p)))
126 (and (not (eq? new p))
127 (match (package-inputs new)
128 ((("foo" dep1) ("bar" dep2))
129 (and (string=? (package-full-name dep1)
130 (package-full-name grep))
131 (eq? (package-replacement dep1) findutils)
132 (string=? (package-name dep2) "chbouib")
133 (match (package-native-inputs dep2)
134 ((("x" dep))
135 (eq? (package-replacement dep) findutils)))))))))))
136
629a064f 137(test-end)