hackage.scm 10 KB

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