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> |
c74f0cb2 | 4 | ;;; Copyright © 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org> |
052d53df | 5 | ;;; Copyright © 2015, 2016 Mathieu Lirzin <mthl@gnu.org> |
b4f5e0e8 CR |
6 | ;;; |
7 | ;;; This file is part of GNU Guix. | |
8 | ;;; | |
9 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | |
10 | ;;; under the terms of the GNU General Public License as published by | |
11 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
12 | ;;; your option) any later version. | |
13 | ;;; | |
14 | ;;; GNU Guix is distributed in the hope that it will be useful, but | |
15 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | ;;; GNU General Public License for more details. | |
18 | ;;; | |
19 | ;;; You should have received a copy of the GNU General Public License | |
20 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | |
21 | ||
c74f0cb2 LC |
22 | ;; Avoid interference. |
23 | (unsetenv "http_proxy") | |
24 | ||
4e7b6b48 | 25 | (define-module (test-lint) |
8b385969 | 26 | #:use-module (guix tests) |
754e5be2 | 27 | #:use-module (guix download) |
50f5c46d | 28 | #:use-module (guix git-download) |
b4f5e0e8 CR |
29 | #:use-module (guix build-system gnu) |
30 | #:use-module (guix packages) | |
31 | #:use-module (guix scripts lint) | |
32 | #:use-module (guix ui) | |
33 | #:use-module (gnu packages) | |
99fe215c | 34 | #:use-module (gnu packages glib) |
b4f5e0e8 | 35 | #:use-module (gnu packages pkg-config) |
907c98ac LC |
36 | #:use-module (web server) |
37 | #:use-module (web server http) | |
38 | #:use-module (web response) | |
9bee2bd1 | 39 | #:use-module (ice-9 match) |
907c98ac LC |
40 | #:use-module (ice-9 threads) |
41 | #:use-module (srfi srfi-9 gnu) | |
b4f5e0e8 CR |
42 | #:use-module (srfi srfi-64)) |
43 | ||
44 | ;; Test the linter. | |
45 | ||
907c98ac LC |
46 | (define %http-server-port |
47 | ;; TCP port to use for the stub HTTP server. | |
48 | 9999) | |
49 | ||
50 | (define %local-url | |
51 | ;; URL to use for 'home-page' tests. | |
52 | (string-append "http://localhost:" (number->string %http-server-port) | |
53 | "/foo/bar")) | |
54 | ||
950d2ea4 LC |
55 | (define %null-sha256 |
56 | ;; SHA256 of the empty string. | |
57 | (base32 | |
58 | "0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73")) | |
59 | ||
907c98ac LC |
60 | (define %http-server-socket |
61 | ;; Socket used by the Web server. | |
62 | (catch 'system-error | |
63 | (lambda () | |
64 | (let ((sock (socket PF_INET SOCK_STREAM 0))) | |
65 | (setsockopt sock SOL_SOCKET SO_REUSEADDR 1) | |
66 | (bind sock | |
67 | (make-socket-address AF_INET INADDR_LOOPBACK | |
68 | %http-server-port)) | |
69 | sock)) | |
70 | (lambda args | |
71 | (let ((err (system-error-errno args))) | |
72 | (format (current-error-port) | |
73 | "warning: cannot run Web server for tests: ~a~%" | |
74 | (strerror err)) | |
75 | #f)))) | |
76 | ||
77 | (define (http-write server client response body) | |
78 | "Write RESPONSE." | |
79 | (let* ((response (write-response response client)) | |
80 | (port (response-port response))) | |
81 | (cond | |
82 | ((not body)) ;pass | |
83 | (else | |
84 | (write-response-body response body))) | |
85 | (close-port port) | |
86 | (quit #t) ;exit the server thread | |
87 | (values))) | |
88 | ||
4655005e LC |
89 | ;; Mutex and condition variable to synchronize with the HTTP server. |
90 | (define %http-server-lock (make-mutex)) | |
91 | (define %http-server-ready (make-condition-variable)) | |
92 | ||
93 | (define (http-open . args) | |
94 | "Start listening for HTTP requests and signal %HTTP-SERVER-READY." | |
95 | (with-mutex %http-server-lock | |
96 | (let ((result (apply (@@ (web server http) http-open) args))) | |
97 | (signal-condition-variable %http-server-ready) | |
98 | result))) | |
99 | ||
907c98ac LC |
100 | (define-server-impl stub-http-server |
101 | ;; Stripped-down version of Guile's built-in HTTP server. | |
4655005e | 102 | http-open |
907c98ac LC |
103 | (@@ (web server http) http-read) |
104 | http-write | |
105 | (@@ (web server http) http-close)) | |
106 | ||
bfcb3d76 LC |
107 | (define (call-with-http-server code data thunk) |
108 | "Call THUNK with an HTTP server running and returning CODE and DATA (a | |
109 | string) on HTTP requests." | |
907c98ac LC |
110 | (define (server-body) |
111 | (define (handle request body) | |
112 | (values (build-response #:code code | |
113 | #:reason-phrase "Such is life") | |
bfcb3d76 | 114 | data)) |
907c98ac LC |
115 | |
116 | (catch 'quit | |
117 | (lambda () | |
118 | (run-server handle stub-http-server | |
119 | `(#:socket ,%http-server-socket))) | |
120 | (const #t))) | |
121 | ||
4655005e LC |
122 | (with-mutex %http-server-lock |
123 | (let ((server (make-thread server-body))) | |
124 | (wait-condition-variable %http-server-ready %http-server-lock) | |
125 | ;; Normally SERVER exits automatically once it has received a request. | |
126 | (thunk)))) | |
907c98ac | 127 | |
bfcb3d76 LC |
128 | (define-syntax-rule (with-http-server code data body ...) |
129 | (call-with-http-server code data (lambda () body ...))) | |
130 | ||
131 | (define %long-string | |
132 | (make-string 2000 #\a)) | |
907c98ac | 133 | |
b4f5e0e8 CR |
134 | \f |
135 | (test-begin "lint") | |
136 | ||
b4f5e0e8 | 137 | (define (call-with-warnings thunk) |
b002e9d0 LC |
138 | (let ((port (open-output-string))) |
139 | (parameterize ((guix-warning-port port)) | |
140 | (thunk)) | |
141 | (get-output-string port))) | |
b4f5e0e8 | 142 | |
4fbf4ca5 LC |
143 | (define-syntax-rule (with-warnings body ...) |
144 | (call-with-warnings (lambda () body ...))) | |
145 | ||
20be23c3 LC |
146 | (test-assert "description: not a string" |
147 | (->bool | |
148 | (string-contains (with-warnings | |
149 | (let ((pkg (dummy-package "x" | |
150 | (description 'foobar)))) | |
151 | (check-description-style pkg))) | |
152 | "invalid description"))) | |
153 | ||
334c43e3 EB |
154 | (test-assert "description: not empty" |
155 | (->bool | |
4fbf4ca5 LC |
156 | (string-contains (with-warnings |
157 | (let ((pkg (dummy-package "x" | |
158 | (description "")))) | |
159 | (check-description-style pkg))) | |
334c43e3 EB |
160 | "description should not be empty"))) |
161 | ||
3500e659 ML |
162 | (test-assert "description: valid Texinfo markup" |
163 | (->bool | |
164 | (string-contains | |
165 | (with-warnings | |
166 | (check-description-style (dummy-package "x" (description "f{oo}b@r")))) | |
167 | "Texinfo markup in description is invalid"))) | |
168 | ||
8202a513 CR |
169 | (test-assert "description: does not start with an upper-case letter" |
170 | (->bool | |
4fbf4ca5 LC |
171 | (string-contains (with-warnings |
172 | (let ((pkg (dummy-package "x" | |
173 | (description "bad description.")))) | |
174 | (check-description-style pkg))) | |
8202a513 CR |
175 | "description should start with an upper-case letter"))) |
176 | ||
903581f9 | 177 | (test-assert "description: may start with a digit" |
b1e66683 | 178 | (string-null? |
4fbf4ca5 LC |
179 | (with-warnings |
180 | (let ((pkg (dummy-package "x" | |
181 | (description "2-component library.")))) | |
182 | (check-description-style pkg))))) | |
903581f9 | 183 | |
3c42965b | 184 | (test-assert "description: may start with lower-case package name" |
b1e66683 | 185 | (string-null? |
4fbf4ca5 LC |
186 | (with-warnings |
187 | (let ((pkg (dummy-package "x" | |
188 | (description "x is a dummy package.")))) | |
189 | (check-description-style pkg))))) | |
3c42965b | 190 | |
574e847b EB |
191 | (test-assert "description: two spaces after end of sentence" |
192 | (->bool | |
4fbf4ca5 LC |
193 | (string-contains (with-warnings |
194 | (let ((pkg (dummy-package "x" | |
195 | (description "Bad. Quite bad.")))) | |
196 | (check-description-style pkg))) | |
574e847b EB |
197 | "sentences in description should be followed by two spaces"))) |
198 | ||
199 | (test-assert "description: end-of-sentence detection with abbreviations" | |
b1e66683 | 200 | (string-null? |
4fbf4ca5 LC |
201 | (with-warnings |
202 | (let ((pkg (dummy-package "x" | |
203 | (description | |
204 | "E.g. Foo, i.e. Bar resp. Baz (a.k.a. DVD).")))) | |
205 | (check-description-style pkg))))) | |
574e847b | 206 | |
83f18e06 EB |
207 | (test-assert "description: may not contain trademark signs" |
208 | (and (->bool | |
209 | (string-contains (with-warnings | |
210 | (let ((pkg (dummy-package "x" | |
211 | (description "Does The Right Thing™")))) | |
212 | (check-description-style pkg))) | |
213 | "should not contain trademark sign")) | |
214 | (->bool | |
215 | (string-contains (with-warnings | |
216 | (let ((pkg (dummy-package "x" | |
217 | (description "Works with Format®")))) | |
218 | (check-description-style pkg))) | |
219 | "should not contain trademark sign")))) | |
220 | ||
4bb54cc4 LC |
221 | (test-assert "description: suggest ornament instead of quotes" |
222 | (->bool | |
223 | (string-contains (with-warnings | |
224 | (let ((pkg (dummy-package "x" | |
225 | (description "This is a 'quoted' thing.")))) | |
226 | (check-description-style pkg))) | |
227 | "use @code"))) | |
228 | ||
20be23c3 LC |
229 | (test-assert "synopsis: not a string" |
230 | (->bool | |
231 | (string-contains (with-warnings | |
232 | (let ((pkg (dummy-package "x" | |
233 | (synopsis #f)))) | |
234 | (check-synopsis-style pkg))) | |
235 | "invalid synopsis"))) | |
236 | ||
574e847b EB |
237 | (test-assert "synopsis: not empty" |
238 | (->bool | |
4fbf4ca5 LC |
239 | (string-contains (with-warnings |
240 | (let ((pkg (dummy-package "x" | |
241 | (synopsis "")))) | |
242 | (check-synopsis-style pkg))) | |
574e847b EB |
243 | "synopsis should not be empty"))) |
244 | ||
8202a513 CR |
245 | (test-assert "synopsis: does not start with an upper-case letter" |
246 | (->bool | |
4fbf4ca5 LC |
247 | (string-contains (with-warnings |
248 | (let ((pkg (dummy-package "x" | |
249 | (synopsis "bad synopsis.")))) | |
250 | (check-synopsis-style pkg))) | |
8202a513 CR |
251 | "synopsis should start with an upper-case letter"))) |
252 | ||
903581f9 | 253 | (test-assert "synopsis: may start with a digit" |
b1e66683 | 254 | (string-null? |
4fbf4ca5 LC |
255 | (with-warnings |
256 | (let ((pkg (dummy-package "x" | |
257 | (synopsis "5-dimensional frobnicator")))) | |
258 | (check-synopsis-style pkg))))) | |
903581f9 | 259 | |
b4f5e0e8 CR |
260 | (test-assert "synopsis: ends with a period" |
261 | (->bool | |
4fbf4ca5 LC |
262 | (string-contains (with-warnings |
263 | (let ((pkg (dummy-package "x" | |
264 | (synopsis "Bad synopsis.")))) | |
265 | (check-synopsis-style pkg))) | |
b4f5e0e8 CR |
266 | "no period allowed at the end of the synopsis"))) |
267 | ||
268 | (test-assert "synopsis: ends with 'etc.'" | |
4fbf4ca5 LC |
269 | (string-null? (with-warnings |
270 | (let ((pkg (dummy-package "x" | |
271 | (synopsis "Foo, bar, etc.")))) | |
272 | (check-synopsis-style pkg))))) | |
b4f5e0e8 CR |
273 | |
274 | (test-assert "synopsis: starts with 'A'" | |
275 | (->bool | |
4fbf4ca5 LC |
276 | (string-contains (with-warnings |
277 | (let ((pkg (dummy-package "x" | |
278 | (synopsis "A bad synopŝis")))) | |
279 | (check-synopsis-style pkg))) | |
b4f5e0e8 CR |
280 | "no article allowed at the beginning of the synopsis"))) |
281 | ||
282 | (test-assert "synopsis: starts with 'An'" | |
283 | (->bool | |
4fbf4ca5 LC |
284 | (string-contains (with-warnings |
285 | (let ((pkg (dummy-package "x" | |
286 | (synopsis "An awful synopsis")))) | |
287 | (check-synopsis-style pkg))) | |
b4f5e0e8 CR |
288 | "no article allowed at the beginning of the synopsis"))) |
289 | ||
a00ffdaa CR |
290 | (test-assert "synopsis: starts with 'a'" |
291 | (->bool | |
4fbf4ca5 LC |
292 | (string-contains (with-warnings |
293 | (let ((pkg (dummy-package "x" | |
294 | (synopsis "a bad synopsis")))) | |
295 | (check-synopsis-style pkg))) | |
a00ffdaa CR |
296 | "no article allowed at the beginning of the synopsis"))) |
297 | ||
298 | (test-assert "synopsis: starts with 'an'" | |
299 | (->bool | |
4fbf4ca5 LC |
300 | (string-contains (with-warnings |
301 | (let ((pkg (dummy-package "x" | |
302 | (synopsis "an awful synopsis")))) | |
303 | (check-synopsis-style pkg))) | |
a00ffdaa CR |
304 | "no article allowed at the beginning of the synopsis"))) |
305 | ||
5622953d CR |
306 | (test-assert "synopsis: too long" |
307 | (->bool | |
4fbf4ca5 LC |
308 | (string-contains (with-warnings |
309 | (let ((pkg (dummy-package "x" | |
310 | (synopsis (make-string 80 #\x))))) | |
311 | (check-synopsis-style pkg))) | |
5622953d CR |
312 | "synopsis should be less than 80 characters long"))) |
313 | ||
3c762a13 CR |
314 | (test-assert "synopsis: start with package name" |
315 | (->bool | |
4fbf4ca5 LC |
316 | (string-contains (with-warnings |
317 | (let ((pkg (dummy-package "x" | |
318 | (name "foo") | |
319 | (synopsis "foo, a nice package")))) | |
320 | (check-synopsis-style pkg))) | |
3c762a13 CR |
321 | "synopsis should not start with the package name"))) |
322 | ||
17854ef9 LC |
323 | (test-assert "synopsis: start with package name prefix" |
324 | (string-null? | |
4fbf4ca5 LC |
325 | (with-warnings |
326 | (let ((pkg (dummy-package "arb" | |
327 | (synopsis "Arbitrary precision")))) | |
328 | (check-synopsis-style pkg))))) | |
17854ef9 | 329 | |
15a6d433 LC |
330 | (test-assert "synopsis: start with abbreviation" |
331 | (string-null? | |
4fbf4ca5 LC |
332 | (with-warnings |
333 | (let ((pkg (dummy-package "uucp" | |
334 | ;; Same problem with "APL interpreter", etc. | |
335 | (synopsis "UUCP implementation") | |
336 | (description "Imagine this is Taylor UUCP.")))) | |
337 | (check-synopsis-style pkg))))) | |
15a6d433 | 338 | |
b4f5e0e8 CR |
339 | (test-assert "inputs: pkg-config is probably a native input" |
340 | (->bool | |
341 | (string-contains | |
4fbf4ca5 LC |
342 | (with-warnings |
343 | (let ((pkg (dummy-package "x" | |
344 | (inputs `(("pkg-config" ,pkg-config)))))) | |
345 | (check-inputs-should-be-native pkg))) | |
99fe215c DC |
346 | "'pkg-config' should probably be a native input"))) |
347 | ||
348 | (test-assert "inputs: glib:bin is probably a native input" | |
349 | (->bool | |
350 | (string-contains | |
351 | (with-warnings | |
352 | (let ((pkg (dummy-package "x" | |
353 | (inputs `(("glib" ,glib "bin")))))) | |
354 | (check-inputs-should-be-native pkg))) | |
355 | "'glib:bin' should probably be a native input"))) | |
b4f5e0e8 CR |
356 | |
357 | (test-assert "patches: file names" | |
358 | (->bool | |
359 | (string-contains | |
4fbf4ca5 LC |
360 | (with-warnings |
361 | (let ((pkg (dummy-package "x" | |
362 | (source | |
052d53df | 363 | (dummy-origin |
4fbf4ca5 | 364 | (patches (list "/path/to/y.patch"))))))) |
56b1b74c | 365 | (check-patch-file-names pkg))) |
907c98ac LC |
366 | "file names of patches should start with the package name"))) |
367 | ||
b210b35d LC |
368 | (test-assert "patches: not found" |
369 | (->bool | |
370 | (string-contains | |
371 | (with-warnings | |
372 | (let ((pkg (dummy-package "x" | |
373 | (source | |
052d53df | 374 | (dummy-origin |
b210b35d LC |
375 | (patches |
376 | (list (search-patch "this-patch-does-not-exist!")))))))) | |
377 | (check-patch-file-names pkg))) | |
378 | "patch not found"))) | |
379 | ||
002c57c6 LC |
380 | (test-assert "derivation: invalid arguments" |
381 | (->bool | |
382 | (string-contains | |
383 | (with-warnings | |
384 | (let ((pkg (dummy-package "x" | |
385 | (arguments | |
386 | '(#:imported-modules (invalid-module)))))) | |
387 | (check-derivation pkg))) | |
388 | "failed to create derivation"))) | |
389 | ||
52b9efe3 LC |
390 | (test-assert "license: invalid license" |
391 | (string-contains | |
392 | (with-warnings | |
393 | (check-license (dummy-package "x" (license #f)))) | |
394 | "invalid license")) | |
395 | ||
907c98ac LC |
396 | (test-assert "home-page: wrong home-page" |
397 | (->bool | |
398 | (string-contains | |
4fbf4ca5 LC |
399 | (with-warnings |
400 | (let ((pkg (package | |
401 | (inherit (dummy-package "x")) | |
402 | (home-page #f)))) | |
403 | (check-home-page pkg))) | |
907c98ac LC |
404 | "invalid"))) |
405 | ||
406 | (test-assert "home-page: invalid URI" | |
407 | (->bool | |
408 | (string-contains | |
4fbf4ca5 LC |
409 | (with-warnings |
410 | (let ((pkg (package | |
411 | (inherit (dummy-package "x")) | |
412 | (home-page "foobar")))) | |
413 | (check-home-page pkg))) | |
907c98ac LC |
414 | "invalid home page URL"))) |
415 | ||
416 | (test-assert "home-page: host not found" | |
417 | (->bool | |
418 | (string-contains | |
4fbf4ca5 LC |
419 | (with-warnings |
420 | (let ((pkg (package | |
421 | (inherit (dummy-package "x")) | |
422 | (home-page "http://does-not-exist")))) | |
423 | (check-home-page pkg))) | |
907c98ac LC |
424 | "domain not found"))) |
425 | ||
426 | (test-skip (if %http-server-socket 0 1)) | |
427 | (test-assert "home-page: Connection refused" | |
428 | (->bool | |
429 | (string-contains | |
4fbf4ca5 LC |
430 | (with-warnings |
431 | (let ((pkg (package | |
432 | (inherit (dummy-package "x")) | |
433 | (home-page %local-url)))) | |
434 | (check-home-page pkg))) | |
907c98ac LC |
435 | "Connection refused"))) |
436 | ||
437 | (test-skip (if %http-server-socket 0 1)) | |
438 | (test-equal "home-page: 200" | |
439 | "" | |
4fbf4ca5 | 440 | (with-warnings |
bfcb3d76 | 441 | (with-http-server 200 %long-string |
4fbf4ca5 LC |
442 | (let ((pkg (package |
443 | (inherit (dummy-package "x")) | |
444 | (home-page %local-url)))) | |
445 | (check-home-page pkg))))) | |
907c98ac | 446 | |
bfcb3d76 LC |
447 | (test-skip (if %http-server-socket 0 1)) |
448 | (test-assert "home-page: 200 but short length" | |
449 | (->bool | |
450 | (string-contains | |
451 | (with-warnings | |
452 | (with-http-server 200 "This is too small." | |
453 | (let ((pkg (package | |
454 | (inherit (dummy-package "x")) | |
455 | (home-page %local-url)))) | |
456 | (check-home-page pkg)))) | |
457 | "suspiciously small"))) | |
458 | ||
907c98ac LC |
459 | (test-skip (if %http-server-socket 0 1)) |
460 | (test-assert "home-page: 404" | |
461 | (->bool | |
462 | (string-contains | |
4fbf4ca5 | 463 | (with-warnings |
bfcb3d76 | 464 | (with-http-server 404 %long-string |
4fbf4ca5 LC |
465 | (let ((pkg (package |
466 | (inherit (dummy-package "x")) | |
467 | (home-page %local-url)))) | |
468 | (check-home-page pkg)))) | |
907c98ac | 469 | "not reachable: 404"))) |
b4f5e0e8 | 470 | |
50f5c46d EB |
471 | (test-assert "source-file-name" |
472 | (->bool | |
473 | (string-contains | |
474 | (with-warnings | |
475 | (let ((pkg (dummy-package "x" | |
476 | (version "3.2.1") | |
477 | (source | |
478 | (origin | |
479 | (method url-fetch) | |
480 | (uri "http://www.example.com/3.2.1.tar.gz") | |
481 | (sha256 %null-sha256)))))) | |
482 | (check-source-file-name pkg))) | |
483 | "file name should contain the package name"))) | |
484 | ||
485 | (test-assert "source-file-name: v prefix" | |
486 | (->bool | |
487 | (string-contains | |
488 | (with-warnings | |
489 | (let ((pkg (dummy-package "x" | |
490 | (version "3.2.1") | |
491 | (source | |
492 | (origin | |
493 | (method url-fetch) | |
494 | (uri "http://www.example.com/v3.2.1.tar.gz") | |
495 | (sha256 %null-sha256)))))) | |
496 | (check-source-file-name pkg))) | |
497 | "file name should contain the package name"))) | |
498 | ||
499 | (test-assert "source-file-name: bad checkout" | |
500 | (->bool | |
501 | (string-contains | |
502 | (with-warnings | |
503 | (let ((pkg (dummy-package "x" | |
504 | (version "3.2.1") | |
505 | (source | |
506 | (origin | |
507 | (method git-fetch) | |
508 | (uri (git-reference | |
509 | (url "http://www.example.com/x.git") | |
510 | (commit "0"))) | |
511 | (sha256 %null-sha256)))))) | |
512 | (check-source-file-name pkg))) | |
513 | "file name should contain the package name"))) | |
514 | ||
515 | (test-assert "source-file-name: good checkout" | |
516 | (not | |
517 | (->bool | |
518 | (string-contains | |
519 | (with-warnings | |
520 | (let ((pkg (dummy-package "x" | |
521 | (version "3.2.1") | |
522 | (source | |
523 | (origin | |
524 | (method git-fetch) | |
525 | (uri (git-reference | |
526 | (url "http://git.example.com/x.git") | |
527 | (commit "0"))) | |
528 | (file-name (string-append "x-" version)) | |
529 | (sha256 %null-sha256)))))) | |
530 | (check-source-file-name pkg))) | |
531 | "file name should contain the package name")))) | |
532 | ||
533 | (test-assert "source-file-name: valid" | |
534 | (not | |
535 | (->bool | |
536 | (string-contains | |
537 | (with-warnings | |
538 | (let ((pkg (dummy-package "x" | |
539 | (version "3.2.1") | |
540 | (source | |
541 | (origin | |
542 | (method url-fetch) | |
543 | (uri "http://www.example.com/x-3.2.1.tar.gz") | |
544 | (sha256 %null-sha256)))))) | |
545 | (check-source-file-name pkg))) | |
546 | "file name should contain the package name")))) | |
547 | ||
950d2ea4 LC |
548 | (test-skip (if %http-server-socket 0 1)) |
549 | (test-equal "source: 200" | |
550 | "" | |
551 | (with-warnings | |
bfcb3d76 | 552 | (with-http-server 200 %long-string |
950d2ea4 LC |
553 | (let ((pkg (package |
554 | (inherit (dummy-package "x")) | |
555 | (source (origin | |
556 | (method url-fetch) | |
557 | (uri %local-url) | |
558 | (sha256 %null-sha256)))))) | |
559 | (check-source pkg))))) | |
560 | ||
bfcb3d76 LC |
561 | (test-skip (if %http-server-socket 0 1)) |
562 | (test-assert "source: 200 but short length" | |
563 | (->bool | |
564 | (string-contains | |
565 | (with-warnings | |
566 | (with-http-server 200 "This is too small." | |
567 | (let ((pkg (package | |
568 | (inherit (dummy-package "x")) | |
569 | (source (origin | |
570 | (method url-fetch) | |
571 | (uri %local-url) | |
572 | (sha256 %null-sha256)))))) | |
573 | (check-source pkg)))) | |
574 | "suspiciously small"))) | |
575 | ||
950d2ea4 LC |
576 | (test-skip (if %http-server-socket 0 1)) |
577 | (test-assert "source: 404" | |
578 | (->bool | |
579 | (string-contains | |
580 | (with-warnings | |
bfcb3d76 | 581 | (with-http-server 404 %long-string |
950d2ea4 LC |
582 | (let ((pkg (package |
583 | (inherit (dummy-package "x")) | |
584 | (source (origin | |
585 | (method url-fetch) | |
586 | (uri %local-url) | |
587 | (sha256 %null-sha256)))))) | |
588 | (check-source pkg)))) | |
589 | "not reachable: 404"))) | |
590 | ||
5432734b LC |
591 | (test-assert "cve" |
592 | (mock ((guix scripts lint) package-vulnerabilities (const '())) | |
593 | (string-null? | |
594 | (with-warnings (check-vulnerabilities (dummy-package "x")))))) | |
595 | ||
596 | (test-assert "cve: one vulnerability" | |
597 | (mock ((guix scripts lint) package-vulnerabilities | |
598 | (lambda (package) | |
599 | (list (make-struct (@@ (guix cve) <vulnerability>) 0 | |
600 | "CVE-2015-1234" | |
601 | (list (cons (package-name package) | |
602 | (package-version package))))))) | |
603 | (string-contains | |
604 | (with-warnings | |
605 | (check-vulnerabilities (dummy-package "pi" (version "3.14")))) | |
606 | "vulnerable to CVE-2015-1234"))) | |
607 | ||
4e70fe4d LC |
608 | (test-assert "cve: one patched vulnerability" |
609 | (mock ((guix scripts lint) package-vulnerabilities | |
610 | (lambda (package) | |
611 | (list (make-struct (@@ (guix cve) <vulnerability>) 0 | |
612 | "CVE-2015-1234" | |
613 | (list (cons (package-name package) | |
614 | (package-version package))))))) | |
615 | (string-null? | |
616 | (with-warnings | |
617 | (check-vulnerabilities | |
618 | (dummy-package "pi" | |
619 | (version "3.14") | |
620 | (source | |
621 | (dummy-origin | |
622 | (patches | |
623 | (list "/a/b/pi-CVE-2015-1234.patch")))))))))) | |
624 | ||
9bee2bd1 LC |
625 | (test-assert "cve: vulnerability fixed in replacement version" |
626 | (mock ((guix scripts lint) package-vulnerabilities | |
627 | (lambda (package) | |
628 | (match (package-version package) | |
629 | ("0" | |
630 | (list (make-struct (@@ (guix cve) <vulnerability>) 0 | |
631 | "CVE-2015-1234" | |
632 | (list (cons (package-name package) | |
633 | (package-version package)))))) | |
634 | ("1" | |
635 | '())))) | |
636 | (and (not (string-null? | |
637 | (with-warnings | |
638 | (check-vulnerabilities | |
639 | (dummy-package "foo" (version "0")))))) | |
640 | (string-null? | |
641 | (with-warnings | |
642 | (check-vulnerabilities | |
643 | (dummy-package | |
644 | "foo" (version "0") | |
645 | (replacement (dummy-package "foo" (version "1")))))))))) | |
646 | ||
5c6a062d LC |
647 | (test-assert "cve: patched vulnerability in replacement" |
648 | (mock ((guix scripts lint) package-vulnerabilities | |
649 | (lambda (package) | |
650 | (list (make-struct (@@ (guix cve) <vulnerability>) 0 | |
651 | "CVE-2015-1234" | |
652 | (list (cons (package-name package) | |
653 | (package-version package))))))) | |
654 | (string-null? | |
655 | (with-warnings | |
656 | (check-vulnerabilities | |
657 | (dummy-package | |
658 | "pi" (version "3.14") (source (dummy-origin)) | |
659 | (replacement (dummy-package | |
660 | "pi" (version "3.14") | |
661 | (source | |
662 | (dummy-origin | |
663 | (patches | |
664 | (list "/a/b/pi-CVE-2015-1234.patch")))))))))))) | |
665 | ||
e0566f12 LC |
666 | (test-assert "formatting: lonely parentheses" |
667 | (string-contains | |
668 | (with-warnings | |
669 | (check-formatting | |
670 | ( | |
671 | dummy-package "ugly as hell!" | |
672 | ) | |
673 | )) | |
674 | "lonely")) | |
675 | ||
40a7d4e5 LC |
676 | (test-assert "formatting: tabulation" |
677 | (string-contains | |
678 | (with-warnings | |
679 | (check-formatting (dummy-package "leave the tab here: "))) | |
680 | "tabulation")) | |
681 | ||
682 | (test-assert "formatting: trailing white space" | |
683 | (string-contains | |
684 | (with-warnings | |
685 | ;; Leave the trailing white space on the next line! | |
686 | (check-formatting (dummy-package "x"))) | |
687 | "trailing white space")) | |
688 | ||
689 | (test-assert "formatting: long line" | |
690 | (string-contains | |
691 | (with-warnings | |
692 | (check-formatting | |
693 | (dummy-package "x" ;here is a stupid comment just to make a long line | |
694 | ))) | |
695 | "too long")) | |
696 | ||
697 | (test-assert "formatting: alright" | |
698 | (string-null? | |
699 | (with-warnings | |
700 | (check-formatting (dummy-package "x"))))) | |
701 | ||
b4f5e0e8 CR |
702 | (test-end "lint") |
703 | ||
907c98ac | 704 | ;; Local Variables: |
bfcb3d76 | 705 | ;; eval: (put 'with-http-server 'scheme-indent-function 2) |
4fbf4ca5 | 706 | ;; eval: (put 'with-warnings 'scheme-indent-function 0) |
907c98ac | 707 | ;; End: |