1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015 Ludovic Courtès <ludo@gnu.org>
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-services)
20 #:use-module (gnu services)
21 #:use-module (gnu services dmd)
22 #:use-module (srfi srfi-1)
23 #:use-module (srfi srfi-26)
24 #:use-module (srfi srfi-34)
25 #:use-module (srfi srfi-64))
27 (test-begin "services")
29 (test-assert "service-back-edges"
30 (let* ((t1 (service-type (name 't1) (extensions '())
31 (compose +) (extend *)))
32 (t2 (service-type (name 't2)
34 (list (service-extension t1 (const '()))))
35 (compose +) (extend *)))
36 (t3 (service-type (name 't3)
38 (list (service-extension t2 identity)
39 (service-extension t1 list)))))
43 (e (service-back-edges (list s1 s2 s3))))
44 (and (lset= eq? (e s1) (list s2 s3))
45 (lset= eq? (e s2) (list s3))
48 (test-equal "fold-services"
49 ;; Make sure 'fold-services' returns the right result. The numbers come
50 ;; from services of type T3; 'xyz 60' comes from the service of type T2,
51 ;; where 60 = 15 × 4 = (1 + 2 + 3 + 4 + 5) × 4.
52 '(initial-value 5 4 3 2 1 xyz 60)
53 (let* ((t1 (service-type (name 't1) (extensions '())
56 (t2 (service-type (name 't2)
58 (list (service-extension t1
60 (compose (cut reduce + 0 <>))
62 (t3 (service-type (name 't3)
64 (list (service-extension t2 identity)
65 (service-extension t1 list)))))
66 (r (fold-services (cons* (service t1 'initial-value)
72 (and (eq? (service-kind r) t1)
73 (service-parameters r))))
75 (test-assert "fold-services, ambiguity"
76 (let* ((t1 (service-type (name 't1) (extensions '())
79 (t2 (service-type (name 't2)
81 (list (service-extension t1 list)))))
83 (guard (c ((ambiguous-target-service-error? c)
84 (and (eq? (ambiguous-target-service-error-target-type c)
86 (eq? (ambiguous-target-service-error-service c)
88 (fold-services (list (service t1 'first)
94 (test-assert "fold-services, missing target"
95 (let* ((t1 (service-type (name 't1) (extensions '())))
96 (t2 (service-type (name 't2)
98 (list (service-extension t1 list)))))
100 (guard (c ((missing-target-service-error? c)
101 (and (eq? (missing-target-service-error-target-type c)
103 (eq? (missing-target-service-error-service c)
105 (fold-services (list s) #:target-type t1)
108 (test-assert "dmd-service-back-edges"
109 (let* ((s1 (dmd-service (provision '(s1)) (start #f)))
110 (s2 (dmd-service (provision '(s2)) (requirement '(s1)) (start #f)))
111 (s3 (dmd-service (provision '(s3)) (requirement '(s1 s2)) (start #f)))
112 (e (dmd-service-back-edges (list s1 s2 s3))))
113 (and (lset= eq? (e s1) (list s2 s3))
114 (lset= eq? (e s2) (list s3))
120 (exit (= (test-runner-fail-count (test-runner-current)) 0))