lint.scm 28 KB

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