lint.scm 55 KB

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