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 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>
8 ;;; This file is part of GNU Guix.
10 ;;; GNU Guix is free software; you can redistribute it and/or modify it
11 ;;; under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 3 of the License, or (at
13 ;;; your option) any later version.
15 ;;; GNU Guix is distributed in the hope that it will be useful, but
16 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
23 ;; Avoid interference.
24 (unsetenv "http_proxy")
26 (define-module (test-lint)
27 #:use-module (guix tests)
28 #:use-module (guix tests http)
29 #:use-module (guix download)
30 #:use-module (guix git-download)
31 #:use-module (guix build-system gnu)
32 #:use-module (guix packages)
33 #:use-module (guix scripts lint)
34 #:use-module (guix ui)
35 #:use-module (gnu packages)
36 #:use-module (gnu packages glib)
37 #:use-module (gnu packages pkg-config)
38 #:use-module (gnu packages python)
39 #:use-module (web server)
40 #:use-module (web server http)
41 #:use-module (web response)
42 #:use-module (ice-9 match)
43 #:use-module (srfi srfi-9 gnu)
44 #:use-module (srfi srfi-64))
48 ;; Avoid collisions with other tests.
49 (%http-server-port 9999)
52 ;; SHA256 of the empty string.
54 "0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73"))
57 (make-string 2000 #\a))
62 (define (call-with-warnings thunk)
63 (let ((port (open-output-string)))
64 (parameterize ((guix-warning-port port))
66 (get-output-string port)))
68 (define-syntax-rule (with-warnings body ...)
69 (call-with-warnings (lambda () body ...)))
71 (test-assert "description: not a string"
73 (string-contains (with-warnings
74 (let ((pkg (dummy-package "x"
75 (description 'foobar))))
76 (check-description-style pkg)))
77 "invalid description")))
79 (test-assert "description: not empty"
81 (string-contains (with-warnings
82 (let ((pkg (dummy-package "x"
84 (check-description-style pkg)))
85 "description should not be empty")))
87 (test-assert "description: valid Texinfo markup"
91 (check-description-style (dummy-package "x" (description "f{oo}b@r"))))
92 "Texinfo markup in description is invalid")))
94 (test-assert "description: does not start with an upper-case letter"
96 (string-contains (with-warnings
97 (let ((pkg (dummy-package "x"
98 (description "bad description."))))
99 (check-description-style pkg)))
100 "description should start with an upper-case letter")))
102 (test-assert "description: may start with a digit"
105 (let ((pkg (dummy-package "x"
106 (description "2-component library."))))
107 (check-description-style pkg)))))
109 (test-assert "description: may start with lower-case package name"
112 (let ((pkg (dummy-package "x"
113 (description "x is a dummy package."))))
114 (check-description-style pkg)))))
116 (test-assert "description: two spaces after end of sentence"
118 (string-contains (with-warnings
119 (let ((pkg (dummy-package "x"
120 (description "Bad. Quite bad."))))
121 (check-description-style pkg)))
122 "sentences in description should be followed by two spaces")))
124 (test-assert "description: end-of-sentence detection with abbreviations"
127 (let ((pkg (dummy-package "x"
129 "E.g. Foo, i.e. Bar resp. Baz (a.k.a. DVD)."))))
130 (check-description-style pkg)))))
132 (test-assert "description: may not contain trademark signs"
134 (string-contains (with-warnings
135 (let ((pkg (dummy-package "x"
136 (description "Does The Right Thing™"))))
137 (check-description-style pkg)))
138 "should not contain trademark sign"))
140 (string-contains (with-warnings
141 (let ((pkg (dummy-package "x"
142 (description "Works with Format®"))))
143 (check-description-style pkg)))
144 "should not contain trademark sign"))))
146 (test-assert "description: suggest ornament instead of quotes"
148 (string-contains (with-warnings
149 (let ((pkg (dummy-package "x"
150 (description "This is a 'quoted' thing."))))
151 (check-description-style pkg)))
154 (test-assert "synopsis: not a string"
156 (string-contains (with-warnings
157 (let ((pkg (dummy-package "x"
159 (check-synopsis-style pkg)))
160 "invalid synopsis")))
162 (test-assert "synopsis: not empty"
164 (string-contains (with-warnings
165 (let ((pkg (dummy-package "x"
167 (check-synopsis-style pkg)))
168 "synopsis should not be empty")))
170 (test-assert "synopsis: does not start with an upper-case letter"
172 (string-contains (with-warnings
173 (let ((pkg (dummy-package "x"
174 (synopsis "bad synopsis."))))
175 (check-synopsis-style pkg)))
176 "synopsis should start with an upper-case letter")))
178 (test-assert "synopsis: may start with a digit"
181 (let ((pkg (dummy-package "x"
182 (synopsis "5-dimensional frobnicator"))))
183 (check-synopsis-style pkg)))))
185 (test-assert "synopsis: ends with a period"
187 (string-contains (with-warnings
188 (let ((pkg (dummy-package "x"
189 (synopsis "Bad synopsis."))))
190 (check-synopsis-style pkg)))
191 "no period allowed at the end of the synopsis")))
193 (test-assert "synopsis: ends with 'etc.'"
194 (string-null? (with-warnings
195 (let ((pkg (dummy-package "x"
196 (synopsis "Foo, bar, etc."))))
197 (check-synopsis-style pkg)))))
199 (test-assert "synopsis: starts with 'A'"
201 (string-contains (with-warnings
202 (let ((pkg (dummy-package "x"
203 (synopsis "A bad synopŝis"))))
204 (check-synopsis-style pkg)))
205 "no article allowed at the beginning of the synopsis")))
207 (test-assert "synopsis: starts with 'An'"
209 (string-contains (with-warnings
210 (let ((pkg (dummy-package "x"
211 (synopsis "An awful synopsis"))))
212 (check-synopsis-style pkg)))
213 "no article allowed at the beginning of the synopsis")))
215 (test-assert "synopsis: starts with 'a'"
217 (string-contains (with-warnings
218 (let ((pkg (dummy-package "x"
219 (synopsis "a bad synopsis"))))
220 (check-synopsis-style pkg)))
221 "no article allowed at the beginning of the synopsis")))
223 (test-assert "synopsis: starts with 'an'"
225 (string-contains (with-warnings
226 (let ((pkg (dummy-package "x"
227 (synopsis "an awful synopsis"))))
228 (check-synopsis-style pkg)))
229 "no article allowed at the beginning of the synopsis")))
231 (test-assert "synopsis: too long"
233 (string-contains (with-warnings
234 (let ((pkg (dummy-package "x"
235 (synopsis (make-string 80 #\x)))))
236 (check-synopsis-style pkg)))
237 "synopsis should be less than 80 characters long")))
239 (test-assert "synopsis: start with package name"
241 (string-contains (with-warnings
242 (let ((pkg (dummy-package "x"
244 (synopsis "foo, a nice package"))))
245 (check-synopsis-style pkg)))
246 "synopsis should not start with the package name")))
248 (test-assert "synopsis: start with package name prefix"
251 (let ((pkg (dummy-package "arb"
252 (synopsis "Arbitrary precision"))))
253 (check-synopsis-style pkg)))))
255 (test-assert "synopsis: start with abbreviation"
258 (let ((pkg (dummy-package "uucp"
259 ;; Same problem with "APL interpreter", etc.
260 (synopsis "UUCP implementation")
261 (description "Imagine this is Taylor UUCP."))))
262 (check-synopsis-style pkg)))))
264 (test-assert "inputs: pkg-config is probably a native input"
268 (let ((pkg (dummy-package "x"
269 (inputs `(("pkg-config" ,pkg-config))))))
270 (check-inputs-should-be-native pkg)))
271 "'pkg-config' should probably be a native input")))
273 (test-assert "inputs: glib:bin is probably a native input"
277 (let ((pkg (dummy-package "x"
278 (inputs `(("glib" ,glib "bin"))))))
279 (check-inputs-should-be-native pkg)))
280 "'glib:bin' should probably be a native input")))
283 "inputs: python-setuptools should not be an input at all (input)"
287 (let ((pkg (dummy-package "x"
288 (inputs `(("python-setuptools" ,python-setuptools))))))
289 (check-inputs-should-not-be-an-input-at-all pkg)))
290 "'python-setuptools' should probably not be an input at all")))
293 "inputs: python-setuptools should not be an input at all (native-input)"
297 (let ((pkg (dummy-package "x"
299 `(("python-setuptools" ,python-setuptools))))))
300 (check-inputs-should-not-be-an-input-at-all pkg)))
301 "'python-setuptools' should probably not be an input at all")))
304 "inputs: python-setuptools should not be an input at all (propagated-input)"
308 (let ((pkg (dummy-package "x"
310 `(("python-setuptools" ,python-setuptools))))))
311 (check-inputs-should-not-be-an-input-at-all pkg)))
312 "'python-setuptools' should probably not be an input at all")))
314 (test-assert "patches: file names"
318 (let ((pkg (dummy-package "x"
321 (patches (list "/path/to/y.patch")))))))
322 (check-patch-file-names pkg)))
323 "file names of patches should start with the package name")))
325 (test-assert "patches: not found"
329 (let ((pkg (dummy-package "x"
333 (list (search-patch "this-patch-does-not-exist!"))))))))
334 (check-patch-file-names pkg)))
337 (test-assert "derivation: invalid arguments"
341 (let ((pkg (dummy-package "x"
343 '(#:imported-modules (invalid-module))))))
344 (check-derivation pkg)))
345 "failed to create derivation")))
347 (test-assert "license: invalid license"
350 (check-license (dummy-package "x" (license #f))))
353 (test-assert "home-page: wrong home-page"
358 (inherit (dummy-package "x"))
360 (check-home-page pkg)))
363 (test-assert "home-page: invalid URI"
368 (inherit (dummy-package "x"))
369 (home-page "foobar"))))
370 (check-home-page pkg)))
371 "invalid home page URL")))
373 (test-assert "home-page: host not found"
378 (inherit (dummy-package "x"))
379 (home-page "http://does-not-exist"))))
380 (check-home-page pkg)))
381 "domain not found")))
383 (test-skip (if (force %http-server-socket) 0 1))
384 (test-assert "home-page: Connection refused"
389 (inherit (dummy-package "x"))
390 (home-page (%local-url)))))
391 (check-home-page pkg)))
392 "Connection refused")))
394 (test-skip (if (force %http-server-socket) 0 1))
395 (test-equal "home-page: 200"
398 (with-http-server 200 %long-string
400 (inherit (dummy-package "x"))
401 (home-page (%local-url)))))
402 (check-home-page pkg)))))
404 (test-skip (if (force %http-server-socket) 0 1))
405 (test-assert "home-page: 200 but short length"
409 (with-http-server 200 "This is too small."
411 (inherit (dummy-package "x"))
412 (home-page (%local-url)))))
413 (check-home-page pkg))))
414 "suspiciously small")))
416 (test-skip (if (force %http-server-socket) 0 1))
417 (test-assert "home-page: 404"
421 (with-http-server 404 %long-string
423 (inherit (dummy-package "x"))
424 (home-page (%local-url)))))
425 (check-home-page pkg))))
426 "not reachable: 404")))
428 (test-assert "source-file-name"
432 (let ((pkg (dummy-package "x"
437 (uri "http://www.example.com/3.2.1.tar.gz")
438 (sha256 %null-sha256))))))
439 (check-source-file-name pkg)))
440 "file name should contain the package name")))
442 (test-assert "source-file-name: v prefix"
446 (let ((pkg (dummy-package "x"
451 (uri "http://www.example.com/v3.2.1.tar.gz")
452 (sha256 %null-sha256))))))
453 (check-source-file-name pkg)))
454 "file name should contain the package name")))
456 (test-assert "source-file-name: bad checkout"
460 (let ((pkg (dummy-package "x"
466 (url "http://www.example.com/x.git")
468 (sha256 %null-sha256))))))
469 (check-source-file-name pkg)))
470 "file name should contain the package name")))
472 (test-assert "source-file-name: good checkout"
477 (let ((pkg (dummy-package "x"
483 (url "http://git.example.com/x.git")
485 (file-name (string-append "x-" version))
486 (sha256 %null-sha256))))))
487 (check-source-file-name pkg)))
488 "file name should contain the package name"))))
490 (test-assert "source-file-name: valid"
495 (let ((pkg (dummy-package "x"
500 (uri "http://www.example.com/x-3.2.1.tar.gz")
501 (sha256 %null-sha256))))))
502 (check-source-file-name pkg)))
503 "file name should contain the package name"))))
505 (test-skip (if (force %http-server-socket) 0 1))
506 (test-equal "source: 200"
509 (with-http-server 200 %long-string
511 (inherit (dummy-package "x"))
515 (sha256 %null-sha256))))))
516 (check-source pkg)))))
518 (test-skip (if (force %http-server-socket) 0 1))
519 (test-assert "source: 200 but short length"
523 (with-http-server 200 "This is too small."
525 (inherit (dummy-package "x"))
529 (sha256 %null-sha256))))))
530 (check-source pkg))))
531 "suspiciously small")))
533 (test-skip (if (force %http-server-socket) 0 1))
534 (test-assert "source: 404"
538 (with-http-server 404 %long-string
540 (inherit (dummy-package "x"))
544 (sha256 %null-sha256))))))
545 (check-source pkg))))
546 "not reachable: 404")))
548 (test-assert "mirror-url"
551 (let ((source (origin
553 (uri "http://example.org/foo/bar.tar.gz")
554 (sha256 %null-sha256))))
555 (check-mirror-url (dummy-package "x" (source source)))))))
557 (test-assert "mirror-url: one suggestion"
560 (let ((source (origin
562 (uri "http://ftp.gnu.org/pub/gnu/foo/foo.tar.gz")
563 (sha256 %null-sha256))))
564 (check-mirror-url (dummy-package "x" (source source)))))
565 "mirror://gnu/foo/foo.tar.gz"))
568 (mock ((guix scripts lint) package-vulnerabilities (const '()))
570 (with-warnings (check-vulnerabilities (dummy-package "x"))))))
572 (test-assert "cve: one vulnerability"
573 (mock ((guix scripts lint) package-vulnerabilities
575 (list (make-struct (@@ (guix cve) <vulnerability>) 0
577 (list (cons (package-name package)
578 (package-version package)))))))
581 (check-vulnerabilities (dummy-package "pi" (version "3.14"))))
582 "vulnerable to CVE-2015-1234")))
584 (test-assert "cve: one patched vulnerability"
585 (mock ((guix scripts lint) package-vulnerabilities
587 (list (make-struct (@@ (guix cve) <vulnerability>) 0
589 (list (cons (package-name package)
590 (package-version package)))))))
593 (check-vulnerabilities
599 (list "/a/b/pi-CVE-2015-1234.patch"))))))))))
601 (test-assert "cve: vulnerability fixed in replacement version"
602 (mock ((guix scripts lint) package-vulnerabilities
604 (match (package-version package)
606 (list (make-struct (@@ (guix cve) <vulnerability>) 0
608 (list (cons (package-name package)
609 (package-version package))))))
612 (and (not (string-null?
614 (check-vulnerabilities
615 (dummy-package "foo" (version "0"))))))
618 (check-vulnerabilities
621 (replacement (dummy-package "foo" (version "1"))))))))))
623 (test-assert "cve: patched vulnerability in replacement"
624 (mock ((guix scripts lint) package-vulnerabilities
626 (list (make-struct (@@ (guix cve) <vulnerability>) 0
628 (list (cons (package-name package)
629 (package-version package)))))))
632 (check-vulnerabilities
634 "pi" (version "3.14") (source (dummy-origin))
635 (replacement (dummy-package
636 "pi" (version "3.14")
640 (list "/a/b/pi-CVE-2015-1234.patch"))))))))))))
642 (test-assert "formatting: lonely parentheses"
647 dummy-package "ugly as hell!"
652 (test-assert "formatting: tabulation"
655 (check-formatting (dummy-package "leave the tab here: ")))
658 (test-assert "formatting: trailing white space"
661 ;; Leave the trailing white space on the next line!
662 (check-formatting (dummy-package "x")))
663 "trailing white space"))
665 (test-assert "formatting: long line"
669 (dummy-package "x" ;here is a stupid comment just to make a long line
673 (test-assert "formatting: alright"
676 (check-formatting (dummy-package "x")))))
681 ;; eval: (put 'with-http-server 'scheme-indent-function 2)
682 ;; eval: (put 'with-warnings 'scheme-indent-function 0)