lint.scm 54 KB

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