lint.scm 54 KB

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