Commit | Line | Data |
---|---|---|
59ee1075 XC |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz | |
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-import-git) | |
20 | #:use-module (git) | |
21 | #:use-module (guix git) | |
22 | #:use-module (guix tests) | |
23 | #:use-module (guix packages) | |
24 | #:use-module (guix import git) | |
25 | #:use-module (guix git-download) | |
26 | #:use-module (guix tests git) | |
27 | #:use-module (guix build utils) | |
28 | #:use-module (srfi srfi-1) | |
29 | #:use-module (srfi srfi-64)) | |
30 | ||
31 | ;; Test the (guix import git) tools. | |
32 | ||
33 | (test-begin "git") | |
34 | ||
35 | (define* (make-package directory version #:optional (properties '())) | |
36 | (dummy-package "test-package" | |
37 | (version version) | |
38 | (properties properties) | |
39 | (source | |
40 | (origin | |
41 | (method git-fetch) | |
42 | (uri (git-reference | |
43 | (url (string-append "file://" directory)) | |
44 | (commit version))) | |
45 | (sha256 | |
46 | (base32 | |
47 | "0000000000000000000000000000000000000000000000000000")))))) | |
48 | ||
49 | (unless (which (git-command)) (test-skip 1)) | |
50 | (test-equal "latest-git-tag-version: no custom prefix, suffix, and delimiter" | |
51 | "1.0.1" | |
52 | (with-temporary-git-repository directory | |
53 | '((add "a.txt" "A") | |
54 | (commit "First commit") | |
55 | (tag "1.0.1" "Release 1.0.1")) | |
56 | (let ((package (make-package directory "1.0.0"))) | |
57 | (latest-git-tag-version package)))) | |
58 | ||
59 | (unless (which (git-command)) (test-skip 1)) | |
60 | (test-equal "latest-git-tag-version: custom prefix, no suffix and delimiter" | |
61 | "1.0.1" | |
62 | (with-temporary-git-repository directory | |
63 | '((add "a.txt" "A") | |
64 | (commit "First commit") | |
65 | (tag "prefix-1.0.1" "Release 1.0.1")) | |
66 | (let ((package (make-package directory "1.0.0" | |
67 | '((release-tag-prefix . "prefix-"))))) | |
68 | (latest-git-tag-version package)))) | |
69 | ||
70 | (unless (which (git-command)) (test-skip 1)) | |
71 | (test-equal "latest-git-tag-version: custom suffix, no prefix and delimiter" | |
72 | "1.0.1" | |
73 | (with-temporary-git-repository directory | |
74 | '((add "a.txt" "A") | |
75 | (commit "First commit") | |
76 | (tag "1.0.1-suffix-123" "Release 1.0.1")) | |
77 | (let ((package (make-package directory "1.0.0" | |
78 | '((release-tag-suffix . "-suffix-[0-9]*"))))) | |
79 | (latest-git-tag-version package)))) | |
80 | ||
81 | (unless (which (git-command)) (test-skip 1)) | |
82 | (test-equal "latest-git-tag-version: custom delimiter, no prefix and suffix" | |
83 | "2021.09.07" | |
84 | (with-temporary-git-repository directory | |
85 | '((add "a.txt" "A") | |
86 | (commit "First commit") | |
87 | (tag "2021-09-07" "Release 2021-09-07")) | |
88 | (let ((package (make-package directory "2021-09-06" | |
89 | '((release-tag-version-delimiter . "-"))))) | |
90 | (latest-git-tag-version package)))) | |
91 | ||
92 | (unless (which (git-command)) (test-skip 1)) | |
93 | (test-equal "latest-git-tag-version: empty delimiter, no prefix and suffix" | |
94 | "20210907" | |
95 | (with-temporary-git-repository directory | |
96 | '((add "a.txt" "A") | |
97 | (commit "First commit") | |
98 | (tag "20210907" "Release 20210907")) | |
99 | (let ((package (make-package directory "20210906" | |
100 | '((release-tag-version-delimiter . ""))))) | |
101 | (latest-git-tag-version package)))) | |
102 | ||
103 | (unless (which (git-command)) (test-skip 1)) | |
104 | (test-equal "latest-git-tag-version: custom prefix and suffix, no delimiter" | |
105 | "2.0.0" | |
106 | (with-temporary-git-repository directory | |
107 | '((add "a.txt" "A") | |
108 | (commit "First commit") | |
109 | (tag "Release-2.0.0suffix-1" "Release 2.0.0")) | |
110 | (let ((package (make-package directory "1.0.0" | |
111 | '((release-tag-prefix . "Release-") | |
112 | (release-tag-suffix . "suffix-[0-9]"))))) | |
113 | (latest-git-tag-version package)))) | |
114 | ||
115 | (unless (which (git-command)) (test-skip 1)) | |
116 | (test-equal "latest-git-tag-version: custom prefix, suffix, and delimiter" | |
117 | "2.0.0" | |
118 | (with-temporary-git-repository directory | |
119 | '((add "a.txt" "A") | |
120 | (commit "First commit") | |
121 | (tag "Release-2_0_0suffix-1" "Release 2.0.0")) | |
122 | (let ((package (make-package directory "1.0.0" | |
123 | '((release-tag-prefix . "Release-") | |
124 | (release-tag-suffix . "suffix-[0-9]") | |
125 | (release-tag-version-delimiter . "_"))))) | |
126 | (latest-git-tag-version package)))) | |
127 | ||
128 | (unless (which (git-command)) (test-skip 1)) | |
129 | (test-equal "latest-git-tag-version: only pre-releases available" | |
130 | #f | |
131 | (with-temporary-git-repository directory | |
132 | '((add "a.txt" "A") | |
133 | (commit "First commit") | |
134 | (tag "2.0.0-rc1" "Release candidate for 2.0.0")) | |
135 | (let ((package (make-package directory "1.0.0"))) | |
136 | (latest-git-tag-version package)))) | |
137 | ||
138 | (unless (which (git-command)) (test-skip 1)) | |
139 | (test-equal "latest-git-tag-version: accept pre-releases" | |
140 | "2.0.0-rc1" | |
141 | (with-temporary-git-repository directory | |
142 | '((add "a.txt" "A") | |
143 | (commit "First commit") | |
144 | (tag "2.0.0-rc1" "Release candidate for 2.0.0")) | |
145 | (let ((package (make-package directory "1.0.0" | |
146 | '((accept-pre-releases? . #t))))) | |
147 | (latest-git-tag-version package)))) | |
148 | ||
149 | (unless (which (git-command)) (test-skip 1)) | |
150 | (test-equal "latest-git-tag-version: accept pre-releases, and custom prefix" | |
151 | "2.0.0-rc1" | |
152 | (with-temporary-git-repository directory | |
153 | '((add "a.txt" "A") | |
154 | (commit "First commit") | |
155 | (tag "version-2.0.0-rc1" "Release candidate for 2.0.0")) | |
156 | (let ((package (make-package directory "1.0.0" | |
157 | '((accept-pre-releases? . #t) | |
158 | (release-tag-prefix . "version-"))))) | |
159 | (latest-git-tag-version package)))) | |
160 | ||
161 | (unless (which (git-command)) (test-skip 1)) | |
162 | (test-equal "latest-git-tag-version: accept pre-releases, and custom suffix" | |
163 | "2.0.0-rc1" | |
164 | (with-temporary-git-repository directory | |
165 | '((add "a.txt" "A") | |
166 | (commit "First commit") | |
167 | (tag "2.0.0-rc1-suffix" "Release candidate for 2.0.0")) | |
168 | (let ((package (make-package directory "1.0.0" | |
169 | '((accept-pre-releases? . #t) | |
170 | (release-tag-suffix . "-suffix"))))) | |
171 | (latest-git-tag-version package)))) | |
172 | ||
173 | (unless (which (git-command)) (test-skip 1)) | |
174 | (test-equal "latest-git-tag-version: accept pre-releases, delimiter conflicts with pre-release part" | |
175 | "2.0.0_alpha" | |
176 | (with-temporary-git-repository directory | |
177 | '((add "a.txt" "A") | |
178 | (commit "First commit") | |
179 | (tag "2_0_0_alpha" "Alpha release for 2.0.0")) | |
180 | (let ((package (make-package directory "1.0.0" | |
181 | '((accept-pre-releases? . #t) | |
182 | (release-tag-version-delimiter . "_"))))) | |
183 | (latest-git-tag-version package)))) | |
184 | ||
185 | (unless (which (git-command)) (test-skip 1)) | |
186 | (test-equal "latest-git-tag-version: accept pre-releases, and custom suffix and prefix" | |
187 | "2.0.0-alpha" | |
188 | (with-temporary-git-repository directory | |
189 | '((add "a.txt" "A") | |
190 | (commit "First commit") | |
191 | (tag "prefix123-2.0.0-alpha-suffix" "Alpha release for 2.0.0")) | |
192 | (let ((package (make-package directory "1.0.0" | |
193 | '((accept-pre-releases? . #t) | |
194 | (release-tag-prefix . "prefix[0-9]{3}-") | |
195 | (release-tag-suffix . "-suffix"))))) | |
196 | (latest-git-tag-version package)))) | |
197 | ||
198 | (unless (which (git-command)) (test-skip 1)) | |
199 | (test-equal "latest-git-tag-version: accept pre-releases, and custom suffix, prefix, and delimiter" | |
200 | "2.0.0-alpha" | |
201 | (with-temporary-git-repository directory | |
202 | '((add "a.txt" "A") | |
203 | (commit "First commit") | |
204 | (tag "prefix123-2-0-0-alpha-suffix" "Alpha release for 2.0.0")) | |
205 | (let ((package (make-package directory "1.0.0" | |
206 | '((accept-pre-releases? . #t) | |
207 | (release-tag-prefix . "prefix[0-9]{3}-") | |
208 | (release-tag-suffix . "-suffix") | |
209 | (release-tag-version-delimiter . "-"))))) | |
210 | (latest-git-tag-version package)))) | |
211 | ||
212 | (unless (which (git-command)) (test-skip 1)) | |
213 | (test-equal "latest-git-tag-version: accept pre-releases, no delimiter, and custom suffix, prefix" | |
214 | "2alpha" | |
215 | (with-temporary-git-repository directory | |
216 | '((add "a.txt" "A") | |
217 | (commit "First commit") | |
218 | (tag "prefix123-2alpha-suffix" "Alpha release for version 2")) | |
219 | (let ((package (make-package directory "1.0.0" | |
220 | '((accept-pre-releases? . #t) | |
221 | (release-tag-prefix . "prefix[0-9]{3}-") | |
222 | (release-tag-suffix . "-suffix") | |
223 | (release-tag-version-delimiter . ""))))) | |
224 | (latest-git-tag-version package)))) | |
225 | ||
226 | (unless (which (git-command)) (test-skip 1)) | |
227 | (test-equal "latest-git-tag-version: no tags found" | |
228 | #f | |
229 | (with-temporary-git-repository directory | |
230 | '((add "a.txt" "A") | |
231 | (commit "First commit")) | |
232 | (let ((package (make-package directory "1.0.0"))) | |
233 | (latest-git-tag-version package)))) | |
234 | ||
235 | (unless (which (git-command)) (test-skip 1)) | |
236 | (test-equal "latest-git-tag-version: no valid tags found" | |
237 | #f | |
238 | (with-temporary-git-repository directory | |
239 | '((add "a.txt" "A") | |
240 | (commit "First commit") | |
241 | (tag "Test" "Test tag")) | |
242 | (let ((package (make-package directory "1.0.0"))) | |
243 | (latest-git-tag-version package)))) | |
244 | ||
245 | (test-end "git") |