Commit | Line | Data |
---|---|---|
b4f5e0e8 CR |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2012, 2013 Cyril Roelandt <tipecaml@gmail.com> | |
83f18e06 | 3 | ;;; Copyright © 2014, 2015, 2016 Eric Bavier <bavier@member.fsf.org> |
7d873f19 | 4 | ;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org> |
052d53df | 5 | ;;; Copyright © 2015, 2016 Mathieu Lirzin <mthl@gnu.org> |
891a843d | 6 | ;;; Copyright © 2016 Hartmut Goebel <h.goebel@crazy-compilers.com> |
689db38e | 7 | ;;; Copyright © 2017 Alex Kost <alezost@gmail.com> |
f4007b25 | 8 | ;;; Copyright © 2017 Efraim Flashner <efraim@flashner.co.il> |
40fa21c2 | 9 | ;;; Copyright © 2018, 2019 Arun Isaac <arunisaac@systemreboot.net> |
464b1fff | 10 | ;;; Copyright © 2020 Timothy Sample <samplet@ngyro.com> |
eac82c0e | 11 | ;;; Copyright © 2020 Tobias Geerinckx-Rice <me@tobias.gr> |
c68070e4 | 12 | ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz> |
5532371a | 13 | ;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be> |
b4f5e0e8 CR |
14 | ;;; |
15 | ;;; This file is part of GNU Guix. | |
16 | ;;; | |
17 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | |
18 | ;;; under the terms of the GNU General Public License as published by | |
19 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
20 | ;;; your option) any later version. | |
21 | ;;; | |
22 | ;;; GNU Guix is distributed in the hope that it will be useful, but | |
23 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
24 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25 | ;;; GNU General Public License for more details. | |
26 | ;;; | |
27 | ;;; You should have received a copy of the GNU General Public License | |
28 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | |
29 | ||
c74f0cb2 LC |
30 | ;; Avoid interference. |
31 | (unsetenv "http_proxy") | |
32 | ||
4e7b6b48 | 33 | (define-module (test-lint) |
8b385969 | 34 | #:use-module (guix tests) |
17ab08bc | 35 | #:use-module (guix tests http) |
754e5be2 | 36 | #:use-module (guix download) |
50f5c46d | 37 | #:use-module (guix git-download) |
b4f5e0e8 CR |
38 | #:use-module (guix build-system gnu) |
39 | #:use-module (guix packages) | |
f363c836 | 40 | #:use-module (guix lint) |
b4f5e0e8 | 41 | #:use-module (guix ui) |
55549c7b | 42 | #:use-module (guix swh) |
5532371a | 43 | #:use-module ((guix gexp) #:select (gexp local-file gexp?)) |
4f156c25 | 44 | #:use-module ((guix utils) #:select (call-with-temporary-directory)) |
464b1fff TS |
45 | #:use-module ((guix import hackage) #:select (%hackage-url)) |
46 | #:use-module ((guix import stackage) #:select (%stackage-url)) | |
b4f5e0e8 | 47 | #:use-module (gnu packages) |
99fe215c | 48 | #:use-module (gnu packages glib) |
b4f5e0e8 | 49 | #:use-module (gnu packages pkg-config) |
3b98522b | 50 | #:use-module (gnu packages python-xyz) |
eac82c0e | 51 | #:use-module ((gnu packages bash) #:select (bash bash-minimal)) |
61f28fe7 | 52 | #:use-module (web uri) |
907c98ac LC |
53 | #:use-module (web server) |
54 | #:use-module (web server http) | |
55 | #:use-module (web response) | |
9bee2bd1 | 56 | #:use-module (ice-9 match) |
50fc2384 CB |
57 | #:use-module (ice-9 regex) |
58 | #:use-module (ice-9 getopt-long) | |
59 | #:use-module (ice-9 pretty-print) | |
55549c7b | 60 | #:use-module (rnrs bytevectors) |
50fc2384 | 61 | #:use-module (srfi srfi-1) |
907c98ac | 62 | #:use-module (srfi srfi-9 gnu) |
50fc2384 | 63 | #:use-module (srfi srfi-26) |
b4f5e0e8 CR |
64 | #:use-module (srfi srfi-64)) |
65 | ||
66 | ;; Test the linter. | |
67 | ||
950d2ea4 LC |
68 | (define %null-sha256 |
69 | ;; SHA256 of the empty string. | |
70 | (base32 | |
71 | "0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73")) | |
72 | ||
bfcb3d76 LC |
73 | (define %long-string |
74 | (make-string 2000 #\a)) | |
907c98ac | 75 | |
50fc2384 CB |
76 | (define (string-match-or-error pattern str) |
77 | (or (string-match pattern str) | |
78 | (error str "did not match" pattern))) | |
79 | ||
80 | (define single-lint-warning-message | |
81 | (match-lambda | |
82 | (((and (? lint-warning?) warning)) | |
83 | (lint-warning-message warning)))) | |
84 | ||
37592014 LC |
85 | (define (warning-contains? str warnings) |
86 | "Return true if WARNINGS is a singleton with a warning that contains STR." | |
87 | (match warnings | |
88 | (((? lint-warning? warning)) | |
89 | (string-contains (lint-warning-message warning) str)))) | |
90 | ||
b4f5e0e8 CR |
91 | \f |
92 | (test-begin "lint") | |
93 | ||
50fc2384 CB |
94 | (test-equal "description: not a string" |
95 | "invalid description: foobar" | |
96 | (single-lint-warning-message | |
97 | (check-description-style | |
98 | (dummy-package "x" (description 'foobar))))) | |
99 | ||
100 | (test-equal "description: not empty" | |
101 | "description should not be empty" | |
102 | (single-lint-warning-message | |
103 | (check-description-style | |
104 | (dummy-package "x" (description ""))))) | |
105 | ||
106 | (test-equal "description: invalid Texinfo markup" | |
107 | "Texinfo markup in description is invalid" | |
108 | (single-lint-warning-message | |
109 | (check-description-style | |
86ed0039 | 110 | (dummy-package "x" (description (identity "f{oo}b@r")))))) |
50fc2384 CB |
111 | |
112 | (test-equal "description: does not start with an upper-case letter" | |
113 | "description should start with an upper-case letter or digit" | |
114 | (single-lint-warning-message | |
115 | (let ((pkg (dummy-package "x" | |
116 | (description "bad description.")))) | |
117 | (check-description-style pkg)))) | |
118 | ||
119 | (test-equal "description: may start with a digit" | |
120 | '() | |
121 | (let ((pkg (dummy-package "x" | |
122 | (description "2-component library.")))) | |
123 | (check-description-style pkg))) | |
124 | ||
125 | (test-equal "description: may start with lower-case package name" | |
126 | '() | |
127 | (let ((pkg (dummy-package "x" | |
128 | (description "x is a dummy package.")))) | |
129 | (check-description-style pkg))) | |
130 | ||
131 | (test-equal "description: two spaces after end of sentence" | |
132 | "sentences in description should be followed by two spaces; possible infraction at 3" | |
133 | (single-lint-warning-message | |
134 | (let ((pkg (dummy-package "x" | |
135 | (description "Bad. Quite bad.")))) | |
136 | (check-description-style pkg)))) | |
137 | ||
138 | (test-equal "description: end-of-sentence detection with abbreviations" | |
139 | '() | |
140 | (let ((pkg (dummy-package "x" | |
141 | (description | |
142 | "E.g. Foo, i.e. Bar resp. Baz (a.k.a. DVD).")))) | |
143 | (check-description-style pkg))) | |
144 | ||
145 | (test-equal "description: may not contain trademark signs: ™" | |
146 | "description should not contain trademark sign '™' at 20" | |
147 | (single-lint-warning-message | |
148 | (let ((pkg (dummy-package "x" | |
149 | (description "Does The Right Thing™")))) | |
150 | (check-description-style pkg)))) | |
151 | ||
152 | (test-equal "description: may not contain trademark signs: ®" | |
153 | "description should not contain trademark sign '®' at 17" | |
154 | (single-lint-warning-message | |
155 | (let ((pkg (dummy-package "x" | |
156 | (description "Works with Format®")))) | |
157 | (check-description-style pkg)))) | |
158 | ||
159 | (test-equal "description: suggest ornament instead of quotes" | |
160 | "use @code or similar ornament instead of quotes" | |
161 | (single-lint-warning-message | |
162 | (let ((pkg (dummy-package "x" | |
163 | (description "This is a 'quoted' thing.")))) | |
164 | (check-description-style pkg)))) | |
165 | ||
edb328ad BW |
166 | (test-equal "description: leading whitespace" |
167 | "description contains leading whitespace" | |
168 | (single-lint-warning-message | |
169 | (let ((pkg (dummy-package "x" | |
170 | (description " Whitespace.")))) | |
171 | (check-description-style pkg)))) | |
172 | ||
93d85dea XC |
173 | (test-equal "description: trailing whitespace" |
174 | "description contains trailing whitespace" | |
175 | (single-lint-warning-message | |
176 | (let ((pkg (dummy-package "x" | |
177 | (description "Whitespace. ")))) | |
178 | (check-description-style pkg)))) | |
179 | ||
b5f45a21 VC |
180 | (test-equal "description: pluralized 'This package'" |
181 | "description contains typo 'This packages', should be 'This package'" | |
182 | (single-lint-warning-message | |
183 | (let ((pkg (dummy-package "x" | |
184 | (description "This packages is a typo.")))) | |
185 | (check-description-style pkg)))) | |
186 | ||
187 | (test-equal "description: grammar 'allows to'" | |
188 | "description contains typo 'allows to'" | |
189 | (single-lint-warning-message | |
190 | (let ((pkg (dummy-package "x" | |
191 | (description "This package allows to do stuff.")))) | |
192 | (check-description-style pkg)))) | |
193 | ||
50fc2384 CB |
194 | (test-equal "synopsis: not a string" |
195 | "invalid synopsis: #f" | |
196 | (single-lint-warning-message | |
197 | (let ((pkg (dummy-package "x" | |
198 | (synopsis #f)))) | |
199 | (check-synopsis-style pkg)))) | |
200 | ||
201 | (test-equal "synopsis: not empty" | |
202 | "synopsis should not be empty" | |
203 | (single-lint-warning-message | |
204 | (let ((pkg (dummy-package "x" | |
205 | (synopsis "")))) | |
206 | (check-synopsis-style pkg)))) | |
207 | ||
208 | (test-equal "synopsis: valid Texinfo markup" | |
209 | "Texinfo markup in synopsis is invalid" | |
210 | (single-lint-warning-message | |
211 | (check-synopsis-style | |
86ed0039 | 212 | (dummy-package "x" (synopsis (identity "Bad $@ texinfo")))))) |
50fc2384 CB |
213 | |
214 | (test-equal "synopsis: does not start with an upper-case letter" | |
215 | "synopsis should start with an upper-case letter or digit" | |
216 | (single-lint-warning-message | |
217 | (let ((pkg (dummy-package "x" | |
218 | (synopsis "bad synopsis")))) | |
219 | (check-synopsis-style pkg)))) | |
220 | ||
221 | (test-equal "synopsis: may start with a digit" | |
222 | '() | |
223 | (let ((pkg (dummy-package "x" | |
224 | (synopsis "5-dimensional frobnicator")))) | |
225 | (check-synopsis-style pkg))) | |
226 | ||
227 | (test-equal "synopsis: ends with a period" | |
228 | "no period allowed at the end of the synopsis" | |
229 | (single-lint-warning-message | |
230 | (let ((pkg (dummy-package "x" | |
231 | (synopsis "Bad synopsis.")))) | |
232 | (check-synopsis-style pkg)))) | |
233 | ||
234 | (test-equal "synopsis: ends with 'etc.'" | |
235 | '() | |
236 | (let ((pkg (dummy-package "x" | |
237 | (synopsis "Foo, bar, etc.")))) | |
238 | (check-synopsis-style pkg))) | |
239 | ||
240 | (test-equal "synopsis: starts with 'A'" | |
241 | "no article allowed at the beginning of the synopsis" | |
242 | (single-lint-warning-message | |
243 | (let ((pkg (dummy-package "x" | |
244 | (synopsis "A bad synopŝis")))) | |
245 | (check-synopsis-style pkg)))) | |
246 | ||
247 | (test-equal "synopsis: starts with 'An'" | |
248 | "no article allowed at the beginning of the synopsis" | |
249 | (single-lint-warning-message | |
250 | (let ((pkg (dummy-package "x" | |
251 | (synopsis "An awful synopsis")))) | |
252 | (check-synopsis-style pkg)))) | |
253 | ||
254 | (test-equal "synopsis: starts with 'a'" | |
255 | '("no article allowed at the beginning of the synopsis" | |
256 | "synopsis should start with an upper-case letter or digit") | |
257 | (sort | |
258 | (map | |
259 | lint-warning-message | |
260 | (let ((pkg (dummy-package "x" | |
261 | (synopsis "a bad synopsis")))) | |
262 | (check-synopsis-style pkg))) | |
263 | string<?)) | |
264 | ||
265 | (test-equal "synopsis: starts with 'an'" | |
266 | '("no article allowed at the beginning of the synopsis" | |
267 | "synopsis should start with an upper-case letter or digit") | |
268 | (sort | |
269 | (map | |
270 | lint-warning-message | |
271 | (let ((pkg (dummy-package "x" | |
272 | (synopsis "an awful synopsis")))) | |
273 | (check-synopsis-style pkg))) | |
274 | string<?)) | |
275 | ||
276 | (test-equal "synopsis: too long" | |
277 | "synopsis should be less than 80 characters long" | |
278 | (single-lint-warning-message | |
279 | (let ((pkg (dummy-package "x" | |
280 | (synopsis (make-string 80 #\X))))) | |
281 | (check-synopsis-style pkg)))) | |
282 | ||
283 | (test-equal "synopsis: start with package name" | |
284 | "synopsis should not start with the package name" | |
285 | (single-lint-warning-message | |
286 | (let ((pkg (dummy-package "x" | |
287 | (name "Foo") | |
288 | (synopsis "Foo, a nice package")))) | |
289 | (check-synopsis-style pkg)))) | |
290 | ||
291 | (test-equal "synopsis: start with package name prefix" | |
292 | '() | |
293 | (let ((pkg (dummy-package "arb" | |
294 | (synopsis "Arbitrary precision")))) | |
295 | (check-synopsis-style pkg))) | |
296 | ||
297 | (test-equal "synopsis: start with abbreviation" | |
298 | '() | |
299 | (let ((pkg (dummy-package "uucp" | |
300 | ;; Same problem with "APL interpreter", etc. | |
301 | (synopsis "UUCP implementation") | |
302 | (description "Imagine this is Taylor UUCP.")))) | |
303 | (check-synopsis-style pkg))) | |
304 | ||
04afb769 XC |
305 | (test-equal "synopsis: contains trailing whitespace" |
306 | "synopsis contains trailing whitespace" | |
307 | (single-lint-warning-message | |
308 | (let ((pkg (dummy-package "x" | |
309 | (synopsis "Whitespace ")))) | |
310 | (check-synopsis-style pkg)))) | |
311 | ||
c68070e4 XC |
312 | (test-equal "name: use underscore in package name" |
313 | "name should use hyphens instead of underscores" | |
314 | (single-lint-warning-message | |
315 | (let ((pkg (dummy-package "under_score"))) | |
316 | (check-name pkg)))) | |
317 | ||
82b0e27d MD |
318 | (test-equal "tests-true: #:tests? must not be set to #t" |
319 | "#:tests? must not be explicitly set to #t" | |
320 | (single-lint-warning-message | |
321 | (let ((pkg (dummy-package "x" (arguments '(#:tests? #t))))) | |
322 | (check-tests-true pkg)))) | |
323 | ||
324 | (test-equal "tests-true: absent #:tests? is acceptable" | |
325 | '() | |
326 | (let ((pkg (dummy-package "x"))) | |
327 | (check-tests-true pkg))) | |
328 | ||
329 | (test-equal "tests-true: #:tests? #f is acceptable" | |
330 | '() | |
331 | (let ((pkg (dummy-package "x" (arguments '(#:tests? #f))))) | |
332 | (check-tests-true pkg))) | |
333 | ||
334 | (test-equal "tests-true: #:tests? #t acceptable when compiling natively" | |
335 | '() | |
336 | (let ((pkg (dummy-package "x" | |
337 | (arguments | |
338 | `(#:tests? ,(not (%current-target-system))))))) | |
339 | (check-tests-true pkg))) | |
340 | ||
50fc2384 CB |
341 | (test-equal "inputs: pkg-config is probably a native input" |
342 | "'pkg-config' should probably be a native input" | |
343 | (single-lint-warning-message | |
344 | (let ((pkg (dummy-package "x" | |
345 | (inputs `(("pkg-config" ,pkg-config)))))) | |
346 | (check-inputs-should-be-native pkg)))) | |
347 | ||
348 | (test-equal "inputs: glib:bin is probably a native input" | |
349 | "'glib:bin' should probably be a native input" | |
350 | (single-lint-warning-message | |
351 | (let ((pkg (dummy-package "x" | |
352 | (inputs `(("glib" ,glib "bin")))))) | |
353 | (check-inputs-should-be-native pkg)))) | |
354 | ||
355 | (test-equal | |
891a843d | 356 | "inputs: python-setuptools should not be an input at all (input)" |
50fc2384 CB |
357 | "'python-setuptools' should probably not be an input at all" |
358 | (single-lint-warning-message | |
359 | (let ((pkg (dummy-package "x" | |
360 | (inputs `(("python-setuptools" | |
361 | ,python-setuptools)))))) | |
362 | (check-inputs-should-not-be-an-input-at-all pkg)))) | |
363 | ||
364 | (test-equal | |
891a843d | 365 | "inputs: python-setuptools should not be an input at all (native-input)" |
50fc2384 CB |
366 | "'python-setuptools' should probably not be an input at all" |
367 | (single-lint-warning-message | |
368 | (let ((pkg (dummy-package "x" | |
369 | (native-inputs | |
370 | `(("python-setuptools" | |
371 | ,python-setuptools)))))) | |
372 | (check-inputs-should-not-be-an-input-at-all pkg)))) | |
373 | ||
374 | (test-equal | |
891a843d | 375 | "inputs: python-setuptools should not be an input at all (propagated-input)" |
50fc2384 CB |
376 | "'python-setuptools' should probably not be an input at all" |
377 | (single-lint-warning-message | |
378 | (let ((pkg (dummy-package "x" | |
379 | (propagated-inputs | |
380 | `(("python-setuptools" ,python-setuptools)))))) | |
381 | (check-inputs-should-not-be-an-input-at-all pkg)))) | |
382 | ||
b7f1b4c1 LC |
383 | (test-assert "input labels: no warnings" |
384 | (let ((pkg (dummy-package "x" | |
385 | (inputs `(("glib" ,glib) | |
386 | ("pkg-config" ,pkg-config)))))) | |
387 | (null? (check-input-labels pkg)))) | |
388 | ||
389 | (test-equal "input labels: one warning" | |
390 | "label 'pkgkonfig' does not match package name 'pkg-config'" | |
391 | (single-lint-warning-message | |
392 | (let ((pkg (dummy-package "x" | |
393 | (inputs `(("glib" ,glib) | |
394 | ("pkgkonfig" ,pkg-config)))))) | |
395 | (check-input-labels pkg)))) | |
396 | ||
eac82c0e MD |
397 | (test-equal "explicit #:sh argument to 'wrap-program' is acceptable" |
398 | '() | |
399 | (let* ((phases | |
400 | ;; Loosely based on the "catfish" package | |
401 | `(modify-phases %standard-phases | |
402 | (add-after 'install 'wrap | |
403 | (lambda* (#:key inputs outputs #:allow-other-keys) | |
404 | (define catfish (string-append (assoc-ref outputs "out") | |
405 | "/bin/catfish")) | |
406 | (define hsab (string-append (assoc-ref inputs "hsab") | |
407 | "/bin/hsab")) | |
408 | (wrap-program catfish #:sh hsab | |
409 | `("PYTHONPATH" = (,"blabla"))))))) | |
410 | (pkg (dummy-package "x" (arguments `(#:phases ,phases))))) | |
411 | (check-wrapper-inputs pkg))) | |
412 | ||
413 | (test-equal | |
414 | "'check-wrapper-inputs' detects 'wrap-program' without \"bash\" in inputs" | |
415 | "\"bash-minimal\" should be in 'inputs' when 'wrap-program' is used" | |
416 | (let* ((phases | |
417 | `(modify-phases %standard-phases | |
418 | (add-after 'install 'wrap | |
419 | (lambda _ | |
420 | (wrap-program the-binary bla-bla))))) | |
421 | (pkg (dummy-package "x" (arguments `(#:phases ,phases))))) | |
422 | (single-lint-warning-message (check-wrapper-inputs pkg)))) | |
423 | ||
424 | (test-equal | |
425 | "'check-wrapper-inputs' detects 'wrap-qt-program' without \"bash\" in inputs" | |
426 | "\"bash-minimal\" should be in 'inputs' when 'wrap-qt-program' is used" | |
427 | (let* ((phases | |
428 | `(modify-phases %standard-phases | |
429 | (add-after 'install 'qtwrap | |
430 | (lambda _ | |
431 | (wrap-qt-program the-binary bla-bla))))) | |
432 | (pkg (dummy-package "x" (arguments `(#:phases ,phases))))) | |
433 | (single-lint-warning-message (check-wrapper-inputs pkg)))) | |
434 | ||
435 | (test-equal "\"bash\" in 'inputs' satisfies 'check-wrapper-inputs'" | |
436 | '() | |
437 | (let* ((phases | |
438 | `(modify-phases %standard-phases | |
439 | (add-after 'install 'wrap | |
440 | (lambda _ | |
441 | (wrap-program the-binary bla-bla))))) | |
442 | (pkg (dummy-package "x" (arguments `(#:phases ,phases)) | |
443 | (inputs `(("bash" ,bash)))))) | |
444 | (check-wrapper-inputs pkg))) | |
445 | ||
446 | (test-equal "\"bash-minimal\" in 'inputs' satisfies 'check-wrapper-inputs'" | |
447 | '() | |
448 | (let* ((phases | |
449 | `(modify-phases %standard-phases | |
450 | (add-after 'install 'wrap | |
451 | (lambda _ | |
452 | (wrap-program THE-BINARY bla-bla))))) | |
453 | (pkg (dummy-package "x" (arguments `(#:phases ,phases)) | |
454 | (inputs `(("bash-minimal" ,bash-minimal)))))) | |
455 | (check-wrapper-inputs pkg))) | |
456 | ||
457 | (test-equal "'cut' doesn't hide bad usages of 'wrap-program'" | |
458 | "\"bash-minimal\" should be in 'inputs' when 'wrap-program' is used" | |
459 | (let* ((phases | |
460 | ;; Taken from the "straw-viewer" package | |
461 | `(modify-phases %standard-phases | |
462 | (add-after 'install 'wrap-program | |
463 | (lambda* (#:key outputs #:allow-other-keys) | |
464 | (let* ((out (assoc-ref outputs "out")) | |
465 | (bin-dir (string-append out "/bin/")) | |
466 | (site-dir (string-append out "/lib/perl5/site_perl/")) | |
467 | (lib-path (getenv "PERL5LIB"))) | |
468 | (for-each (cut wrap-program <> | |
469 | `("PERL5LIB" ":" prefix | |
470 | (,lib-path ,site-dir))) | |
471 | (find-files bin-dir))))))) | |
472 | (pkg (dummy-package "x" (arguments `(#:phases ,phases))))) | |
473 | (single-lint-warning-message (check-wrapper-inputs pkg)))) | |
474 | ||
475 | (test-equal "bogus phase specifications don't crash the linter" | |
476 | "invalid phase clause" | |
477 | (let* ((phases | |
478 | `(modify-phases %standard-phases | |
479 | (add-invalid))) | |
480 | (pkg (dummy-package "x" (arguments `(#:phases ,phases))))) | |
481 | (single-lint-warning-message (check-wrapper-inputs pkg)))) | |
482 | ||
d8ae7852 | 483 | (test-equal "file patches: different file name -> warning" |
50fc2384 CB |
484 | "file names of patches should start with the package name" |
485 | (single-lint-warning-message | |
486 | (let ((pkg (dummy-package "x" | |
487 | (source | |
488 | (dummy-origin | |
489 | (patches (list "/path/to/y.patch"))))))) | |
490 | (check-patch-file-names pkg)))) | |
491 | ||
d8ae7852 CM |
492 | (test-equal "file patches: same file name -> no warnings" |
493 | '() | |
494 | (let ((pkg (dummy-package "x" | |
495 | (source | |
496 | (dummy-origin | |
497 | (patches (list "/path/to/x.patch"))))))) | |
498 | (check-patch-file-names pkg))) | |
499 | ||
500 | (test-equal "<origin> patches: different file name -> warning" | |
501 | "file names of patches should start with the package name" | |
502 | (single-lint-warning-message | |
503 | (let ((pkg (dummy-package "x" | |
504 | (source | |
505 | (dummy-origin | |
506 | (patches | |
507 | (list | |
508 | (dummy-origin | |
509 | (file-name "y.patch"))))))))) | |
510 | (check-patch-file-names pkg)))) | |
511 | ||
512 | (test-equal "<origin> patches: same file name -> no warnings" | |
513 | '() | |
514 | (let ((pkg (dummy-package "x" | |
515 | (source | |
516 | (dummy-origin | |
517 | (patches | |
518 | (list | |
519 | (dummy-origin | |
520 | (file-name "x.patch"))))))))) | |
521 | (check-patch-file-names pkg))) | |
522 | ||
5f547a5c | 523 | (test-equal "patches: file name too long, which may break 'make dist'" |
50fc2384 | 524 | (string-append "x-" |
5f547a5c VC |
525 | (make-string 152 #\a) |
526 | ".patch: file name is too long, which may break 'make dist'") | |
50fc2384 CB |
527 | (single-lint-warning-message |
528 | (let ((pkg (dummy-package | |
529 | "x" | |
530 | (source | |
531 | (dummy-origin | |
532 | (patches (list (string-append "x-" | |
5f547a5c | 533 | (make-string 152 #\a) |
50fc2384 CB |
534 | ".patch")))))))) |
535 | (check-patch-file-names pkg)))) | |
536 | ||
537 | (test-equal "patches: not found" | |
d51bfe24 | 538 | "this-patch-does-not-exist!: patch not found\n" |
50fc2384 CB |
539 | (single-lint-warning-message |
540 | (let ((pkg (dummy-package | |
541 | "x" | |
542 | (source | |
543 | (dummy-origin | |
544 | (patches | |
545 | (list (search-patch "this-patch-does-not-exist!")))))))) | |
546 | (check-patch-file-names pkg)))) | |
547 | ||
4f156c25 LC |
548 | (test-assert "patch headers: no warnings" |
549 | (call-with-temporary-directory | |
550 | (lambda (directory) | |
551 | (call-with-output-file (string-append directory "/t.patch") | |
552 | (lambda (port) | |
553 | (display "This is a patch.\n\n--- a\n+++ b\n" | |
554 | port))) | |
555 | ||
556 | (parameterize ((%patch-path (list directory))) | |
557 | (let ((pkg (dummy-package "x" | |
558 | (source (dummy-origin | |
559 | (patches (search-patches "t.patch"))))))) | |
560 | (null? (check-patch-headers pkg))))))) | |
561 | ||
562 | (test-equal "patch headers: missing comment" | |
563 | "t.patch: patch lacks comment and upstream status" | |
564 | (call-with-temporary-directory | |
565 | (lambda (directory) | |
566 | (call-with-output-file (string-append directory "/t.patch") | |
567 | (lambda (port) | |
568 | (display "\n--- a\n+++ b\n" | |
569 | port))) | |
570 | ||
571 | (parameterize ((%patch-path (list directory))) | |
572 | (let ((pkg (dummy-package "x" | |
573 | (source (dummy-origin | |
574 | (patches (search-patches "t.patch"))))))) | |
575 | (single-lint-warning-message (check-patch-headers pkg))))))) | |
576 | ||
577 | (test-equal "patch headers: empty" | |
578 | "t.patch: empty patch" | |
579 | (call-with-temporary-directory | |
580 | (lambda (directory) | |
581 | (call-with-output-file (string-append directory "/t.patch") | |
582 | (const #t)) | |
583 | ||
584 | (parameterize ((%patch-path '())) | |
585 | (let ((pkg (dummy-package "x" | |
586 | (source (dummy-origin | |
587 | (patches | |
588 | (list (local-file | |
589 | (string-append directory | |
590 | "/t.patch"))))))))) | |
591 | (single-lint-warning-message (check-patch-headers pkg))))))) | |
592 | ||
593 | (test-equal "patch headers: patch not found" | |
594 | "does-not-exist.patch: patch not found\n" | |
595 | (parameterize ((%patch-path '())) | |
596 | (let ((pkg (dummy-package "x" | |
597 | (source (dummy-origin | |
598 | (patches | |
599 | (search-patches "does-not-exist.patch"))))))) | |
600 | (single-lint-warning-message (check-patch-headers pkg))))) | |
601 | ||
50fc2384 | 602 | (test-equal "derivation: invalid arguments" |
7d873f19 | 603 | "failed to create x86_64-linux derivation: (match-error \"match\" \"no matching pattern\" invalid-module)" |
50fc2384 CB |
604 | (match (let ((pkg (dummy-package "x" |
605 | (arguments | |
606 | '(#:imported-modules (invalid-module)))))) | |
607 | (check-derivation pkg)) | |
608 | (((and (? lint-warning?) first-warning) others ...) | |
609 | (lint-warning-message first-warning)))) | |
610 | ||
993023a2 LC |
611 | (test-equal "profile-collisions: no warnings" |
612 | '() | |
613 | (check-profile-collisions (dummy-package "x"))) | |
614 | ||
615 | (test-equal "profile-collisions: propagated inputs collide" | |
616 | "propagated inputs p0@1 and p0@2 collide" | |
617 | (let* ((p0 (dummy-package "p0" (version "1"))) | |
618 | (p0* (dummy-package "p0" (version "2"))) | |
619 | (p1 (dummy-package "p1" (propagated-inputs `(("p0" ,p0))))) | |
620 | (p2 (dummy-package "p2" (propagated-inputs `(("p1" ,p1))))) | |
621 | (p3 (dummy-package "p3" (propagated-inputs `(("p0" ,p0*))))) | |
622 | (p4 (dummy-package "p4" (propagated-inputs | |
623 | `(("p2" ,p2) ("p3", p3)))))) | |
624 | (single-lint-warning-message | |
625 | (check-profile-collisions p4)))) | |
626 | ||
627 | (test-assert "profile-collisions: propagated inputs collide, store items" | |
628 | (string-match-or-error | |
629 | "propagated inputs /[[:graph:]]+-p0-1 and /[[:graph:]]+-p0-1 collide" | |
630 | (let* ((p0 (dummy-package "p0" (version "1"))) | |
631 | (p0* (dummy-package "p0" (version "1") | |
632 | (inputs `(("x" ,(dummy-package "x")))))) | |
633 | (p1 (dummy-package "p1" (propagated-inputs `(("p0" ,p0))))) | |
634 | (p2 (dummy-package "p2" (propagated-inputs `(("p1" ,p1))))) | |
635 | (p3 (dummy-package "p3" (propagated-inputs `(("p0" ,p0*))))) | |
636 | (p4 (dummy-package "p4" (propagated-inputs | |
637 | `(("p2" ,p2) ("p3", p3)))))) | |
638 | (single-lint-warning-message | |
639 | (check-profile-collisions p4))))) | |
640 | ||
50fc2384 CB |
641 | (test-equal "license: invalid license" |
642 | "invalid license field" | |
643 | (single-lint-warning-message | |
644 | (check-license (dummy-package "x" (license #f))))) | |
645 | ||
646 | (test-equal "home-page: wrong home-page" | |
647 | "invalid value for home page" | |
648 | (let ((pkg (package | |
649 | (inherit (dummy-package "x")) | |
650 | (home-page #f)))) | |
651 | (single-lint-warning-message | |
652 | (check-home-page pkg)))) | |
653 | ||
654 | (test-equal "home-page: invalid URI" | |
655 | "invalid home page URL: \"foobar\"" | |
656 | (let ((pkg (package | |
657 | (inherit (dummy-package "x")) | |
658 | (home-page "foobar")))) | |
659 | (single-lint-warning-message | |
660 | (check-home-page pkg)))) | |
661 | ||
37592014 | 662 | (test-assert "home-page: host not found" |
50fc2384 CB |
663 | (let ((pkg (package |
664 | (inherit (dummy-package "x")) | |
665 | (home-page "http://does-not-exist")))) | |
37592014 | 666 | (warning-contains? "domain not found" (check-home-page pkg)))) |
907c98ac | 667 | |
c05ceaf2 MD |
668 | (parameterize ((%http-server-port 9999)) |
669 | ;; TODO skip this test if some process is currently listening at 9999 | |
670 | (test-equal "home-page: Connection refused" | |
671 | "URI http://localhost:9999/foo/bar unreachable: Connection refused" | |
672 | (let ((pkg (package | |
673 | (inherit (dummy-package "x")) | |
674 | (home-page (%local-url))))) | |
675 | (single-lint-warning-message | |
676 | (check-home-page pkg))))) | |
907c98ac | 677 | |
907c98ac | 678 | (test-equal "home-page: 200" |
50fc2384 | 679 | '() |
9323ab55 | 680 | (with-http-server `((200 ,%long-string)) |
50fc2384 CB |
681 | (let ((pkg (package |
682 | (inherit (dummy-package "x")) | |
683 | (home-page (%local-url))))) | |
684 | (check-home-page pkg)))) | |
907c98ac | 685 | |
c05ceaf2 MD |
686 | (with-http-server `((200 "This is too small.")) |
687 | (test-equal "home-page: 200 but short length" | |
688 | (format #f "URI ~a returned suspiciously small file (18 bytes)" | |
689 | (%local-url)) | |
50fc2384 CB |
690 | (let ((pkg (package |
691 | (inherit (dummy-package "x")) | |
692 | (home-page (%local-url))))) | |
693 | ||
694 | (single-lint-warning-message | |
695 | (check-home-page pkg))))) | |
bfcb3d76 | 696 | |
c05ceaf2 MD |
697 | (with-http-server `((404 ,%long-string)) |
698 | (test-equal "home-page: 404" | |
699 | (format #f "URI ~a not reachable: 404 (\"Such is life\")" (%local-url)) | |
50fc2384 CB |
700 | (let ((pkg (package |
701 | (inherit (dummy-package "x")) | |
702 | (home-page (%local-url))))) | |
703 | (single-lint-warning-message | |
704 | (check-home-page pkg))))) | |
b4f5e0e8 | 705 | |
c05ceaf2 MD |
706 | (with-http-server `((301 ,%long-string)) |
707 | (test-equal "home-page: 301, invalid" | |
708 | (format #f "invalid permanent redirect from ~a" (%local-url)) | |
50fc2384 CB |
709 | (let ((pkg (package |
710 | (inherit (dummy-package "x")) | |
711 | (home-page (%local-url))))) | |
712 | (single-lint-warning-message | |
713 | (check-home-page pkg))))) | |
61f28fe7 | 714 | |
c05ceaf2 MD |
715 | (with-http-server `((200 ,%long-string)) |
716 | (let* ((initial-url (%local-url)) | |
717 | (redirect (build-response #:code 301 | |
718 | #:headers | |
719 | `((location | |
720 | . ,(string->uri initial-url)))))) | |
721 | (parameterize ((%http-server-port 0)) | |
722 | (with-http-server `((,redirect "")) | |
723 | (test-equal "home-page: 301 -> 200" | |
724 | (format #f "permanent redirect from ~a to ~a" | |
725 | (%local-url) initial-url) | |
50fc2384 CB |
726 | (let ((pkg (package |
727 | (inherit (dummy-package "x")) | |
728 | (home-page (%local-url))))) | |
729 | (single-lint-warning-message | |
730 | (check-home-page pkg)))))))) | |
61f28fe7 | 731 | |
c05ceaf2 MD |
732 | (with-http-server `((404 "booh!")) |
733 | (let* ((initial-url (%local-url)) | |
734 | (redirect (build-response #:code 301 | |
735 | #:headers | |
736 | `((location | |
737 | . ,(string->uri initial-url)))))) | |
738 | (parameterize ((%http-server-port 0)) | |
739 | (with-http-server `((,redirect "")) | |
740 | (test-equal "home-page: 301 -> 404" | |
741 | (format #f "URI ~a not reachable: 404 (\"Such is life\")" (%local-url)) | |
50fc2384 CB |
742 | (let ((pkg (package |
743 | (inherit (dummy-package "x")) | |
744 | (home-page (%local-url))))) | |
745 | (single-lint-warning-message | |
746 | (check-home-page pkg)))))))) | |
747 | ||
748 | ||
749 | (test-equal "source-file-name" | |
750 | "the source file name should contain the package name" | |
751 | (let ((pkg (dummy-package "x" | |
752 | (version "3.2.1") | |
753 | (source | |
754 | (origin | |
755 | (method url-fetch) | |
756 | (uri "http://www.example.com/3.2.1.tar.gz") | |
757 | (sha256 %null-sha256)))))) | |
758 | (single-lint-warning-message | |
759 | (check-source-file-name pkg)))) | |
760 | ||
761 | (test-equal "source-file-name: v prefix" | |
762 | "the source file name should contain the package name" | |
763 | (let ((pkg (dummy-package "x" | |
764 | (version "3.2.1") | |
765 | (source | |
766 | (origin | |
767 | (method url-fetch) | |
768 | (uri "http://www.example.com/v3.2.1.tar.gz") | |
769 | (sha256 %null-sha256)))))) | |
770 | (single-lint-warning-message | |
771 | (check-source-file-name pkg)))) | |
772 | ||
773 | (test-equal "source-file-name: bad checkout" | |
774 | "the source file name should contain the package name" | |
775 | (let ((pkg (dummy-package "x" | |
776 | (version "3.2.1") | |
777 | (source | |
778 | (origin | |
779 | (method git-fetch) | |
780 | (uri (git-reference | |
781 | (url "http://www.example.com/x.git") | |
782 | (commit "0"))) | |
783 | (sha256 %null-sha256)))))) | |
784 | (single-lint-warning-message | |
785 | (check-source-file-name pkg)))) | |
786 | ||
787 | (test-equal "source-file-name: good checkout" | |
788 | '() | |
789 | (let ((pkg (dummy-package "x" | |
790 | (version "3.2.1") | |
791 | (source | |
792 | (origin | |
793 | (method git-fetch) | |
794 | (uri (git-reference | |
795 | (url "http://git.example.com/x.git") | |
796 | (commit "0"))) | |
797 | (file-name (string-append "x-" version)) | |
798 | (sha256 %null-sha256)))))) | |
799 | (check-source-file-name pkg))) | |
800 | ||
801 | (test-equal "source-file-name: valid" | |
802 | '() | |
803 | (let ((pkg (dummy-package "x" | |
804 | (version "3.2.1") | |
805 | (source | |
806 | (origin | |
807 | (method url-fetch) | |
808 | (uri "http://www.example.com/x-3.2.1.tar.gz") | |
809 | (sha256 %null-sha256)))))) | |
810 | (check-source-file-name pkg))) | |
c180017b | 811 | |
50fc2384 CB |
812 | (test-equal "source-unstable-tarball" |
813 | "the source URI should not be an autogenerated tarball" | |
814 | (let ((pkg (dummy-package "x" | |
815 | (source | |
816 | (origin | |
817 | (method url-fetch) | |
818 | (uri "https://github.com/example/example/archive/v0.0.tar.gz") | |
819 | (sha256 %null-sha256)))))) | |
820 | (single-lint-warning-message | |
821 | (check-source-unstable-tarball pkg)))) | |
822 | ||
823 | (test-equal "source-unstable-tarball: source #f" | |
824 | '() | |
825 | (let ((pkg (dummy-package "x" | |
826 | (source #f)))) | |
827 | (check-source-unstable-tarball pkg))) | |
828 | ||
829 | (test-equal "source-unstable-tarball: valid" | |
830 | '() | |
831 | (let ((pkg (dummy-package "x" | |
832 | (source | |
833 | (origin | |
834 | (method url-fetch) | |
835 | (uri "https://github.com/example/example/releases/download/x-0.0/x-0.0.tar.gz") | |
836 | (sha256 %null-sha256)))))) | |
837 | (check-source-unstable-tarball pkg))) | |
950d2ea4 | 838 | |
50fc2384 CB |
839 | (test-equal "source-unstable-tarball: package named archive" |
840 | '() | |
841 | (let ((pkg (dummy-package "x" | |
842 | (source | |
843 | (origin | |
bfcb3d76 | 844 | (method url-fetch) |
50fc2384 | 845 | (uri "https://github.com/example/archive/releases/download/x-0.0/x-0.0.tar.gz") |
bfcb3d76 | 846 | (sha256 %null-sha256)))))) |
50fc2384 | 847 | (check-source-unstable-tarball pkg))) |
bfcb3d76 | 848 | |
50fc2384 CB |
849 | (test-equal "source-unstable-tarball: not-github" |
850 | '() | |
851 | (let ((pkg (dummy-package "x" | |
852 | (source | |
853 | (origin | |
950d2ea4 | 854 | (method url-fetch) |
50fc2384 | 855 | (uri "https://bitbucket.org/archive/example/download/x-0.0.tar.gz") |
950d2ea4 | 856 | (sha256 %null-sha256)))))) |
50fc2384 CB |
857 | (check-source-unstable-tarball pkg))) |
858 | ||
859 | (test-equal "source-unstable-tarball: git-fetch" | |
860 | '() | |
861 | (let ((pkg (dummy-package "x" | |
862 | (source | |
863 | (origin | |
864 | (method git-fetch) | |
865 | (uri (git-reference | |
b0e7b699 | 866 | (url "https://github.com/archive/example") |
50fc2384 CB |
867 | (commit "0"))) |
868 | (sha256 %null-sha256)))))) | |
869 | (check-source-unstable-tarball pkg))) | |
870 | ||
5532371a MD |
871 | (define (package-with-phase-changes changes) |
872 | (dummy-package "x" | |
873 | (arguments `(#:phases | |
874 | ,(if (gexp? changes) | |
875 | #~(modify-phases %standard-phases | |
876 | #$@changes) | |
877 | `(modify-phases %standard-phases | |
878 | ,@changes)))))) | |
879 | ||
880 | (test-equal "optional-tests: no check phase" | |
881 | '() | |
882 | (let ((pkg (package-with-phase-changes '()))) | |
883 | (check-optional-tests pkg))) | |
884 | ||
885 | (test-equal "optional-tests: check phase respects #:tests?" | |
886 | '() | |
887 | (let ((pkg (package-with-phase-changes | |
888 | '((replace 'check | |
889 | (lambda* (#:key tests? #:allow-other-keys?) | |
890 | (when tests? | |
891 | (invoke "./the-test-suite")))))))) | |
892 | (check-optional-tests pkg))) | |
893 | ||
894 | (test-equal "optional-tests: check phase ignores #:tests?" | |
895 | "the 'check' phase should respect #:tests?" | |
896 | (let ((pkg (package-with-phase-changes | |
897 | '((replace 'check | |
898 | (lambda _ | |
899 | (invoke "./the-test-suite"))))))) | |
900 | (single-lint-warning-message | |
901 | (check-optional-tests pkg)))) | |
902 | ||
903 | (test-equal "optional-tests: do not crash when #:phases is invalid" | |
904 | "incorrect call to ‘modify-phases’" | |
905 | (let ((pkg (package-with-phase-changes 'this-is-not-a-list))) | |
906 | (single-lint-warning-message | |
907 | (check-optional-tests pkg)))) | |
908 | ||
909 | (test-equal "optional-tests: allow G-exps (no warning)" | |
910 | '() | |
911 | (let ((pkg (package-with-phase-changes #~()))) | |
912 | (check-optional-tests pkg))) | |
913 | ||
914 | (test-equal "optional-tests: allow G-exps (warning)" | |
915 | "the 'check' phase should respect #:tests?" | |
916 | (let ((pkg (package-with-phase-changes | |
917 | #~((replace 'check | |
918 | (lambda _ | |
919 | (invoke "/the-test-suite"))))))) | |
920 | (single-lint-warning-message | |
921 | (check-optional-tests pkg)))) | |
922 | ||
923 | (test-equal "optional-tests: complicated 'check' phase" | |
924 | "the 'check' phase should respect #:tests?" | |
925 | (let ((pkg (package-with-phase-changes | |
926 | '((replace 'check | |
927 | (lambda* (#:key inputs tests? #:allow-other-keys) | |
928 | (let ((something (stuff from inputs or native-inputs))) | |
929 | (delete-file "dateutil/test/test_utils.py") | |
930 | (invoke "pytest" "-vv")))))))) | |
931 | (single-lint-warning-message | |
932 | (check-optional-tests pkg)))) | |
933 | ||
934 | (test-equal "optional-tests: 'check' phase is not first phase" | |
935 | "the 'check' phase should respect #:tests?" | |
936 | (let ((pkg (package-with-phase-changes | |
937 | '((add-after 'unpack | |
938 | (lambda _ | |
939 | (chdir "libtestcase-0.0.0"))) | |
940 | (replace 'check | |
941 | (lambda _ (invoke "./test-suite"))))))) | |
942 | (single-lint-warning-message | |
943 | (check-optional-tests pkg)))) | |
944 | ||
50fc2384 CB |
945 | (test-equal "source: 200" |
946 | '() | |
9323ab55 | 947 | (with-http-server `((200 ,%long-string)) |
50fc2384 CB |
948 | (let ((pkg (package |
949 | (inherit (dummy-package "x")) | |
950 | (source (origin | |
951 | (method url-fetch) | |
952 | (uri (%local-url)) | |
953 | (sha256 %null-sha256)))))) | |
954 | (check-source pkg)))) | |
955 | ||
c05ceaf2 MD |
956 | (with-http-server '((200 "This is too small.")) |
957 | (test-equal "source: 200 but short length" | |
958 | (format #f "URI ~a returned suspiciously small file (18 bytes)" | |
959 | (%local-url)) | |
50fc2384 CB |
960 | (let ((pkg (package |
961 | (inherit (dummy-package "x")) | |
962 | (source (origin | |
963 | (method url-fetch) | |
964 | (uri (%local-url)) | |
965 | (sha256 %null-sha256)))))) | |
966 | (match (check-source pkg) | |
967 | ((first-warning ; All source URIs are unreachable | |
968 | (and (? lint-warning?) second-warning)) | |
969 | (lint-warning-message second-warning)))))) | |
970 | ||
c05ceaf2 MD |
971 | (with-http-server `((404 ,%long-string)) |
972 | (test-equal "source: 404" | |
973 | (format #f "URI ~a not reachable: 404 (\"Such is life\")" | |
974 | (%local-url)) | |
50fc2384 CB |
975 | (let ((pkg (package |
976 | (inherit (dummy-package "x")) | |
977 | (source (origin | |
978 | (method url-fetch) | |
979 | (uri (%local-url)) | |
980 | (sha256 %null-sha256)))))) | |
981 | (match (check-source pkg) | |
982 | ((first-warning ; All source URIs are unreachable | |
983 | (and (? lint-warning?) second-warning)) | |
984 | (lint-warning-message second-warning)))))) | |
950d2ea4 | 985 | |
99b20428 LC |
986 | (test-equal "source: 404 and 200" |
987 | '() | |
9323ab55 | 988 | (with-http-server `((404 ,%long-string)) |
99b20428 LC |
989 | (let ((bad-url (%local-url))) |
990 | (parameterize ((%http-server-port (+ 1 (%http-server-port)))) | |
9323ab55 | 991 | (with-http-server `((200 ,%long-string)) |
99b20428 LC |
992 | (let ((pkg (package |
993 | (inherit (dummy-package "x")) | |
994 | (source (origin | |
995 | (method url-fetch) | |
996 | (uri (list bad-url (%local-url))) | |
997 | (sha256 %null-sha256)))))) | |
998 | ;; Since one of the two URLs is good, this should return the empty | |
999 | ;; list. | |
1000 | (check-source pkg))))))) | |
1001 | ||
c05ceaf2 MD |
1002 | (with-http-server `((200 ,%long-string)) |
1003 | (let* ((initial-url (%local-url)) | |
1004 | (redirect (build-response #:code 301 | |
1005 | #:headers | |
1006 | `((location | |
1007 | . ,(string->uri initial-url)))))) | |
1008 | (parameterize ((%http-server-port 0)) | |
1009 | (with-http-server `((,redirect "")) | |
1010 | (test-equal "source: 301 -> 200" | |
1011 | (format #f "permanent redirect from ~a to ~a" | |
1012 | (%local-url) initial-url) | |
50fc2384 CB |
1013 | (let ((pkg (package |
1014 | (inherit (dummy-package "x")) | |
1015 | (source (origin | |
1016 | (method url-fetch) | |
1017 | (uri (%local-url)) | |
1018 | (sha256 %null-sha256)))))) | |
1019 | (match (check-source pkg) | |
1020 | ((first-warning ; All source URIs are unreachable | |
1021 | (and (? lint-warning?) second-warning)) | |
1022 | (lint-warning-message second-warning))))))))) | |
61f28fe7 | 1023 | |
c05ceaf2 MD |
1024 | (with-http-server `((200 ,%long-string)) |
1025 | (let* ((initial-url (%local-url)) | |
1026 | (redirect (build-response #:code 301 | |
1027 | #:headers | |
1028 | `((location | |
1029 | . ,(string->uri initial-url)))))) | |
1030 | (parameterize ((%http-server-port 0)) | |
1031 | (with-http-server `((,redirect "")) | |
1032 | (test-equal "source, git-reference: 301 -> 200" | |
1033 | (format #f "permanent redirect from ~a to ~a" | |
1034 | (%local-url) initial-url) | |
c1052667 LC |
1035 | (let ((pkg (dummy-package |
1036 | "x" | |
1037 | (source (origin | |
1038 | (method git-fetch) | |
1039 | (uri (git-reference (url (%local-url)) | |
1040 | (commit "v1.0.0"))) | |
1041 | (sha256 %null-sha256)))))) | |
1042 | (single-lint-warning-message (check-source pkg)))))))) | |
1043 | ||
c05ceaf2 MD |
1044 | (with-http-server '((404 "booh!")) |
1045 | (let* ((initial-url (%local-url)) | |
1046 | (redirect (build-response #:code 301 | |
1047 | #:headers | |
1048 | `((location | |
1049 | . ,(string->uri initial-url)))))) | |
1050 | (parameterize ((%http-server-port 0)) | |
1051 | (with-http-server `((,redirect "")) | |
1052 | (test-equal "source: 301 -> 404" | |
1053 | (format #f "URI ~a not reachable: 404 (\"Such is life\")" | |
1054 | (%local-url)) | |
50fc2384 CB |
1055 | (let ((pkg (package |
1056 | (inherit (dummy-package "x")) | |
1057 | (source (origin | |
1058 | (method url-fetch) | |
1059 | (uri (%local-url)) | |
1060 | (sha256 %null-sha256)))))) | |
1061 | (match (check-source pkg) | |
1062 | ((first-warning ; The first warning says that all URI's are | |
1063 | ; unreachable | |
1064 | (and (? lint-warning?) second-warning)) | |
1065 | (lint-warning-message second-warning))))))))) | |
1066 | ||
1067 | (test-equal "mirror-url" | |
1068 | '() | |
1069 | (let ((source (origin | |
1070 | (method url-fetch) | |
1071 | (uri "http://example.org/foo/bar.tar.gz") | |
1072 | (sha256 %null-sha256)))) | |
1073 | (check-mirror-url (dummy-package "x" (source source))))) | |
1074 | ||
1075 | (test-equal "mirror-url: one suggestion" | |
1076 | "URL should be 'mirror://gnu/foo/foo.tar.gz'" | |
1077 | (let ((source (origin | |
1078 | (method url-fetch) | |
1079 | (uri "http://ftp.gnu.org/pub/gnu/foo/foo.tar.gz") | |
1080 | (sha256 %null-sha256)))) | |
1081 | (single-lint-warning-message | |
1082 | (check-mirror-url (dummy-package "x" (source source)))))) | |
1083 | ||
1084 | (test-equal "github-url" | |
1085 | '() | |
9323ab55 | 1086 | (with-http-server `((200 ,%long-string)) |
50fc2384 CB |
1087 | (check-github-url |
1088 | (dummy-package "x" (source | |
1089 | (origin | |
1090 | (method url-fetch) | |
1091 | (uri (%local-url)) | |
1092 | (sha256 %null-sha256))))))) | |
0865d8a8 AI |
1093 | |
1094 | (let ((github-url "https://github.com/foo/bar/bar-1.0.tar.gz")) | |
50fc2384 CB |
1095 | (test-equal "github-url: one suggestion" |
1096 | (string-append | |
1097 | "URL should be '" github-url "'") | |
9323ab55 LC |
1098 | (let ((redirect (build-response #:code 301 |
1099 | #:headers | |
1100 | `((location | |
1101 | . ,(string->uri github-url)))))) | |
1102 | (with-http-server `((,redirect "")) | |
1103 | (let* ((initial-url (%local-url)) | |
1104 | (redirect (build-response #:code 302 | |
1105 | #:headers | |
1106 | `((location | |
1107 | . ,(string->uri initial-url)))))) | |
c05ceaf2 | 1108 | (parameterize ((%http-server-port 0)) |
9323ab55 LC |
1109 | (with-http-server `((,redirect "")) |
1110 | (single-lint-warning-message | |
1111 | (check-github-url | |
1112 | (dummy-package "x" (source | |
1113 | (origin | |
1114 | (method url-fetch) | |
1115 | (uri (%local-url)) | |
1116 | (sha256 %null-sha256)))))))))))) | |
95c2bc49 | 1117 | |
50fc2384 CB |
1118 | (test-equal "github-url: already the correct github url" |
1119 | '() | |
1120 | (check-github-url | |
1121 | (dummy-package "x" (source | |
1122 | (origin | |
1123 | (method url-fetch) | |
1124 | (uri github-url) | |
1125 | (sha256 %null-sha256))))))) | |
1126 | ||
1127 | (test-equal "cve" | |
1128 | '() | |
571f6e7f | 1129 | (mock ((guix lint) package-vulnerabilities (const '())) |
50fc2384 | 1130 | (check-vulnerabilities (dummy-package "x")))) |
5432734b | 1131 | |
50fc2384 CB |
1132 | (test-equal "cve: one vulnerability" |
1133 | "probably vulnerable to CVE-2015-1234" | |
fcb2318e | 1134 | (let ((dummy-vulnerabilities |
5432734b | 1135 | (lambda (package) |
fcb2318e LC |
1136 | (list (make-struct/no-tail |
1137 | (@@ (guix cve) <vulnerability>) | |
1138 | "CVE-2015-1234" | |
1139 | (list (cons (package-name package) | |
1140 | (package-version package)))))))) | |
1141 | (single-lint-warning-message | |
1142 | (check-vulnerabilities (dummy-package "pi" (version "3.14")) | |
1143 | dummy-vulnerabilities)))) | |
5432734b | 1144 | |
50fc2384 CB |
1145 | (test-equal "cve: one patched vulnerability" |
1146 | '() | |
571f6e7f | 1147 | (mock ((guix lint) package-vulnerabilities |
4e70fe4d | 1148 | (lambda (package) |
79c03e55 LC |
1149 | (list (make-struct/no-tail (@@ (guix cve) <vulnerability>) |
1150 | "CVE-2015-1234" | |
1151 | (list (cons (package-name package) | |
1152 | (package-version package))))))) | |
50fc2384 CB |
1153 | (check-vulnerabilities |
1154 | (dummy-package "pi" | |
1155 | (version "3.14") | |
1156 | (source | |
1157 | (dummy-origin | |
1158 | (patches | |
1159 | (list "/a/b/pi-CVE-2015-1234.patch")))))))) | |
1160 | ||
1161 | (test-equal "cve: known safe from vulnerability" | |
1162 | '() | |
571f6e7f | 1163 | (mock ((guix lint) package-vulnerabilities |
f4007b25 | 1164 | (lambda (package) |
79c03e55 LC |
1165 | (list (make-struct/no-tail (@@ (guix cve) <vulnerability>) |
1166 | "CVE-2015-1234" | |
1167 | (list (cons (package-name package) | |
1168 | (package-version package))))))) | |
50fc2384 CB |
1169 | (check-vulnerabilities |
1170 | (dummy-package "pi" | |
1171 | (version "3.14") | |
1172 | (properties `((lint-hidden-cve . ("CVE-2015-1234")))))))) | |
1173 | ||
1174 | (test-equal "cve: vulnerability fixed in replacement version" | |
1175 | '() | |
571f6e7f | 1176 | (mock ((guix lint) package-vulnerabilities |
9bee2bd1 LC |
1177 | (lambda (package) |
1178 | (match (package-version package) | |
1179 | ("0" | |
79c03e55 LC |
1180 | (list (make-struct/no-tail (@@ (guix cve) <vulnerability>) |
1181 | "CVE-2015-1234" | |
1182 | (list (cons (package-name package) | |
1183 | (package-version package)))))) | |
9bee2bd1 LC |
1184 | ("1" |
1185 | '())))) | |
50fc2384 CB |
1186 | (check-vulnerabilities |
1187 | (dummy-package | |
1188 | "foo" (version "0") | |
1189 | (replacement (dummy-package "foo" (version "1"))))))) | |
1190 | ||
1191 | (test-equal "cve: patched vulnerability in replacement" | |
1192 | '() | |
571f6e7f | 1193 | (mock ((guix lint) package-vulnerabilities |
5c6a062d | 1194 | (lambda (package) |
79c03e55 LC |
1195 | (list (make-struct/no-tail (@@ (guix cve) <vulnerability>) |
1196 | "CVE-2015-1234" | |
1197 | (list (cons (package-name package) | |
1198 | (package-version package))))))) | |
50fc2384 CB |
1199 | (check-vulnerabilities |
1200 | (dummy-package | |
1201 | "pi" (version "3.14") (source (dummy-origin)) | |
1202 | (replacement (dummy-package | |
1203 | "pi" (version "3.14") | |
1204 | (source | |
1205 | (dummy-origin | |
1206 | (patches | |
1207 | (list "/a/b/pi-CVE-2015-1234.patch")))))))))) | |
1208 | ||
1209 | (test-equal "formatting: lonely parentheses" | |
1210 | "parentheses feel lonely, move to the previous or next line" | |
1211 | (single-lint-warning-message | |
1212 | (check-formatting | |
1213 | (dummy-package "ugly as hell!" | |
1214 | ) | |
1215 | ))) | |
e0566f12 | 1216 | |
40a7d4e5 | 1217 | (test-assert "formatting: tabulation" |
50fc2384 CB |
1218 | (string-match-or-error |
1219 | "tabulation on line [0-9]+, column [0-9]+" | |
1220 | (single-lint-warning-message | |
1221 | (check-formatting (dummy-package "leave the tab here: "))))) | |
40a7d4e5 LC |
1222 | |
1223 | (test-assert "formatting: trailing white space" | |
50fc2384 CB |
1224 | (string-match-or-error |
1225 | "trailing white space .*" | |
1226 | ;; Leave the trailing white space on the next line! | |
1227 | (single-lint-warning-message | |
1228 | (check-formatting (dummy-package "x"))))) | |
40a7d4e5 LC |
1229 | |
1230 | (test-assert "formatting: long line" | |
50fc2384 CB |
1231 | (string-match-or-error |
1232 | "line [0-9]+ is way too long \\([0-9]+ characters\\)" | |
1233 | (single-lint-warning-message (check-formatting | |
1234 | (dummy-package "x")) ;here is a stupid comment just to make a long line | |
1235 | ))) | |
1236 | ||
1237 | (test-equal "formatting: alright" | |
1238 | '() | |
1239 | (check-formatting (dummy-package "x"))) | |
40a7d4e5 | 1240 | |
55549c7b LC |
1241 | (test-assert "archival: missing content" |
1242 | (let* ((origin (origin | |
1243 | (method url-fetch) | |
1244 | (uri "http://example.org/foo.tgz") | |
1245 | (sha256 (make-bytevector 32)))) | |
bc4d81d2 LC |
1246 | (warnings (with-http-server '((404 "Not archived.") |
1247 | (404 "Not in Disarchive database.")) | |
55549c7b | 1248 | (parameterize ((%swh-base-url (%local-url))) |
bc4d81d2 LC |
1249 | (mock ((guix download) %disarchive-mirrors |
1250 | (list (%local-url))) | |
1251 | (check-archival (dummy-package "x" | |
1252 | (source origin)))))))) | |
55549c7b LC |
1253 | (warning-contains? "not archived" warnings))) |
1254 | ||
1255 | (test-equal "archival: content available" | |
1256 | '() | |
1257 | (let* ((origin (origin | |
1258 | (method url-fetch) | |
1259 | (uri "http://example.org/foo.tgz") | |
1260 | (sha256 (make-bytevector 32)))) | |
1261 | ;; https://archive.softwareheritage.org/api/1/content/ | |
1262 | (content "{ \"checksums\": {}, \"data_url\": \"xyz\", | |
1263 | \"length\": 42 }")) | |
1264 | (with-http-server `((200 ,content)) | |
1265 | (parameterize ((%swh-base-url (%local-url))) | |
1266 | (check-archival (dummy-package "x" (source origin))))))) | |
1267 | ||
bc4d81d2 LC |
1268 | (test-equal "archival: content unavailable but disarchive available" |
1269 | '() | |
1270 | (let* ((origin (origin | |
1271 | (method url-fetch) | |
1272 | (uri "http://example.org/foo.tgz") | |
1273 | (sha256 (make-bytevector 32)))) | |
1274 | (disarchive (object->string | |
1275 | '(disarchive (version 0) | |
1276 | ... | |
1277 | "swh:1:dir:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))) | |
1278 | ;; https://archive.softwareheritage.org/api/1/directory/ | |
1279 | (directory "[ { \"checksums\": {}, | |
1280 | \"dir_id\": \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\", | |
1281 | \"type\": \"file\", | |
1282 | \"name\": \"README\" | |
1283 | \"length\": 42 } ]")) | |
1284 | (with-http-server `((404 "") ;lookup-content | |
1285 | (200 ,disarchive) ;Disarchive database lookup | |
1286 | (200 ,directory)) ;lookup-directory | |
1287 | (mock ((guix download) %disarchive-mirrors (list (%local-url))) | |
1288 | (parameterize ((%swh-base-url (%local-url))) | |
1289 | (check-archival (dummy-package "x" (source origin)))))))) | |
1290 | ||
55549c7b LC |
1291 | (test-assert "archival: missing revision" |
1292 | (let* ((origin (origin | |
1293 | (method git-fetch) | |
1294 | (uri (git-reference | |
1295 | (url "http://example.org/foo.git") | |
1296 | (commit "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))) | |
1297 | (sha256 (make-bytevector 32)))) | |
1298 | ;; https://archive.softwareheritage.org/api/1/origin/save/ | |
1299 | (save "{ \"origin_url\": \"http://example.org/foo.git\", | |
1300 | \"save_request_date\": \"2014-11-17T22:09:38+01:00\", | |
1301 | \"save_request_status\": \"accepted\", | |
1302 | \"save_task_status\": \"scheduled\" }") | |
1303 | (warnings (with-http-server `((404 "No revision.") ;lookup-revision | |
1304 | (404 "No origin.") ;lookup-origin | |
1305 | (200 ,save)) ;save-origin | |
1306 | (parameterize ((%swh-base-url (%local-url))) | |
1307 | (check-archival (dummy-package "x" (source origin))))))) | |
1308 | (warning-contains? "scheduled" warnings))) | |
1309 | ||
1310 | (test-equal "archival: revision available" | |
1311 | '() | |
1312 | (let* ((origin (origin | |
1313 | (method git-fetch) | |
1314 | (uri (git-reference | |
1315 | (url "http://example.org/foo.git") | |
1316 | (commit "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))) | |
1317 | (sha256 (make-bytevector 32)))) | |
1318 | ;; https://archive.softwareheritage.org/api/1/revision/ | |
1319 | (revision "{ \"author\": {}, \"parents\": [], | |
1320 | \"date\": \"2014-11-17T22:09:38+01:00\" }")) | |
1321 | (with-http-server `((200 ,revision)) | |
1322 | (parameterize ((%swh-base-url (%local-url))) | |
1323 | (check-archival (dummy-package "x" (source origin))))))) | |
1324 | ||
1325 | (test-assert "archival: rate limit reached" | |
1326 | ;; We should get a single warning stating that the rate limit was reached, | |
1327 | ;; and nothing more, in particular no other HTTP requests. | |
1328 | (let* ((origin (origin | |
1329 | (method url-fetch) | |
1330 | (uri "http://example.org/foo.tgz") | |
1331 | (sha256 (make-bytevector 32)))) | |
1332 | (too-many (build-response | |
1333 | #:code 429 | |
1334 | #:reason-phrase "Too many requests" | |
1335 | #:headers '((x-ratelimit-remaining . "0") | |
1336 | (x-ratelimit-reset . "3000000000")))) | |
1337 | (warnings (with-http-server `((,too-many "Rate limit reached.")) | |
1338 | (parameterize ((%swh-base-url (%local-url))) | |
1339 | (append-map (lambda (name) | |
1340 | (check-archival | |
1341 | (dummy-package name (source origin)))) | |
1342 | '("x" "y" "z")))))) | |
1343 | (string-contains (single-lint-warning-message warnings) | |
1344 | "rate limit reached"))) | |
1345 | ||
464b1fff TS |
1346 | (test-assert "haskell-stackage" |
1347 | (let* ((stackage (string-append "{ \"packages\": [{" | |
50d24214 XC |
1348 | " \"name\":\"pandoc\"," |
1349 | " \"synopsis\":\"synopsis\"," | |
46d15af4 LC |
1350 | " \"version\":\"1.0\" }]," |
1351 | " \"snapshot\": {" | |
1352 | " \"ghc\": \"8.6.5\"," | |
1353 | " \"name\": \"lts-14.27\"" | |
1354 | " }}")) | |
464b1fff TS |
1355 | (packages (map (lambda (version) |
1356 | (dummy-package | |
50d24214 | 1357 | "ghc-pandoc" |
464b1fff TS |
1358 | (version version) |
1359 | (source | |
1360 | (dummy-origin | |
1361 | (method url-fetch) | |
1362 | (uri (string-append | |
1363 | "https://hackage.haskell.org/package/" | |
50d24214 XC |
1364 | "pandoc-" version "/pandoc-" version ".tar.gz")))))) |
1365 | '("0.9" "1.0" "100.0"))) | |
464b1fff | 1366 | (warnings (pk (with-http-server `((200 ,stackage) ; memoized |
50d24214 XC |
1367 | (200 "name: pandoc\nversion: 1.0\n") |
1368 | (200 "name: pandoc\nversion: 1.0\n") | |
1369 | (200 "name: pandoc\nversion: 1.0\n")) | |
464b1fff TS |
1370 | (parameterize ((%hackage-url (%local-url)) |
1371 | (%stackage-url (%local-url))) | |
1372 | (append-map check-haskell-stackage packages)))))) | |
1373 | (match warnings | |
1374 | (((? lint-warning? warning)) | |
50d24214 | 1375 | (and (string=? (package-version (lint-warning-package warning)) "100.0") |
464b1fff TS |
1376 | (string-contains (lint-warning-message warning) |
1377 | "ahead of Stackage LTS version")))))) | |
1378 | ||
b4f5e0e8 CR |
1379 | (test-end "lint") |
1380 | ||
907c98ac | 1381 | ;; Local Variables: |
9323ab55 | 1382 | ;; eval: (put 'with-http-server 'scheme-indent-function 1) |
4fbf4ca5 | 1383 | ;; eval: (put 'with-warnings 'scheme-indent-function 0) |
907c98ac | 1384 | ;; End: |