hackage.scm 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. ;; A fragment of a real Cabal file with minor modification to check precedence
  68. ;; of 'and' over 'or', missing final newline, spaces between keywords and
  69. ;; parentheses and between key and column.
  70. (define test-read-cabal-1
  71. "name: test-me
  72. library
  73. -- Choose which library versions to use.
  74. if flag(base4point8)
  75. Build-depends: base >= 4.8 && < 5
  76. else
  77. if flag(base4)
  78. Build-depends: base >= 4 && < 4.8
  79. else
  80. if flag(base3)
  81. Build-depends: base >= 3 && < 4
  82. else
  83. Build-depends: base < 3
  84. if flag(base4point8) || flag (base4) && flag(base3)
  85. Build-depends: random
  86. Build-depends : containers
  87. -- Modules that are always built.
  88. Exposed-Modules:
  89. Test.QuickCheck.Exception")
  90. (test-begin "hackage")
  91. (define* (eval-test-with-cabal test-cabal #:key (cabal-environment '()))
  92. (mock
  93. ((guix import hackage) hackage-fetch
  94. (lambda (name-version)
  95. (call-with-input-string test-cabal
  96. read-cabal)))
  97. (match (hackage->guix-package "foo" #:cabal-environment cabal-environment)
  98. (('package
  99. ('name "ghc-foo")
  100. ('version "1.0.0")
  101. ('source
  102. ('origin
  103. ('method 'url-fetch)
  104. ('uri ('string-append
  105. "https://hackage.haskell.org/package/foo/foo-"
  106. 'version
  107. ".tar.gz"))
  108. ('sha256
  109. ('base32
  110. (? string? hash)))))
  111. ('build-system 'haskell-build-system)
  112. ('inputs
  113. ('quasiquote
  114. (("ghc-http" ('unquote 'ghc-http))
  115. ("ghc-mtl" ('unquote 'ghc-mtl)))))
  116. ('home-page "http://test.org")
  117. ('synopsis (? string?))
  118. ('description (? string?))
  119. ('license 'bsd-3))
  120. #t)
  121. (x
  122. (pk 'fail x #f)))))
  123. (test-assert "hackage->guix-package test 1"
  124. (eval-test-with-cabal test-cabal-1))
  125. (test-assert "hackage->guix-package test 2"
  126. (eval-test-with-cabal test-cabal-2))
  127. (test-assert "hackage->guix-package test 3"
  128. (eval-test-with-cabal test-cabal-3
  129. #:cabal-environment '(("impl" . "ghc-7.8"))))
  130. (test-assert "read-cabal test 1"
  131. (match (call-with-input-string test-read-cabal-1 read-cabal)
  132. ((("name" ("test-me"))
  133. ('section 'library
  134. (('if ('flag "base4point8")
  135. (("build-depends" ("base >= 4.8 && < 5")))
  136. (('if ('flag "base4")
  137. (("build-depends" ("base >= 4 && < 4.8")))
  138. (('if ('flag "base3")
  139. (("build-depends" ("base >= 3 && < 4")))
  140. (("build-depends" ("base < 3"))))))))
  141. ('if ('or ('flag "base4point8")
  142. ('and ('flag "base4") ('flag "base3")))
  143. (("build-depends" ("random")))
  144. ())
  145. ("build-depends" ("containers"))
  146. ("exposed-modules" ("Test.QuickCheck.Exception")))))
  147. #t)
  148. (x (pk 'fail x #f))))
  149. (test-end "hackage")