lint.scm 59 KB

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