guix: Add support for channel dependencies.
[jackhill/guix/guix.git] / tests / channels.scm
CommitLineData
af12790b
RW
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
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-channels)
20 #:use-module (guix channels)
21 #:use-module ((guix build syscalls) #:select (mkdtemp!))
22 #:use-module (guix tests)
23 #:use-module (srfi srfi-1)
24 #:use-module (srfi srfi-64)
25 #:use-module (ice-9 match))
26
27(test-begin "channels")
28
29(define* (make-instance #:key
30 (name 'fake)
31 (commit "cafebabe")
32 (spec #f))
33 (define instance-dir (mkdtemp! "/tmp/checkout.XXXXXX"))
34 (and spec
35 (with-output-to-file (string-append instance-dir "/.guix-channel")
36 (lambda _ (format #t "~a" spec))))
37 ((@@ (guix channels) channel-instance)
38 name commit instance-dir))
39
40(define instance--boring (make-instance))
41(define instance--no-deps
42 (make-instance #:spec
43 '(channel
44 (version 0)
45 (dependencies
46 (channel
47 (name test-channel)
48 (url "https://example.com/test-channel"))))))
49(define instance--simple
50 (make-instance #:spec
51 '(channel
52 (version 0)
53 (dependencies
54 (channel
55 (name test-channel)
56 (url "https://example.com/test-channel"))))))
57(define instance--with-dupes
58 (make-instance #:spec
59 '(channel
60 (version 0)
61 (dependencies
62 (channel
63 (name test-channel)
64 (url "https://example.com/test-channel"))
65 (channel
66 (name test-channel)
67 (url "https://example.com/test-channel")
68 (commit "abc1234"))
69 (channel
70 (name test-channel)
71 (url "https://example.com/test-channel-elsewhere"))))))
72
73(define read-channel-metadata
74 (@@ (guix channels) read-channel-metadata))
75
76\f
77(test-equal "read-channel-metadata returns #f if .guix-channel does not exist"
78 #f
79 (read-channel-metadata instance--boring))
80
81(test-assert "read-channel-metadata returns <channel-metadata>"
82 (every (@@ (guix channels) channel-metadata?)
83 (map read-channel-metadata
84 (list instance--no-deps
85 instance--simple
86 instance--with-dupes))))
87
88(test-assert "read-channel-metadata dependencies are channels"
89 (let ((deps ((@@ (guix channels) channel-metadata-dependencies)
90 (read-channel-metadata instance--simple))))
91 (match deps
92 (((? channel? dep)) #t)
93 (_ #f))))
94
95(test-assert "latest-channel-instances includes channel dependencies"
96 (let* ((channel (channel
97 (name 'test)
98 (url "test")))
99 (test-dir (channel-instance-checkout instance--simple)))
100 (mock ((guix git) latest-repository-commit
101 (lambda* (store url #:key ref)
102 (match url
103 ("test" (values test-dir 'whatever))
104 (_ (values "/not-important" 'not-important)))))
105 (let ((instances (latest-channel-instances #f (list channel))))
106 (and (eq? 2 (length instances))
107 (lset= eq?
108 '(test test-channel)
109 (map (compose channel-name channel-instance-channel)
110 instances)))))))
111
112(test-assert "latest-channel-instances excludes duplicate channel dependencies"
113 (let* ((channel (channel
114 (name 'test)
115 (url "test")))
116 (test-dir (channel-instance-checkout instance--with-dupes)))
117 (mock ((guix git) latest-repository-commit
118 (lambda* (store url #:key ref)
119 (match url
120 ("test" (values test-dir 'whatever))
121 (_ (values "/not-important" 'not-important)))))
122 (let ((instances (latest-channel-instances #f (list channel))))
123 (and (eq? 2 (length instances))
124 (lset= eq?
125 '(test test-channel)
126 (map (compose channel-name channel-instance-channel)
127 instances))
128 ;; only the most specific channel dependency should remain,
129 ;; i.e. the one with a specified commit.
130 (find (lambda (instance)
131 (and (eq? (channel-name
132 (channel-instance-channel instance))
133 'test-channel)
134 (eq? (channel-commit
135 (channel-instance-channel instance))
136 'abc1234)))
137 instances))))))
138
139(test-end "channels")