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 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))
27 (test-begin "channels")
29 (define* (make-instance #:key
33 (define instance-dir (mkdtemp! "/tmp/checkout.XXXXXX"))
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))
40 (define instance--boring (make-instance))
41 (define instance--no-deps
48 (url "https://example.com/test-channel"))))))
49 (define instance--simple
56 (url "https://example.com/test-channel"))))))
57 (define instance--with-dupes
64 (url "https://example.com/test-channel"))
67 (url "https://example.com/test-channel")
71 (url "https://example.com/test-channel-elsewhere"))))))
73 (define read-channel-metadata
74 (@@ (guix channels) read-channel-metadata))
77 (test-equal "read-channel-metadata returns #f if .guix-channel does not exist"
79 (read-channel-metadata instance--boring))
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
86 instance--with-dupes))))
88 (test-assert "read-channel-metadata dependencies are channels"
89 (let ((deps ((@@ (guix channels) channel-metadata-dependencies)
90 (read-channel-metadata instance--simple))))
92 (((? channel? dep)) #t)
95 (test-assert "latest-channel-instances includes channel dependencies"
96 (let* ((channel (channel
99 (test-dir (channel-instance-checkout instance--simple)))
100 (mock ((guix git) latest-repository-commit
101 (lambda* (store url #:key ref)
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))
109 (map (compose channel-name channel-instance-channel)
112 (test-assert "latest-channel-instances excludes duplicate channel dependencies"
113 (let* ((channel (channel
116 (test-dir (channel-instance-checkout instance--with-dupes)))
117 (mock ((guix git) latest-repository-commit
118 (lambda* (store url #:key ref)
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))
126 (map (compose channel-name channel-instance-channel)
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))
135 (channel-instance-channel instance))
139 (test-end "channels")