hackage.scm 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2015 Federico Beffa <beffa@fbengineering.ch>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (test-hackage)
  19. #:use-module (guix import cabal)
  20. #:use-module (guix import hackage)
  21. #:use-module (guix tests)
  22. #:use-module (srfi srfi-64)
  23. #:use-module (ice-9 match))
  24. (define test-cabal-1
  25. "name: foo
  26. version: 1.0.0
  27. homepage: http://test.org
  28. synopsis: synopsis
  29. description: description
  30. license: BSD3
  31. executable cabal
  32. build-depends:
  33. HTTP >= 4000.2.5 && < 4000.3,
  34. mtl >= 2.0 && < 3
  35. ")
  36. (define test-cabal-2
  37. "name: foo
  38. version: 1.0.0
  39. homepage: http://test.org
  40. synopsis: synopsis
  41. description: description
  42. license: BSD3
  43. executable cabal {
  44. build-depends:
  45. HTTP >= 4000.2.5 && < 4000.3,
  46. mtl >= 2.0 && < 3
  47. }
  48. ")
  49. ;; Check compiler implementation test with and without spaces.
  50. (define test-cabal-3
  51. "name: foo
  52. version: 1.0.0
  53. homepage: http://test.org
  54. synopsis: synopsis
  55. description: description
  56. license: BSD3
  57. library
  58. if impl(ghc >= 7.2 && < 7.6)
  59. Build-depends: ghc-a
  60. if impl(ghc>=7.2&&<7.6)
  61. Build-depends: ghc-b
  62. if impl(ghc == 7.8)
  63. Build-depends:
  64. HTTP >= 4000.2.5 && < 4000.3,
  65. mtl >= 2.0 && < 3
  66. ")
  67. ;; Check "-any", "-none" when name is different.
  68. (define test-cabal-4
  69. "name: foo
  70. version: 1.0.0
  71. homepage: http://test.org
  72. synopsis: synopsis
  73. description: description
  74. license: BSD3
  75. library
  76. if impl(ghcjs -any)
  77. Build-depends: ghc-a
  78. if impl(ghc>=7.2&&<7.6)
  79. Build-depends: ghc-b
  80. if impl(ghc == 7.8)
  81. Build-depends:
  82. HTTP >= 4000.2.5 && < 4000.3,
  83. mtl >= 2.0 && < 3
  84. ")
  85. ;; Check "-any", "-none".
  86. (define test-cabal-5
  87. "name: foo
  88. version: 1.0.0
  89. homepage: http://test.org
  90. synopsis: synopsis
  91. description: description
  92. license: BSD3
  93. library
  94. if impl(ghc == 7.8)
  95. Build-depends:
  96. HTTP >= 4000.2.5 && < 4000.3,
  97. if impl(ghc -any)
  98. Build-depends: mtl >= 2.0 && < 3
  99. if impl(ghc>=7.2&&<7.6)
  100. Build-depends: ghc-b
  101. ")
  102. ;; Check "custom-setup".
  103. (define test-cabal-6
  104. "name: foo
  105. build-type: Custom
  106. version: 1.0.0
  107. homepage: http://test.org
  108. synopsis: synopsis
  109. description: description
  110. license: BSD3
  111. custom-setup
  112. setup-depends: base >= 4.7 && < 5,
  113. Cabal >= 1.24,
  114. haskell-gi == 0.21.*
  115. library
  116. if impl(ghc>=7.2&&<7.6)
  117. Build-depends: ghc-b
  118. if impl(ghc == 7.8)
  119. Build-depends:
  120. HTTP >= 4000.2.5 && < 4000.3,
  121. mtl >= 2.0 && < 3
  122. ")
  123. ;; A fragment of a real Cabal file with minor modification to check precedence
  124. ;; of 'and' over 'or', missing final newline, spaces between keywords and
  125. ;; parentheses and between key and column.
  126. (define test-read-cabal-1
  127. "name: test-me
  128. library
  129. -- Choose which library versions to use.
  130. if flag(base4point8)
  131. Build-depends: base >= 4.8 && < 5
  132. else
  133. if flag(base4)
  134. Build-depends: base >= 4 && < 4.8
  135. else
  136. if flag(base3)
  137. Build-depends: base >= 3 && < 4
  138. else
  139. Build-depends: base < 3
  140. if flag(base4point8) || flag (base4) && flag(base3)
  141. Build-depends: random
  142. Build-depends : containers
  143. -- Modules that are always built.
  144. Exposed-Modules:
  145. Test.QuickCheck.Exception")
  146. (test-begin "hackage")
  147. (define* (eval-test-with-cabal test-cabal #:key (cabal-environment '()))
  148. (mock
  149. ((guix import hackage) hackage-fetch
  150. (lambda (name-version)
  151. (call-with-input-string test-cabal
  152. read-cabal)))
  153. (match (hackage->guix-package "foo" #:cabal-environment cabal-environment)
  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. ("ghc-mtl" ('unquote 'ghc-mtl)))))
  172. ('home-page "http://test.org")
  173. ('synopsis (? string?))
  174. ('description (? string?))
  175. ('license 'bsd-3))
  176. #t)
  177. (x
  178. (pk 'fail x #f)))))
  179. (test-assert "hackage->guix-package test 1"
  180. (eval-test-with-cabal test-cabal-1))
  181. (test-assert "hackage->guix-package test 2"
  182. (eval-test-with-cabal test-cabal-2))
  183. (test-assert "hackage->guix-package test 3"
  184. (eval-test-with-cabal test-cabal-3
  185. #:cabal-environment '(("impl" . "ghc-7.8"))))
  186. (test-assert "hackage->guix-package test 4"
  187. (eval-test-with-cabal test-cabal-4
  188. #:cabal-environment '(("impl" . "ghc-7.8"))))
  189. (test-assert "hackage->guix-package test 5"
  190. (eval-test-with-cabal test-cabal-5
  191. #:cabal-environment '(("impl" . "ghc-7.8"))))
  192. (test-assert "hackage->guix-package test 6"
  193. (eval-test-with-cabal test-cabal-6
  194. #:cabal-environment '(("impl" . "ghc-7.8"))))
  195. (test-assert "read-cabal test 1"
  196. (match (call-with-input-string test-read-cabal-1 read-cabal)
  197. ((("name" ("test-me"))
  198. ('section 'library
  199. (('if ('flag "base4point8")
  200. (("build-depends" ("base >= 4.8 && < 5")))
  201. (('if ('flag "base4")
  202. (("build-depends" ("base >= 4 && < 4.8")))
  203. (('if ('flag "base3")
  204. (("build-depends" ("base >= 3 && < 4")))
  205. (("build-depends" ("base < 3"))))))))
  206. ('if ('or ('flag "base4point8")
  207. ('and ('flag "base4") ('flag "base3")))
  208. (("build-depends" ("random")))
  209. ())
  210. ("build-depends" ("containers"))
  211. ("exposed-modules" ("Test.QuickCheck.Exception")))))
  212. #t)
  213. (x (pk 'fail x #f))))
  214. (test-end "hackage")