1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
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-channels)
20 #:use-module (guix channels)
21 #:use-module (guix profiles)
22 #:use-module ((guix build syscalls) #:select (mkdtemp!))
23 #:use-module (guix tests)
24 #:use-module (guix store)
25 #:use-module ((guix grafts) #:select (%graft?))
26 #:use-module (guix derivations)
27 #:use-module (guix sets)
28 #:use-module (guix gexp)
29 #:use-module ((guix utils)
30 #:select (error-location? error-location location-line))
31 #:use-module (srfi srfi-1)
32 #:use-module (srfi srfi-26)
33 #:use-module (srfi srfi-34)
34 #:use-module (srfi srfi-35)
35 #:use-module (srfi srfi-64)
36 #:use-module (ice-9 match))
38 (test-begin "channels")
40 (define* (make-instance #:key
44 (define instance-dir (mkdtemp! "/tmp/checkout.XXXXXX"))
46 (with-output-to-file (string-append instance-dir "/.guix-channel")
47 (lambda _ (format #t "~a" spec))))
48 (checkout->channel-instance instance-dir
52 (define instance--boring (make-instance))
53 (define instance--unsupported-version
55 '(channel (version 42) (dependencies whatever))))
56 (define instance--no-deps
63 (url "https://example.com/test-channel"))))))
64 (define instance--simple
71 (url "https://example.com/test-channel"))))))
72 (define instance--with-dupes
79 (url "https://example.com/test-channel"))
82 (url "https://example.com/test-channel")
86 (url "https://example.com/test-channel-elsewhere"))))))
88 (define channel-instance-metadata
89 (@@ (guix channels) channel-instance-metadata))
92 (test-equal "channel-instance-metadata returns #f if .guix-channel does not exist"
94 (channel-instance-metadata instance--boring))
96 (test-equal "channel-instance-metadata rejects unsupported version"
97 1 ;line number in the generated '.guix-channel'
98 (guard (c ((and (message-condition? c) (error-location? c))
99 (location-line (error-location c))))
100 (channel-instance-metadata instance--unsupported-version)))
102 (test-assert "channel-instance-metadata returns <channel-metadata>"
103 (every (@@ (guix channels) channel-metadata?)
104 (map channel-instance-metadata
105 (list instance--no-deps
107 instance--with-dupes))))
109 (test-assert "channel-instance-metadata dependencies are channels"
110 (let ((deps ((@@ (guix channels) channel-metadata-dependencies)
111 (channel-instance-metadata instance--simple))))
113 (((? channel? dep)) #t)
116 (test-assert "latest-channel-instances includes channel dependencies"
117 (let* ((channel (channel
120 (test-dir (channel-instance-checkout instance--simple)))
121 (mock ((guix git) latest-repository-commit
122 (lambda* (store url #:key ref)
124 ("test" (values test-dir 'whatever))
125 (_ (values "/not-important" 'not-important)))))
126 (let ((instances (latest-channel-instances #f (list channel))))
127 (and (eq? 2 (length instances))
130 (map (compose channel-name channel-instance-channel)
133 (test-assert "latest-channel-instances excludes duplicate channel dependencies"
134 (let* ((channel (channel
137 (test-dir (channel-instance-checkout instance--with-dupes)))
138 (mock ((guix git) latest-repository-commit
139 (lambda* (store url #:key ref)
141 ("test" (values test-dir 'whatever))
142 (_ (values "/not-important" 'not-important)))))
143 (let ((instances (latest-channel-instances #f (list channel))))
144 (and (eq? 2 (length instances))
147 (map (compose channel-name channel-instance-channel)
149 ;; only the most specific channel dependency should remain,
150 ;; i.e. the one with a specified commit.
151 (find (lambda (instance)
152 (and (eq? (channel-name
153 (channel-instance-channel instance))
156 (channel-instance-channel instance))
160 (test-assert "channel-instances->manifest"
161 ;; Compute the manifest for a graph of instances and make sure we get a
162 ;; derivation graph that mirrors the instance graph. This test also ensures
163 ;; we don't try to access Git repositores at all at this stage.
164 (let* ((spec (lambda deps
165 `(channel (version 0)
170 (url "http://example.org")))
172 (guix (make-instance #:name 'guix))
173 (instance0 (make-instance #:name 'a))
174 (instance1 (make-instance #:name 'b #:spec (spec 'a)))
175 (instance2 (make-instance #:name 'c #:spec (spec 'b)))
176 (instance3 (make-instance #:name 'd #:spec (spec 'c 'a))))
177 (%graft? #f) ;don't try to build stuff
179 ;; Create 'build-self.scm' so that GUIX is recognized as the 'guix' channel.
180 (let ((source (channel-instance-checkout guix)))
181 (mkdir (string-append source "/build-aux"))
182 (call-with-output-file (string-append source
183 "/build-aux/build-self.scm")
186 (use-modules (guix) (gnu packages bootstrap))
189 (package->derivation %bootstrap-guile)))
195 (run-with-store store
196 (channel-instances->manifest (list guix
198 instance2 instance3))))
201 (manifest-entries manifest))
203 (define (depends? drv in out)
204 ;; Return true if DRV depends (directly or indirectly) on all of IN
206 (let ((set (list->set
208 (list (derivation-file-name drv)))))
209 (in (map derivation-file-name in))
210 (out (map derivation-file-name out)))
211 (and (every (cut set-contains? set <>) in)
212 (not (any (cut set-contains? set <>) out)))))
214 (define (lookup name)
215 (run-with-store store
218 (manifest-lookup manifest
219 (manifest-pattern (name name)))))))
221 (let ((drv-guix (lookup "guix"))
226 (and (depends? drv-guix '() (list drv0 drv1 drv2 drv3))
228 (list) (list drv1 drv2 drv3))
230 (list drv0) (list drv2 drv3))
232 (list drv1) (list drv3))
234 (list drv2 drv0) (list))))))))
236 (test-end "channels")