1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015 Federico Beffa <beffa@fbengineering.ch>
4 ;;; This file is part of GNU Guix.
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.
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.
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/>.
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))
29 homepage: http://test.org
31 description: description
35 HTTP >= 4000.2.5 && < 4000.3,
42 homepage: http://test.org
44 description: description
48 HTTP >= 4000.2.5 && < 4000.3,
53 ;; Check compiler implementation test with and without spaces.
57 homepage: http://test.org
59 description: description
62 if impl(ghc >= 7.2 && < 7.6)
64 if impl(ghc>=7.2&&<7.6)
68 HTTP >= 4000.2.5 && < 4000.3,
72 ;; A fragment of a real Cabal file with minor modification to check precedence
73 ;; of 'and' over 'or', missing final newline, spaces between keywords and
74 ;; parentheses and between key and column.
75 (define test-read-cabal-1
78 -- Choose which library versions to use.
80 Build-depends: base >= 4.8 && < 5
83 Build-depends: base >= 4 && < 4.8
86 Build-depends: base >= 3 && < 4
88 Build-depends: base < 3
89 if flag(base4point8) || flag (base4) && flag(base3)
91 Build-depends : containers
93 -- Modules that are always built.
95 Test.QuickCheck.Exception")
97 (test-begin "hackage")
99 (define* (eval-test-with-cabal test-cabal #:key (cabal-environment '()))
101 ((guix import hackage) hackage-fetch
102 (lambda (name-version)
103 (call-with-input-string test-cabal
105 (match (hackage->guix-package "foo" #:cabal-environment cabal-environment)
112 ('uri ('string-append
113 "https://hackage.haskell.org/package/foo/foo-"
119 ('build-system 'haskell-build-system)
122 (("ghc-http" ('unquote 'ghc-http))
123 ("ghc-mtl" ('unquote 'ghc-mtl)))))
124 ('home-page "http://test.org")
125 ('synopsis (? string?))
126 ('description (? string?))
132 (test-assert "hackage->guix-package test 1"
133 (eval-test-with-cabal test-cabal-1))
135 (test-assert "hackage->guix-package test 2"
136 (eval-test-with-cabal test-cabal-2))
138 (test-assert "hackage->guix-package test 3"
139 (eval-test-with-cabal test-cabal-3
140 #:cabal-environment '(("impl" . "ghc-7.8"))))
142 (test-assert "read-cabal test 1"
143 (match (call-with-input-string test-read-cabal-1 read-cabal)
144 ((("name" ("test-me"))
146 (('if ('flag "base4point8")
147 (("build-depends" ("base >= 4.8 && < 5")))
148 (('if ('flag "base4")
149 (("build-depends" ("base >= 4 && < 4.8")))
150 (('if ('flag "base3")
151 (("build-depends" ("base >= 3 && < 4")))
152 (("build-depends" ("base < 3"))))))))
153 ('if ('or ('flag "base4point8")
154 ('and ('flag "base4") ('flag "base3")))
155 (("build-depends" ("random")))
157 ("build-depends" ("containers"))
158 ("exposed-modules" ("Test.QuickCheck.Exception")))))
160 (x (pk 'fail x #f))))