lint.scm 58 KB

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