lint.scm 56 KB

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