lint.scm 57 KB

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