hackage.scm 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2015 Federico Beffa <beffa@fbengineering.ch>
  3. ;;; Copyright © 2019 Robert Vollmert <rob@vllmrt.net>
  4. ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
  5. ;;;
  6. ;;; This file is part of GNU Guix.
  7. ;;;
  8. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  9. ;;; under the terms of the GNU General Public License as published by
  10. ;;; the Free Software Foundation; either version 3 of the License, or (at
  11. ;;; your option) any later version.
  12. ;;;
  13. ;;; GNU Guix is distributed in the hope that it will be useful, but
  14. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;;; GNU General Public License for more details.
  17. ;;;
  18. ;;; You should have received a copy of the GNU General Public License
  19. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  20. (define-module (test-hackage)
  21. #:use-module (guix import cabal)
  22. #:use-module (guix import hackage)
  23. #:use-module (guix tests)
  24. #:use-module (srfi srfi-64)
  25. #:use-module (ice-9 match))
  26. (define test-cabal-1
  27. "name: foo
  28. version: 1.0.0
  29. homepage: http://test.org
  30. synopsis: synopsis
  31. description: description
  32. license: BSD3
  33. executable cabal
  34. build-depends:
  35. HTTP >= 4000.2.5 && < 4000.3,
  36. mtl >= 2.0 && < 3
  37. ")
  38. (define test-cabal-2
  39. "name: foo
  40. version: 1.0.0
  41. homepage: http://test.org
  42. synopsis: synopsis
  43. description: description
  44. license: BSD3
  45. executable cabal {
  46. build-depends:
  47. HTTP >= 4000.2.5 && < 4000.3,
  48. mtl >= 2.0 && < 3
  49. }
  50. ")
  51. ;; Check compiler implementation test with and without spaces.
  52. (define test-cabal-3
  53. "name: foo
  54. version: 1.0.0
  55. homepage: http://test.org
  56. synopsis: synopsis
  57. description: description
  58. license: BSD3
  59. library
  60. if impl(ghc >= 7.2 && < 7.6)
  61. Build-depends: ghc-a
  62. if impl(ghc>=7.2&&<7.6)
  63. Build-depends: ghc-b
  64. if impl(ghc == 7.8)
  65. Build-depends:
  66. HTTP >= 4000.2.5 && < 4000.3,
  67. mtl >= 2.0 && < 3
  68. ")
  69. ;; Check "-any", "-none" when name is different.
  70. (define test-cabal-4
  71. "name: foo
  72. version: 1.0.0
  73. homepage: http://test.org
  74. synopsis: synopsis
  75. description: description
  76. license: BSD3
  77. library
  78. if impl(ghcjs -any)
  79. Build-depends: ghc-a
  80. if impl(ghc>=7.2&&<7.6)
  81. Build-depends: ghc-b
  82. if impl(ghc == 7.8)
  83. Build-depends:
  84. HTTP >= 4000.2.5 && < 4000.3,
  85. mtl >= 2.0 && < 3
  86. ")
  87. ;; Check "-any", "-none".
  88. (define test-cabal-5
  89. "name: foo
  90. version: 1.0.0
  91. homepage: http://test.org
  92. synopsis: synopsis
  93. description: description
  94. license: BSD3
  95. library
  96. if impl(ghc == 7.8)
  97. Build-depends:
  98. HTTP >= 4000.2.5 && < 4000.3,
  99. if impl(ghc -any)
  100. Build-depends: mtl >= 2.0 && < 3
  101. if impl(ghc>=7.2&&<7.6)
  102. Build-depends: ghc-b
  103. ")
  104. ;; Check "custom-setup".
  105. (define test-cabal-6
  106. "name: foo
  107. build-type: Custom
  108. version: 1.0.0
  109. homepage: http://test.org
  110. synopsis: synopsis
  111. description: description
  112. license: BSD3
  113. custom-setup
  114. setup-depends: base >= 4.7 && < 5,
  115. Cabal >= 1.24,
  116. haskell-gi == 0.21.*
  117. library
  118. if impl(ghc>=7.2&&<7.6)
  119. Build-depends: ghc-b
  120. if impl(ghc == 7.8)
  121. Build-depends:
  122. HTTP >= 4000.2.5 && < 4000.3,
  123. mtl >= 2.0 && < 3
  124. ")
  125. ;; A fragment of a real Cabal file with minor modification to check precedence
  126. ;; of 'and' over 'or', missing final newline, spaces between keywords and
  127. ;; parentheses and between key and column.
  128. (define test-read-cabal-1
  129. "name: test-me
  130. library
  131. -- Choose which library versions to use.
  132. if flag(base4point8)
  133. Build-depends: base >= 4.8 && < 5
  134. else
  135. if flag(base4)
  136. Build-depends: base >= 4 && < 4.8
  137. else
  138. if flag(base3)
  139. Build-depends: base >= 3 && < 4
  140. else
  141. Build-depends: base < 3
  142. if flag(base4point8) || flag (base4) && flag(base3)
  143. Build-depends: random
  144. Build-depends : containers
  145. -- Modules that are always built.
  146. Exposed-Modules:
  147. Test.QuickCheck.Exception")
  148. (test-begin "hackage")
  149. (define-syntax-rule (define-package-matcher name pattern)
  150. (define* (name obj)
  151. (match obj
  152. (pattern #t)
  153. (x (pk 'fail x #f)))))
  154. (define-package-matcher match-ghc-foo
  155. ('package
  156. ('name "ghc-foo")
  157. ('version "1.0.0")
  158. ('source
  159. ('origin
  160. ('method 'url-fetch)
  161. ('uri ('string-append
  162. "https://hackage.haskell.org/package/foo/foo-"
  163. 'version
  164. ".tar.gz"))
  165. ('sha256
  166. ('base32
  167. (? string? hash)))))
  168. ('build-system 'haskell-build-system)
  169. ('inputs
  170. ('quasiquote
  171. (("ghc-http" ('unquote 'ghc-http)))))
  172. ('home-page "http://test.org")
  173. ('synopsis (? string?))
  174. ('description (? string?))
  175. ('license 'license:bsd-3)))
  176. (define* (eval-test-with-cabal test-cabal matcher #:key (cabal-environment '()))
  177. (define port (open-input-string test-cabal))
  178. (matcher (hackage->guix-package "foo" #:port port #:cabal-environment cabal-environment)))
  179. (test-assert "hackage->guix-package test 1"
  180. (eval-test-with-cabal test-cabal-1 match-ghc-foo))
  181. (test-assert "hackage->guix-package test 2"
  182. (eval-test-with-cabal test-cabal-2 match-ghc-foo))
  183. (test-assert "hackage->guix-package test 3"
  184. (eval-test-with-cabal test-cabal-3 match-ghc-foo
  185. #:cabal-environment '(("impl" . "ghc-7.8"))))
  186. (test-assert "hackage->guix-package test 4"
  187. (eval-test-with-cabal test-cabal-4 match-ghc-foo
  188. #:cabal-environment '(("impl" . "ghc-7.8"))))
  189. (test-assert "hackage->guix-package test 5"
  190. (eval-test-with-cabal test-cabal-5 match-ghc-foo
  191. #:cabal-environment '(("impl" . "ghc-7.8"))))
  192. (define-package-matcher match-ghc-foo-6
  193. ('package
  194. ('name "ghc-foo")
  195. ('version "1.0.0")
  196. ('source
  197. ('origin
  198. ('method 'url-fetch)
  199. ('uri ('string-append
  200. "https://hackage.haskell.org/package/foo/foo-"
  201. 'version
  202. ".tar.gz"))
  203. ('sha256
  204. ('base32
  205. (? string? hash)))))
  206. ('build-system 'haskell-build-system)
  207. ('inputs
  208. ('quasiquote
  209. (("ghc-b" ('unquote 'ghc-b))
  210. ("ghc-http" ('unquote 'ghc-http)))))
  211. ('native-inputs
  212. ('quasiquote
  213. (("ghc-haskell-gi" ('unquote 'ghc-haskell-gi)))))
  214. ('home-page "http://test.org")
  215. ('synopsis (? string?))
  216. ('description (? string?))
  217. ('license 'license:bsd-3)))
  218. (test-assert "hackage->guix-package test 6"
  219. (eval-test-with-cabal test-cabal-6 match-ghc-foo-6))
  220. ;; Check multi-line layouted description.
  221. (define test-cabal-multiline-layout
  222. "name: foo
  223. version: 1.0.0
  224. homepage: http://test.org
  225. synopsis: synopsis
  226. description: first line
  227. second line
  228. license: BSD3
  229. executable cabal
  230. build-depends:
  231. HTTP >= 4000.2.5 && < 4000.3,
  232. mtl >= 2.0 && < 3
  233. ")
  234. (test-assert "hackage->guix-package test multiline desc (layout)"
  235. (eval-test-with-cabal test-cabal-multiline-layout match-ghc-foo))
  236. ;; Check multi-line braced description.
  237. (define test-cabal-multiline-braced
  238. "name: foo
  239. version: 1.0.0
  240. homepage: http://test.org
  241. synopsis: synopsis
  242. description: {
  243. first line
  244. second line
  245. }
  246. license: BSD3
  247. executable cabal
  248. build-depends:
  249. HTTP >= 4000.2.5 && < 4000.3,
  250. mtl >= 2.0 && < 3
  251. ")
  252. (test-assert "hackage->guix-package test multiline desc (braced)"
  253. (eval-test-with-cabal test-cabal-multiline-braced match-ghc-foo))
  254. ;; Check mixed layout. Compare e.g. warp.
  255. (define test-cabal-mixed-layout
  256. "name: foo
  257. version: 1.0.0
  258. homepage: http://test.org
  259. synopsis: synopsis
  260. description: description
  261. license: BSD3
  262. executable cabal
  263. build-depends:
  264. HTTP >= 4000.2.5 && < 4000.3,
  265. mtl >= 2.0 && < 3
  266. ghc-options: -Wall
  267. ")
  268. ;; Fails: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=35743
  269. (test-expect-fail 1)
  270. (test-assert "hackage->guix-package test mixed layout"
  271. (eval-test-with-cabal test-cabal-mixed-layout match-ghc-foo))
  272. ;; Check flag executable. Compare e.g. darcs.
  273. (define test-cabal-flag-executable
  274. "name: foo
  275. version: 1.0.0
  276. homepage: http://test.org
  277. synopsis: synopsis
  278. description: description
  279. license: BSD3
  280. flag executable
  281. description: Build executable
  282. default: True
  283. executable cabal
  284. if !flag(executable)
  285. buildable: False
  286. else
  287. buildable: True
  288. build-depends:
  289. HTTP >= 4000.2.5 && < 4000.3,
  290. mtl >= 2.0 && < 3
  291. ")
  292. ;; Fails: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=25138
  293. (test-expect-fail 1)
  294. (test-assert "hackage->guix-package test flag executable"
  295. (eval-test-with-cabal test-cabal-flag-executable match-ghc-foo))
  296. ;; Check Hackage Cabal revisions.
  297. (define test-cabal-revision
  298. "name: foo
  299. version: 1.0.0
  300. x-revision: 2
  301. homepage: http://test.org
  302. synopsis: synopsis
  303. description: description
  304. license: BSD3
  305. executable cabal
  306. build-depends:
  307. HTTP >= 4000.2.5 && < 4000.3,
  308. mtl >= 2.0 && < 3
  309. ")
  310. (define-package-matcher match-ghc-foo-revision
  311. ('package
  312. ('name "ghc-foo")
  313. ('version "1.0.0")
  314. ('source
  315. ('origin
  316. ('method 'url-fetch)
  317. ('uri ('string-append
  318. "https://hackage.haskell.org/package/foo/foo-"
  319. 'version
  320. ".tar.gz"))
  321. ('sha256
  322. ('base32
  323. (? string? hash)))))
  324. ('build-system 'haskell-build-system)
  325. ('inputs
  326. ('quasiquote
  327. (("ghc-http" ('unquote 'ghc-http)))))
  328. ('arguments
  329. ('quasiquote
  330. ('#:cabal-revision
  331. ("2" "0xxd88fb659f0krljidbvvmkh9ppjnx83j0nqzx8whcg4n5qbyng"))))
  332. ('home-page "http://test.org")
  333. ('synopsis (? string?))
  334. ('description (? string?))
  335. ('license 'license:bsd-3)))
  336. (test-assert "hackage->guix-package test cabal revision"
  337. (eval-test-with-cabal test-cabal-revision match-ghc-foo-revision))
  338. (test-assert "read-cabal test 1"
  339. (match (call-with-input-string test-read-cabal-1 read-cabal)
  340. ((("name" ("test-me"))
  341. ('section 'library
  342. (('if ('flag "base4point8")
  343. (("build-depends" ("base >= 4.8 && < 5")))
  344. (('if ('flag "base4")
  345. (("build-depends" ("base >= 4 && < 4.8")))
  346. (('if ('flag "base3")
  347. (("build-depends" ("base >= 3 && < 4")))
  348. (("build-depends" ("base < 3"))))))))
  349. ('if ('or ('flag "base4point8")
  350. ('and ('flag "base4") ('flag "base3")))
  351. (("build-depends" ("random")))
  352. ())
  353. ("build-depends" ("containers"))
  354. ("exposed-modules" ("Test.QuickCheck.Exception")))))
  355. #t)
  356. (x (pk 'fail x #f))))
  357. (define test-cabal-import
  358. "name: foo
  359. version: 1.0.0
  360. homepage: http://test.org
  361. synopsis: synopsis
  362. description: description
  363. license: BSD3
  364. common commons
  365. build-depends:
  366. HTTP >= 4000.2.5 && < 4000.3,
  367. mtl >= 2.0 && < 3
  368. executable cabal
  369. import: commons
  370. ")
  371. (define-package-matcher match-ghc-foo-import
  372. ('package
  373. ('name "ghc-foo")
  374. ('version "1.0.0")
  375. ('source
  376. ('origin
  377. ('method 'url-fetch)
  378. ('uri ('string-append
  379. "https://hackage.haskell.org/package/foo/foo-"
  380. 'version
  381. ".tar.gz"))
  382. ('sha256
  383. ('base32
  384. (? string? hash)))))
  385. ('build-system 'haskell-build-system)
  386. ('inputs
  387. ('quasiquote
  388. (("ghc-http" ('unquote 'ghc-http)))))
  389. ('home-page "http://test.org")
  390. ('synopsis (? string?))
  391. ('description (? string?))
  392. ('license 'license:bsd-3)))
  393. (test-assert "hackage->guix-package test cabal import"
  394. (eval-test-with-cabal test-cabal-import match-ghc-foo-import))
  395. (test-end "hackage")