summary refs log tree commit diff
path: root/tests/upstream.scm
blob: 9aacb77229ab882f479d2af36bb924968a167a0e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2016 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2022 Ricardo Wurmus <rekado@elephly.net>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (test-upstream)
  #:use-module (gnu packages base)
  #:use-module (guix download)
  #:use-module (guix packages)
  #:use-module (guix build-system gnu)
  #:use-module (guix import print)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix upstream)
  #:use-module (guix tests)
  #:use-module (srfi srfi-64)
  #:use-module (ice-9 match))


(test-begin "upstream")

;; FIXME: Temporarily skipping this test; see <https://bugs.gnu.org/34229>.
(test-skip 1)

(test-equal "coalesce-sources same version"
  (list (upstream-source
         (package "foo") (version "1")
         (urls '("ftp://example.org/foo-1.tar.xz"
                 "ftp://example.org/foo-1.tar.gz"))
         (signature-urls '("ftp://example.org/foo-1.tar.xz.sig"
                           "ftp://example.org/foo-1.tar.gz.sig"))))

  (coalesce-sources (list (upstream-source
                           (package "foo") (version "1")
                           (urls '("ftp://example.org/foo-1.tar.gz"))
                           (signature-urls
                            '("ftp://example.org/foo-1.tar.gz.sig")))
                          (upstream-source
                           (package "foo") (version "1")
                           (urls '("ftp://example.org/foo-1.tar.xz"))
                           (signature-urls
                            '("ftp://example.org/foo-1.tar.xz.sig"))))))

(define test-package
  (package
    (name "test")
    (version "2.10")
    (source (origin
              (method url-fetch)
              (uri (string-append "mirror://gnu/hello/hello-" version
                                  ".tar.gz"))
              (sha256
               (base32
                "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
    (build-system gnu-build-system)
    (inputs
     `(("hello" ,hello)))
    (native-inputs
     `(("sed" ,sed)
       ("tar" ,tar)))
    (propagated-inputs
     `(("grep" ,grep)))
    (home-page "http://localhost")
    (synopsis "test")
    (description "test")
    (license license:gpl3+)))

(define test-package-sexp
  '(package
    (name "test")
    (version "2.10")
    (source (origin
              (method url-fetch)
              (uri (string-append "mirror://gnu/hello/hello-" version
                                  ".tar.gz"))
              (sha256
               (base32
                "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
    (build-system gnu-build-system)
    (inputs
     `(("hello" ,hello)))
    (native-inputs
     `(("sed" ,sed)
       ("tar" ,tar)))
    (propagated-inputs
     `(("grep" ,grep)))
    (home-page "http://localhost")
    (synopsis "test")
    (description "test")
    (license license:gpl3+)))

(test-equal "changed-inputs returns no changes"
  '()
  (changed-inputs test-package test-package-sexp))

(test-assert "changed-inputs returns changes to labelled input list"
  (let ((changes (changed-inputs
                  (package
                    (inherit test-package)
                    (inputs `(("hello" ,hello)
                              ("sed" ,sed))))
                  test-package-sexp)))
    (match changes
      ;; Exactly one change
      (((? upstream-input-change? item))
       (and (equal? (upstream-input-change-type item)
                    'regular)
            (equal? (upstream-input-change-action item)
                    'remove)
            (string=? (upstream-input-change-name item)
                      "sed")))
      (else (pk else #false)))))

(test-assert "changed-inputs returns changes to all labelled input lists"
  (let ((changes (changed-inputs
                  (package
                    (inherit test-package)
                    (inputs '())
                    (native-inputs '())
                    (propagated-inputs '()))
                  test-package-sexp)))
    (match changes
      (((? upstream-input-change? items) ...)
       (and (equal? (map upstream-input-change-type items)
                    '(regular native native propagated))
            (equal? (map upstream-input-change-action items)
                    '(add add add add))
            (equal? (map upstream-input-change-name items)
                    '("hello" "sed" "tar" "grep"))))
      (else (pk else #false)))))

(define test-new-package
  (package
    (inherit test-package)
    (inputs
     (list hello))
    (native-inputs
     (list sed tar))
    (propagated-inputs
     (list grep))))

(define test-new-package-sexp
  '(package
    (name "test")
    (version "2.10")
    (source (origin
              (method url-fetch)
              (uri (string-append "mirror://gnu/hello/hello-" version
                                  ".tar.gz"))
              (sha256
               (base32
                "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
    (build-system gnu-build-system)
    (inputs
     (list hello))
    (native-inputs
     (list sed tar))
    (propagated-inputs
     (list grep))
    (home-page "http://localhost")
    (synopsis "test")
    (description "test")
    (license license:gpl3+)))

(test-assert "changed-inputs returns changes to plain input list"
  (let ((changes (changed-inputs
                  (package
                    (inherit test-new-package)
                    (inputs (list hello sed)))
                  test-new-package-sexp)))
    (match changes
      ;; Exactly one change
      (((? upstream-input-change? item))
       (and (equal? (upstream-input-change-type item)
                    'regular)
            (equal? (upstream-input-change-action item)
                    'remove)
            (string=? (upstream-input-change-name item)
                      "sed")))
      (else (pk else #false)))))

(test-assert "changed-inputs returns changes to all plain input lists"
  (let ((changes (changed-inputs
                  (package
                    (inherit test-new-package)
                    (inputs '())
                    (native-inputs '())
                    (propagated-inputs '()))
                  test-new-package-sexp)))
    (match changes
      (((? upstream-input-change? items) ...)
       (and (equal? (map upstream-input-change-type items)
                    '(regular native native propagated))
            (equal? (map upstream-input-change-action items)
                    '(add add add add))
            (equal? (map upstream-input-change-name items)
                    '("hello" "sed" "tar" "grep"))))
      (else (pk else #false)))))

(test-end)