Commit | Line | Data |
---|---|---|
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 | ||
9a2a2005 LC |
53 | (test-assert "options->transformation, with-source, with version" |
54 | ;; Our pseudo-package is called 'guix.scm' so the 'guix.scm-2.0' source | |
55 | ;; should be applicable, and its version should be extracted. | |
56 | (let ((p (dummy-package "foo")) | |
57 | (s (search-path %load-path "guix.scm"))) | |
58 | (call-with-temporary-directory | |
59 | (lambda (directory) | |
60 | (let* ((f (string-append directory "/foo-42.0.tar.gz")) | |
61 | (t (options->transformation `((with-source . ,f))))) | |
62 | (copy-file s f) | |
63 | (with-store store | |
64 | (let ((new (t store p))) | |
65 | (and (not (eq? new p)) | |
66 | (string=? (package-name new) (package-name p)) | |
67 | (string=? (package-version new) "42.0") | |
68 | (string=? (package-source new) | |
69 | (add-to-store store (basename f) #t | |
70 | "sha256" f)))))))))) | |
71 | ||
629a064f LC |
72 | (test-assert "options->transformation, with-source, no matches" |
73 | ;; When a transformation in not applicable, a warning must be raised. | |
74 | (let* ((p (dummy-package "foobar")) | |
75 | (s (search-path %load-path "guix.scm")) | |
76 | (t (options->transformation `((with-source . ,s))))) | |
77 | (with-store store | |
78 | (let* ((port (open-output-string)) | |
79 | (new (parameterize ((guix-warning-port port)) | |
80 | (t store p)))) | |
81 | (and (eq? new p) | |
82 | (string-contains (get-output-string port) | |
83 | "had no effect")))))) | |
84 | ||
47c0f92c LC |
85 | (test-assert "options->transformation, with-input" |
86 | (let* ((p (dummy-package "guix.scm" | |
87 | (inputs `(("foo" ,coreutils) | |
88 | ("bar" ,grep) | |
89 | ("baz" ,(dummy-package "chbouib" | |
90 | (native-inputs `(("x" ,grep))))))))) | |
91 | (t (options->transformation '((with-input . "coreutils=busybox") | |
92 | (with-input . "grep=findutils"))))) | |
93 | (with-store store | |
94 | (let ((new (t store p))) | |
95 | (and (not (eq? new p)) | |
96 | (match (package-inputs new) | |
97 | ((("foo" dep1) ("bar" dep2) ("baz" dep3)) | |
98 | (and (eq? dep1 busybox) | |
99 | (eq? dep2 findutils) | |
100 | (string=? (package-name dep3) "chbouib") | |
101 | (match (package-native-inputs dep3) | |
102 | ((("x" dep)) | |
103 | (eq? dep findutils))))))))))) | |
104 | ||
629a064f | 105 | (test-end) |