1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013 Cyril Roelandt <tipecaml@gmail.com>
3 ;;; Copyright © 2014, 2015, 2016 Eric Bavier <bavier@member.fsf.org>
4 ;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
5 ;;; Copyright © 2015, 2016 Mathieu Lirzin <mthl@gnu.org>
6 ;;; Copyright © 2016 Hartmut Goebel <h.goebel@crazy-compilers.com>
7 ;;; Copyright © 2017 Alex Kost <alezost@gmail.com>
8 ;;; Copyright © 2017 Efraim Flashner <efraim@flashner.co.il>
9 ;;; Copyright © 2018, 2019 Arun Isaac <arunisaac@systemreboot.net>
10 ;;; Copyright © 2020 Timothy Sample <samplet@ngyro.com>
11 ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
13 ;;; This file is part of GNU Guix.
15 ;;; GNU Guix is free software; you can redistribute it and/or modify it
16 ;;; under the terms of the GNU General Public License as published by
17 ;;; the Free Software Foundation; either version 3 of the License, or (at
18 ;;; your option) any later version.
20 ;;; GNU Guix is distributed in the hope that it will be useful, but
21 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;;; GNU General Public License for more details.
25 ;;; You should have received a copy of the GNU General Public License
26 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
28 ;; Avoid interference.
29 (unsetenv "http_proxy")
31 (define-module (test-lint)
32 #:use-module (guix tests)
33 #:use-module (guix tests http)
34 #:use-module (guix download)
35 #:use-module (guix git-download)
36 #:use-module (guix build-system gnu)
37 #:use-module (guix packages)
38 #:use-module (guix lint)
39 #:use-module (guix ui)
40 #:use-module (guix swh)
41 #:use-module ((guix gexp) #:select (local-file))
42 #:use-module ((guix utils) #:select (call-with-temporary-directory))
43 #:use-module ((guix import hackage) #:select (%hackage-url))
44 #:use-module ((guix import stackage) #:select (%stackage-url))
45 #:use-module (gnu packages)
46 #:use-module (gnu packages glib)
47 #:use-module (gnu packages pkg-config)
48 #:use-module (gnu packages python-xyz)
49 #:use-module (web uri)
50 #:use-module (web server)
51 #:use-module (web server http)
52 #:use-module (web response)
53 #:use-module (ice-9 match)
54 #:use-module (ice-9 regex)
55 #:use-module (ice-9 getopt-long)
56 #:use-module (ice-9 pretty-print)
57 #:use-module (rnrs bytevectors)
58 #:use-module (srfi srfi-1)
59 #:use-module (srfi srfi-9 gnu)
60 #:use-module (srfi srfi-26)
61 #:use-module (srfi srfi-64))
66 ;; SHA256 of the empty string.
68 "0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73"))
71 (make-string 2000 #\a))
73 (define (string-match-or-error pattern str)
74 (or (string-match pattern str)
75 (error str "did not match" pattern)))
77 (define single-lint-warning-message
79 (((and (? lint-warning?) warning))
80 (lint-warning-message warning))))
82 (define (warning-contains? str warnings)
83 "Return true if WARNINGS is a singleton with a warning that contains STR."
85 (((? lint-warning? warning))
86 (string-contains (lint-warning-message warning) str))))
91 (test-equal "description: not a string"
92 "invalid description: foobar"
93 (single-lint-warning-message
94 (check-description-style
95 (dummy-package "x" (description 'foobar)))))
97 (test-equal "description: not empty"
98 "description should not be empty"
99 (single-lint-warning-message
100 (check-description-style
101 (dummy-package "x" (description "")))))
103 (test-equal "description: invalid Texinfo markup"
104 "Texinfo markup in description is invalid"
105 (single-lint-warning-message
106 (check-description-style
107 (dummy-package "x" (description "f{oo}b@r")))))
109 (test-equal "description: does not start with an upper-case letter"
110 "description should start with an upper-case letter or digit"
111 (single-lint-warning-message
112 (let ((pkg (dummy-package "x"
113 (description "bad description."))))
114 (check-description-style pkg))))
116 (test-equal "description: may start with a digit"
118 (let ((pkg (dummy-package "x"
119 (description "2-component library."))))
120 (check-description-style pkg)))
122 (test-equal "description: may start with lower-case package name"
124 (let ((pkg (dummy-package "x"
125 (description "x is a dummy package."))))
126 (check-description-style pkg)))
128 (test-equal "description: two spaces after end of sentence"
129 "sentences in description should be followed by two spaces; possible infraction at 3"
130 (single-lint-warning-message
131 (let ((pkg (dummy-package "x"
132 (description "Bad. Quite bad."))))
133 (check-description-style pkg))))
135 (test-equal "description: end-of-sentence detection with abbreviations"
137 (let ((pkg (dummy-package "x"
139 "E.g. Foo, i.e. Bar resp. Baz (a.k.a. DVD)."))))
140 (check-description-style pkg)))
142 (test-equal "description: may not contain trademark signs: ™"
143 "description should not contain trademark sign '™' at 20"
144 (single-lint-warning-message
145 (let ((pkg (dummy-package "x"
146 (description "Does The Right Thing™"))))
147 (check-description-style pkg))))
149 (test-equal "description: may not contain trademark signs: ®"
150 "description should not contain trademark sign '®' at 17"
151 (single-lint-warning-message
152 (let ((pkg (dummy-package "x"
153 (description "Works with Format®"))))
154 (check-description-style pkg))))
156 (test-equal "description: suggest ornament instead of quotes"
157 "use @code or similar ornament instead of quotes"
158 (single-lint-warning-message
159 (let ((pkg (dummy-package "x"
160 (description "This is a 'quoted' thing."))))
161 (check-description-style pkg))))
163 (test-equal "synopsis: not a string"
164 "invalid synopsis: #f"
165 (single-lint-warning-message
166 (let ((pkg (dummy-package "x"
168 (check-synopsis-style pkg))))
170 (test-equal "synopsis: not empty"
171 "synopsis should not be empty"
172 (single-lint-warning-message
173 (let ((pkg (dummy-package "x"
175 (check-synopsis-style pkg))))
177 (test-equal "synopsis: valid Texinfo markup"
178 "Texinfo markup in synopsis is invalid"
179 (single-lint-warning-message
180 (check-synopsis-style
181 (dummy-package "x" (synopsis "Bad $@ texinfo")))))
183 (test-equal "synopsis: does not start with an upper-case letter"
184 "synopsis should start with an upper-case letter or digit"
185 (single-lint-warning-message
186 (let ((pkg (dummy-package "x"
187 (synopsis "bad synopsis"))))
188 (check-synopsis-style pkg))))
190 (test-equal "synopsis: may start with a digit"
192 (let ((pkg (dummy-package "x"
193 (synopsis "5-dimensional frobnicator"))))
194 (check-synopsis-style pkg)))
196 (test-equal "synopsis: ends with a period"
197 "no period allowed at the end of the synopsis"
198 (single-lint-warning-message
199 (let ((pkg (dummy-package "x"
200 (synopsis "Bad synopsis."))))
201 (check-synopsis-style pkg))))
203 (test-equal "synopsis: ends with 'etc.'"
205 (let ((pkg (dummy-package "x"
206 (synopsis "Foo, bar, etc."))))
207 (check-synopsis-style pkg)))
209 (test-equal "synopsis: starts with 'A'"
210 "no article allowed at the beginning of the synopsis"
211 (single-lint-warning-message
212 (let ((pkg (dummy-package "x"
213 (synopsis "A bad synopŝis"))))
214 (check-synopsis-style pkg))))
216 (test-equal "synopsis: starts with 'An'"
217 "no article allowed at the beginning of the synopsis"
218 (single-lint-warning-message
219 (let ((pkg (dummy-package "x"
220 (synopsis "An awful synopsis"))))
221 (check-synopsis-style pkg))))
223 (test-equal "synopsis: starts with 'a'"
224 '("no article allowed at the beginning of the synopsis"
225 "synopsis should start with an upper-case letter or digit")
229 (let ((pkg (dummy-package "x"
230 (synopsis "a bad synopsis"))))
231 (check-synopsis-style pkg)))
234 (test-equal "synopsis: starts with 'an'"
235 '("no article allowed at the beginning of the synopsis"
236 "synopsis should start with an upper-case letter or digit")
240 (let ((pkg (dummy-package "x"
241 (synopsis "an awful synopsis"))))
242 (check-synopsis-style pkg)))
245 (test-equal "synopsis: too long"
246 "synopsis should be less than 80 characters long"
247 (single-lint-warning-message
248 (let ((pkg (dummy-package "x"
249 (synopsis (make-string 80 #\X)))))
250 (check-synopsis-style pkg))))
252 (test-equal "synopsis: start with package name"
253 "synopsis should not start with the package name"
254 (single-lint-warning-message
255 (let ((pkg (dummy-package "x"
257 (synopsis "Foo, a nice package"))))
258 (check-synopsis-style pkg))))
260 (test-equal "synopsis: start with package name prefix"
262 (let ((pkg (dummy-package "arb"
263 (synopsis "Arbitrary precision"))))
264 (check-synopsis-style pkg)))
266 (test-equal "synopsis: start with abbreviation"
268 (let ((pkg (dummy-package "uucp"
269 ;; Same problem with "APL interpreter", etc.
270 (synopsis "UUCP implementation")
271 (description "Imagine this is Taylor UUCP."))))
272 (check-synopsis-style pkg)))
274 (test-equal "synopsis: contains trailing whitespace"
275 "synopsis contains trailing whitespace"
276 (single-lint-warning-message
277 (let ((pkg (dummy-package "x"
278 (synopsis "Whitespace "))))
279 (check-synopsis-style pkg))))
281 (test-equal "name: use underscore in package name"
282 "name should use hyphens instead of underscores"
283 (single-lint-warning-message
284 (let ((pkg (dummy-package "under_score")))
287 (test-equal "tests-true: #:tests? must not be set to #t"
288 "#:tests? must not be explicitly set to #t"
289 (single-lint-warning-message
290 (let ((pkg (dummy-package "x" (arguments '(#:tests? #t)))))
291 (check-tests-true pkg))))
293 (test-equal "tests-true: absent #:tests? is acceptable"
295 (let ((pkg (dummy-package "x")))
296 (check-tests-true pkg)))
298 (test-equal "tests-true: #:tests? #f is acceptable"
300 (let ((pkg (dummy-package "x" (arguments '(#:tests? #f)))))
301 (check-tests-true pkg)))
303 (test-equal "tests-true: #:tests? #t acceptable when compiling natively"
305 (let ((pkg (dummy-package "x"
307 `(#:tests? ,(not (%current-target-system)))))))
308 (check-tests-true pkg)))
310 (test-equal "inputs: pkg-config is probably a native input"
311 "'pkg-config' should probably be a native input"
312 (single-lint-warning-message
313 (let ((pkg (dummy-package "x"
314 (inputs `(("pkg-config" ,pkg-config))))))
315 (check-inputs-should-be-native pkg))))
317 (test-equal "inputs: glib:bin is probably a native input"
318 "'glib:bin' should probably be a native input"
319 (single-lint-warning-message
320 (let ((pkg (dummy-package "x"
321 (inputs `(("glib" ,glib "bin"))))))
322 (check-inputs-should-be-native pkg))))
325 "inputs: python-setuptools should not be an input at all (input)"
326 "'python-setuptools' should probably not be an input at all"
327 (single-lint-warning-message
328 (let ((pkg (dummy-package "x"
329 (inputs `(("python-setuptools"
330 ,python-setuptools))))))
331 (check-inputs-should-not-be-an-input-at-all pkg))))
334 "inputs: python-setuptools should not be an input at all (native-input)"
335 "'python-setuptools' should probably not be an input at all"
336 (single-lint-warning-message
337 (let ((pkg (dummy-package "x"
339 `(("python-setuptools"
340 ,python-setuptools))))))
341 (check-inputs-should-not-be-an-input-at-all pkg))))
344 "inputs: python-setuptools should not be an input at all (propagated-input)"
345 "'python-setuptools' should probably not be an input at all"
346 (single-lint-warning-message
347 (let ((pkg (dummy-package "x"
349 `(("python-setuptools" ,python-setuptools))))))
350 (check-inputs-should-not-be-an-input-at-all pkg))))
352 (test-equal "file patches: different file name -> warning"
353 "file names of patches should start with the package name"
354 (single-lint-warning-message
355 (let ((pkg (dummy-package "x"
358 (patches (list "/path/to/y.patch")))))))
359 (check-patch-file-names pkg))))
361 (test-equal "file patches: same file name -> no warnings"
363 (let ((pkg (dummy-package "x"
366 (patches (list "/path/to/x.patch")))))))
367 (check-patch-file-names pkg)))
369 (test-equal "<origin> patches: different file name -> warning"
370 "file names of patches should start with the package name"
371 (single-lint-warning-message
372 (let ((pkg (dummy-package "x"
378 (file-name "y.patch")))))))))
379 (check-patch-file-names pkg))))
381 (test-equal "<origin> patches: same file name -> no warnings"
383 (let ((pkg (dummy-package "x"
389 (file-name "x.patch")))))))))
390 (check-patch-file-names pkg)))
392 (test-equal "patches: file name too long"
394 (make-string 100 #\a)
395 ".patch: file name is too long")
396 (single-lint-warning-message
397 (let ((pkg (dummy-package
401 (patches (list (string-append "x-"
402 (make-string 100 #\a)
404 (check-patch-file-names pkg))))
406 (test-equal "patches: not found"
407 "this-patch-does-not-exist!: patch not found\n"
408 (single-lint-warning-message
409 (let ((pkg (dummy-package
414 (list (search-patch "this-patch-does-not-exist!"))))))))
415 (check-patch-file-names pkg))))
417 (test-assert "patch headers: no warnings"
418 (call-with-temporary-directory
420 (call-with-output-file (string-append directory "/t.patch")
422 (display "This is a patch.\n\n--- a\n+++ b\n"
425 (parameterize ((%patch-path (list directory)))
426 (let ((pkg (dummy-package "x"
427 (source (dummy-origin
428 (patches (search-patches "t.patch")))))))
429 (null? (check-patch-headers pkg)))))))
431 (test-equal "patch headers: missing comment"
432 "t.patch: patch lacks comment and upstream status"
433 (call-with-temporary-directory
435 (call-with-output-file (string-append directory "/t.patch")
437 (display "\n--- a\n+++ b\n"
440 (parameterize ((%patch-path (list directory)))
441 (let ((pkg (dummy-package "x"
442 (source (dummy-origin
443 (patches (search-patches "t.patch")))))))
444 (single-lint-warning-message (check-patch-headers pkg)))))))
446 (test-equal "patch headers: empty"
447 "t.patch: empty patch"
448 (call-with-temporary-directory
450 (call-with-output-file (string-append directory "/t.patch")
453 (parameterize ((%patch-path '()))
454 (let ((pkg (dummy-package "x"
455 (source (dummy-origin
458 (string-append directory
460 (single-lint-warning-message (check-patch-headers pkg)))))))
462 (test-equal "patch headers: patch not found"
463 "does-not-exist.patch: patch not found\n"
464 (parameterize ((%patch-path '()))
465 (let ((pkg (dummy-package "x"
466 (source (dummy-origin
468 (search-patches "does-not-exist.patch")))))))
469 (single-lint-warning-message (check-patch-headers pkg)))))
471 (test-equal "derivation: invalid arguments"
472 "failed to create x86_64-linux derivation: (wrong-type-arg \"map\" \"Wrong type argument: ~S\" (invalid-module) ())"
473 (match (let ((pkg (dummy-package "x"
475 '(#:imported-modules (invalid-module))))))
476 (check-derivation pkg))
477 (((and (? lint-warning?) first-warning) others ...)
478 (lint-warning-message first-warning))))
480 (test-equal "profile-collisions: no warnings"
482 (check-profile-collisions (dummy-package "x")))
484 (test-equal "profile-collisions: propagated inputs collide"
485 "propagated inputs p0@1 and p0@2 collide"
486 (let* ((p0 (dummy-package "p0" (version "1")))
487 (p0* (dummy-package "p0" (version "2")))
488 (p1 (dummy-package "p1" (propagated-inputs `(("p0" ,p0)))))
489 (p2 (dummy-package "p2" (propagated-inputs `(("p1" ,p1)))))
490 (p3 (dummy-package "p3" (propagated-inputs `(("p0" ,p0*)))))
491 (p4 (dummy-package "p4" (propagated-inputs
492 `(("p2" ,p2) ("p3", p3))))))
493 (single-lint-warning-message
494 (check-profile-collisions p4))))
496 (test-assert "profile-collisions: propagated inputs collide, store items"
497 (string-match-or-error
498 "propagated inputs /[[:graph:]]+-p0-1 and /[[:graph:]]+-p0-1 collide"
499 (let* ((p0 (dummy-package "p0" (version "1")))
500 (p0* (dummy-package "p0" (version "1")
501 (inputs `(("x" ,(dummy-package "x"))))))
502 (p1 (dummy-package "p1" (propagated-inputs `(("p0" ,p0)))))
503 (p2 (dummy-package "p2" (propagated-inputs `(("p1" ,p1)))))
504 (p3 (dummy-package "p3" (propagated-inputs `(("p0" ,p0*)))))
505 (p4 (dummy-package "p4" (propagated-inputs
506 `(("p2" ,p2) ("p3", p3))))))
507 (single-lint-warning-message
508 (check-profile-collisions p4)))))
510 (test-equal "license: invalid license"
511 "invalid license field"
512 (single-lint-warning-message
513 (check-license (dummy-package "x" (license #f)))))
515 (test-equal "home-page: wrong home-page"
516 "invalid value for home page"
518 (inherit (dummy-package "x"))
520 (single-lint-warning-message
521 (check-home-page pkg))))
523 (test-equal "home-page: invalid URI"
524 "invalid home page URL: \"foobar\""
526 (inherit (dummy-package "x"))
527 (home-page "foobar"))))
528 (single-lint-warning-message
529 (check-home-page pkg))))
531 (test-assert "home-page: host not found"
533 (inherit (dummy-package "x"))
534 (home-page "http://does-not-exist"))))
535 (warning-contains? "domain not found" (check-home-page pkg))))
537 (parameterize ((%http-server-port 9999))
538 ;; TODO skip this test if some process is currently listening at 9999
539 (test-equal "home-page: Connection refused"
540 "URI http://localhost:9999/foo/bar unreachable: Connection refused"
542 (inherit (dummy-package "x"))
543 (home-page (%local-url)))))
544 (single-lint-warning-message
545 (check-home-page pkg)))))
547 (test-equal "home-page: 200"
549 (with-http-server `((200 ,%long-string))
551 (inherit (dummy-package "x"))
552 (home-page (%local-url)))))
553 (check-home-page pkg))))
555 (with-http-server `((200 "This is too small."))
556 (test-equal "home-page: 200 but short length"
557 (format #f "URI ~a returned suspiciously small file (18 bytes)"
560 (inherit (dummy-package "x"))
561 (home-page (%local-url)))))
563 (single-lint-warning-message
564 (check-home-page pkg)))))
566 (with-http-server `((404 ,%long-string))
567 (test-equal "home-page: 404"
568 (format #f "URI ~a not reachable: 404 (\"Such is life\")" (%local-url))
570 (inherit (dummy-package "x"))
571 (home-page (%local-url)))))
572 (single-lint-warning-message
573 (check-home-page pkg)))))
575 (with-http-server `((301 ,%long-string))
576 (test-equal "home-page: 301, invalid"
577 (format #f "invalid permanent redirect from ~a" (%local-url))
579 (inherit (dummy-package "x"))
580 (home-page (%local-url)))))
581 (single-lint-warning-message
582 (check-home-page pkg)))))
584 (with-http-server `((200 ,%long-string))
585 (let* ((initial-url (%local-url))
586 (redirect (build-response #:code 301
589 . ,(string->uri initial-url))))))
590 (parameterize ((%http-server-port 0))
591 (with-http-server `((,redirect ""))
592 (test-equal "home-page: 301 -> 200"
593 (format #f "permanent redirect from ~a to ~a"
594 (%local-url) initial-url)
596 (inherit (dummy-package "x"))
597 (home-page (%local-url)))))
598 (single-lint-warning-message
599 (check-home-page pkg))))))))
601 (with-http-server `((404 "booh!"))
602 (let* ((initial-url (%local-url))
603 (redirect (build-response #:code 301
606 . ,(string->uri initial-url))))))
607 (parameterize ((%http-server-port 0))
608 (with-http-server `((,redirect ""))
609 (test-equal "home-page: 301 -> 404"
610 (format #f "URI ~a not reachable: 404 (\"Such is life\")" (%local-url))
612 (inherit (dummy-package "x"))
613 (home-page (%local-url)))))
614 (single-lint-warning-message
615 (check-home-page pkg))))))))
618 (test-equal "source-file-name"
619 "the source file name should contain the package name"
620 (let ((pkg (dummy-package "x"
625 (uri "http://www.example.com/3.2.1.tar.gz")
626 (sha256 %null-sha256))))))
627 (single-lint-warning-message
628 (check-source-file-name pkg))))
630 (test-equal "source-file-name: v prefix"
631 "the source file name should contain the package name"
632 (let ((pkg (dummy-package "x"
637 (uri "http://www.example.com/v3.2.1.tar.gz")
638 (sha256 %null-sha256))))))
639 (single-lint-warning-message
640 (check-source-file-name pkg))))
642 (test-equal "source-file-name: bad checkout"
643 "the source file name should contain the package name"
644 (let ((pkg (dummy-package "x"
650 (url "http://www.example.com/x.git")
652 (sha256 %null-sha256))))))
653 (single-lint-warning-message
654 (check-source-file-name pkg))))
656 (test-equal "source-file-name: good checkout"
658 (let ((pkg (dummy-package "x"
664 (url "http://git.example.com/x.git")
666 (file-name (string-append "x-" version))
667 (sha256 %null-sha256))))))
668 (check-source-file-name pkg)))
670 (test-equal "source-file-name: valid"
672 (let ((pkg (dummy-package "x"
677 (uri "http://www.example.com/x-3.2.1.tar.gz")
678 (sha256 %null-sha256))))))
679 (check-source-file-name pkg)))
681 (test-equal "source-unstable-tarball"
682 "the source URI should not be an autogenerated tarball"
683 (let ((pkg (dummy-package "x"
687 (uri "https://github.com/example/example/archive/v0.0.tar.gz")
688 (sha256 %null-sha256))))))
689 (single-lint-warning-message
690 (check-source-unstable-tarball pkg))))
692 (test-equal "source-unstable-tarball: source #f"
694 (let ((pkg (dummy-package "x"
696 (check-source-unstable-tarball pkg)))
698 (test-equal "source-unstable-tarball: valid"
700 (let ((pkg (dummy-package "x"
704 (uri "https://github.com/example/example/releases/download/x-0.0/x-0.0.tar.gz")
705 (sha256 %null-sha256))))))
706 (check-source-unstable-tarball pkg)))
708 (test-equal "source-unstable-tarball: package named archive"
710 (let ((pkg (dummy-package "x"
714 (uri "https://github.com/example/archive/releases/download/x-0.0/x-0.0.tar.gz")
715 (sha256 %null-sha256))))))
716 (check-source-unstable-tarball pkg)))
718 (test-equal "source-unstable-tarball: not-github"
720 (let ((pkg (dummy-package "x"
724 (uri "https://bitbucket.org/archive/example/download/x-0.0.tar.gz")
725 (sha256 %null-sha256))))))
726 (check-source-unstable-tarball pkg)))
728 (test-equal "source-unstable-tarball: git-fetch"
730 (let ((pkg (dummy-package "x"
735 (url "https://github.com/archive/example")
737 (sha256 %null-sha256))))))
738 (check-source-unstable-tarball pkg)))
740 (test-equal "source: 200"
742 (with-http-server `((200 ,%long-string))
744 (inherit (dummy-package "x"))
748 (sha256 %null-sha256))))))
749 (check-source pkg))))
751 (with-http-server '((200 "This is too small."))
752 (test-equal "source: 200 but short length"
753 (format #f "URI ~a returned suspiciously small file (18 bytes)"
756 (inherit (dummy-package "x"))
760 (sha256 %null-sha256))))))
761 (match (check-source pkg)
762 ((first-warning ; All source URIs are unreachable
763 (and (? lint-warning?) second-warning))
764 (lint-warning-message second-warning))))))
766 (with-http-server `((404 ,%long-string))
767 (test-equal "source: 404"
768 (format #f "URI ~a not reachable: 404 (\"Such is life\")"
771 (inherit (dummy-package "x"))
775 (sha256 %null-sha256))))))
776 (match (check-source pkg)
777 ((first-warning ; All source URIs are unreachable
778 (and (? lint-warning?) second-warning))
779 (lint-warning-message second-warning))))))
781 (test-equal "source: 404 and 200"
783 (with-http-server `((404 ,%long-string))
784 (let ((bad-url (%local-url)))
785 (parameterize ((%http-server-port (+ 1 (%http-server-port))))
786 (with-http-server `((200 ,%long-string))
788 (inherit (dummy-package "x"))
791 (uri (list bad-url (%local-url)))
792 (sha256 %null-sha256))))))
793 ;; Since one of the two URLs is good, this should return the empty
795 (check-source pkg)))))))
797 (with-http-server `((200 ,%long-string))
798 (let* ((initial-url (%local-url))
799 (redirect (build-response #:code 301
802 . ,(string->uri initial-url))))))
803 (parameterize ((%http-server-port 0))
804 (with-http-server `((,redirect ""))
805 (test-equal "source: 301 -> 200"
806 (format #f "permanent redirect from ~a to ~a"
807 (%local-url) initial-url)
809 (inherit (dummy-package "x"))
813 (sha256 %null-sha256))))))
814 (match (check-source pkg)
815 ((first-warning ; All source URIs are unreachable
816 (and (? lint-warning?) second-warning))
817 (lint-warning-message second-warning)))))))))
819 (with-http-server `((200 ,%long-string))
820 (let* ((initial-url (%local-url))
821 (redirect (build-response #:code 301
824 . ,(string->uri initial-url))))))
825 (parameterize ((%http-server-port 0))
826 (with-http-server `((,redirect ""))
827 (test-equal "source, git-reference: 301 -> 200"
828 (format #f "permanent redirect from ~a to ~a"
829 (%local-url) initial-url)
830 (let ((pkg (dummy-package
834 (uri (git-reference (url (%local-url))
836 (sha256 %null-sha256))))))
837 (single-lint-warning-message (check-source pkg))))))))
839 (with-http-server '((404 "booh!"))
840 (let* ((initial-url (%local-url))
841 (redirect (build-response #:code 301
844 . ,(string->uri initial-url))))))
845 (parameterize ((%http-server-port 0))
846 (with-http-server `((,redirect ""))
847 (test-equal "source: 301 -> 404"
848 (format #f "URI ~a not reachable: 404 (\"Such is life\")"
851 (inherit (dummy-package "x"))
855 (sha256 %null-sha256))))))
856 (match (check-source pkg)
857 ((first-warning ; The first warning says that all URI's are
859 (and (? lint-warning?) second-warning))
860 (lint-warning-message second-warning)))))))))
862 (test-equal "mirror-url"
864 (let ((source (origin
866 (uri "http://example.org/foo/bar.tar.gz")
867 (sha256 %null-sha256))))
868 (check-mirror-url (dummy-package "x" (source source)))))
870 (test-equal "mirror-url: one suggestion"
871 "URL should be 'mirror://gnu/foo/foo.tar.gz'"
872 (let ((source (origin
874 (uri "http://ftp.gnu.org/pub/gnu/foo/foo.tar.gz")
875 (sha256 %null-sha256))))
876 (single-lint-warning-message
877 (check-mirror-url (dummy-package "x" (source source))))))
879 (test-equal "github-url"
881 (with-http-server `((200 ,%long-string))
883 (dummy-package "x" (source
887 (sha256 %null-sha256)))))))
889 (let ((github-url "https://github.com/foo/bar/bar-1.0.tar.gz"))
890 (test-equal "github-url: one suggestion"
892 "URL should be '" github-url "'")
893 (let ((redirect (build-response #:code 301
896 . ,(string->uri github-url))))))
897 (with-http-server `((,redirect ""))
898 (let* ((initial-url (%local-url))
899 (redirect (build-response #:code 302
902 . ,(string->uri initial-url))))))
903 (parameterize ((%http-server-port 0))
904 (with-http-server `((,redirect ""))
905 (single-lint-warning-message
907 (dummy-package "x" (source
911 (sha256 %null-sha256))))))))))))
913 (test-equal "github-url: already the correct github url"
916 (dummy-package "x" (source
920 (sha256 %null-sha256)))))))
924 (mock ((guix lint) package-vulnerabilities (const '()))
925 (check-vulnerabilities (dummy-package "x"))))
927 (test-equal "cve: one vulnerability"
928 "probably vulnerable to CVE-2015-1234"
929 (let ((dummy-vulnerabilities
931 (list (make-struct/no-tail
932 (@@ (guix cve) <vulnerability>)
934 (list (cons (package-name package)
935 (package-version package))))))))
936 (single-lint-warning-message
937 (check-vulnerabilities (dummy-package "pi" (version "3.14"))
938 dummy-vulnerabilities))))
940 (test-equal "cve: one patched vulnerability"
942 (mock ((guix lint) package-vulnerabilities
944 (list (make-struct/no-tail (@@ (guix cve) <vulnerability>)
946 (list (cons (package-name package)
947 (package-version package)))))))
948 (check-vulnerabilities
954 (list "/a/b/pi-CVE-2015-1234.patch"))))))))
956 (test-equal "cve: known safe from vulnerability"
958 (mock ((guix lint) package-vulnerabilities
960 (list (make-struct/no-tail (@@ (guix cve) <vulnerability>)
962 (list (cons (package-name package)
963 (package-version package)))))))
964 (check-vulnerabilities
967 (properties `((lint-hidden-cve . ("CVE-2015-1234"))))))))
969 (test-equal "cve: vulnerability fixed in replacement version"
971 (mock ((guix lint) package-vulnerabilities
973 (match (package-version package)
975 (list (make-struct/no-tail (@@ (guix cve) <vulnerability>)
977 (list (cons (package-name package)
978 (package-version package))))))
981 (check-vulnerabilities
984 (replacement (dummy-package "foo" (version "1")))))))
986 (test-equal "cve: patched vulnerability in replacement"
988 (mock ((guix lint) package-vulnerabilities
990 (list (make-struct/no-tail (@@ (guix cve) <vulnerability>)
992 (list (cons (package-name package)
993 (package-version package)))))))
994 (check-vulnerabilities
996 "pi" (version "3.14") (source (dummy-origin))
997 (replacement (dummy-package
998 "pi" (version "3.14")
1002 (list "/a/b/pi-CVE-2015-1234.patch"))))))))))
1004 (test-equal "formatting: lonely parentheses"
1005 "parentheses feel lonely, move to the previous or next line"
1006 (single-lint-warning-message
1008 (dummy-package "ugly as hell!"
1012 (test-assert "formatting: tabulation"
1013 (string-match-or-error
1014 "tabulation on line [0-9]+, column [0-9]+"
1015 (single-lint-warning-message
1016 (check-formatting (dummy-package "leave the tab here: ")))))
1018 (test-assert "formatting: trailing white space"
1019 (string-match-or-error
1020 "trailing white space .*"
1021 ;; Leave the trailing white space on the next line!
1022 (single-lint-warning-message
1023 (check-formatting (dummy-package "x")))))
1025 (test-assert "formatting: long line"
1026 (string-match-or-error
1027 "line [0-9]+ is way too long \\([0-9]+ characters\\)"
1028 (single-lint-warning-message (check-formatting
1029 (dummy-package "x")) ;here is a stupid comment just to make a long line
1032 (test-equal "formatting: alright"
1034 (check-formatting (dummy-package "x")))
1036 (test-assert "archival: missing content"
1037 (let* ((origin (origin
1039 (uri "http://example.org/foo.tgz")
1040 (sha256 (make-bytevector 32))))
1041 (warnings (with-http-server '((404 "Not archived.")
1042 (404 "Not in Disarchive database."))
1043 (parameterize ((%swh-base-url (%local-url)))
1044 (mock ((guix download) %disarchive-mirrors
1045 (list (%local-url)))
1046 (check-archival (dummy-package "x"
1047 (source origin))))))))
1048 (warning-contains? "not archived" warnings)))
1050 (test-equal "archival: content available"
1052 (let* ((origin (origin
1054 (uri "http://example.org/foo.tgz")
1055 (sha256 (make-bytevector 32))))
1056 ;; https://archive.softwareheritage.org/api/1/content/
1057 (content "{ \"checksums\": {}, \"data_url\": \"xyz\",
1059 (with-http-server `((200 ,content))
1060 (parameterize ((%swh-base-url (%local-url)))
1061 (check-archival (dummy-package "x" (source origin)))))))
1063 (test-equal "archival: content unavailable but disarchive available"
1065 (let* ((origin (origin
1067 (uri "http://example.org/foo.tgz")
1068 (sha256 (make-bytevector 32))))
1069 (disarchive (object->string
1070 '(disarchive (version 0)
1072 "swh:1:dir:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")))
1073 ;; https://archive.softwareheritage.org/api/1/directory/
1074 (directory "[ { \"checksums\": {},
1075 \"dir_id\": \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
1077 \"name\": \"README\"
1078 \"length\": 42 } ]"))
1079 (with-http-server `((404 "") ;lookup-content
1080 (200 ,disarchive) ;Disarchive database lookup
1081 (200 ,directory)) ;lookup-directory
1082 (mock ((guix download) %disarchive-mirrors (list (%local-url)))
1083 (parameterize ((%swh-base-url (%local-url)))
1084 (check-archival (dummy-package "x" (source origin))))))))
1086 (test-assert "archival: missing revision"
1087 (let* ((origin (origin
1090 (url "http://example.org/foo.git")
1091 (commit "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")))
1092 (sha256 (make-bytevector 32))))
1093 ;; https://archive.softwareheritage.org/api/1/origin/save/
1094 (save "{ \"origin_url\": \"http://example.org/foo.git\",
1095 \"save_request_date\": \"2014-11-17T22:09:38+01:00\",
1096 \"save_request_status\": \"accepted\",
1097 \"save_task_status\": \"scheduled\" }")
1098 (warnings (with-http-server `((404 "No revision.") ;lookup-revision
1099 (404 "No origin.") ;lookup-origin
1100 (200 ,save)) ;save-origin
1101 (parameterize ((%swh-base-url (%local-url)))
1102 (check-archival (dummy-package "x" (source origin)))))))
1103 (warning-contains? "scheduled" warnings)))
1105 (test-equal "archival: revision available"
1107 (let* ((origin (origin
1110 (url "http://example.org/foo.git")
1111 (commit "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")))
1112 (sha256 (make-bytevector 32))))
1113 ;; https://archive.softwareheritage.org/api/1/revision/
1114 (revision "{ \"author\": {}, \"parents\": [],
1115 \"date\": \"2014-11-17T22:09:38+01:00\" }"))
1116 (with-http-server `((200 ,revision))
1117 (parameterize ((%swh-base-url (%local-url)))
1118 (check-archival (dummy-package "x" (source origin)))))))
1120 (test-assert "archival: rate limit reached"
1121 ;; We should get a single warning stating that the rate limit was reached,
1122 ;; and nothing more, in particular no other HTTP requests.
1123 (let* ((origin (origin
1125 (uri "http://example.org/foo.tgz")
1126 (sha256 (make-bytevector 32))))
1127 (too-many (build-response
1129 #:reason-phrase "Too many requests"
1130 #:headers '((x-ratelimit-remaining . "0")
1131 (x-ratelimit-reset . "3000000000"))))
1132 (warnings (with-http-server `((,too-many "Rate limit reached."))
1133 (parameterize ((%swh-base-url (%local-url)))
1134 (append-map (lambda (name)
1136 (dummy-package name (source origin))))
1138 (string-contains (single-lint-warning-message warnings)
1139 "rate limit reached")))
1141 (test-assert "haskell-stackage"
1142 (let* ((stackage (string-append "{ \"packages\": [{"
1144 " \"version\":\"1.0\" }]}"))
1145 (packages (map (lambda (version)
1147 (string-append "ghc-x")
1153 "https://hackage.haskell.org/package/"
1154 "x-" version "/x-" version ".tar.gz"))))))
1155 '("0.9" "1.0" "2.0")))
1156 (warnings (pk (with-http-server `((200 ,stackage) ; memoized
1157 (200 "name: x\nversion: 1.0\n")
1158 (200 "name: x\nversion: 1.0\n")
1159 (200 "name: x\nversion: 1.0\n"))
1160 (parameterize ((%hackage-url (%local-url))
1161 (%stackage-url (%local-url)))
1162 (append-map check-haskell-stackage packages))))))
1164 (((? lint-warning? warning))
1165 (and (string=? (package-version (lint-warning-package warning)) "2.0")
1166 (string-contains (lint-warning-message warning)
1167 "ahead of Stackage LTS version"))))))
1172 ;; eval: (put 'with-http-server 'scheme-indent-function 1)
1173 ;; eval: (put 'with-warnings 'scheme-indent-function 0)