gnu: gdm: Fix config file path.
[guix.git] / tests / hackage.scm
bloba4de8be91e0d06598718781c3c05f5036f29e696
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/>.
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))
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
39 (define test-cabal-2
40   "name: foo
41 version: 1.0.0
42 homepage: http://test.org
43 synopsis: synopsis
44 description: description
45 license: BSD3
46 executable cabal {
47 build-depends:
48   HTTP       >= 4000.2.5 && < 4000.3,
49   mtl        >= 2.0      && < 3
53 ;; Check compiler implementation test with and without spaces.
54 (define test-cabal-3
55   "name: foo
56 version: 1.0.0
57 homepage: http://test.org
58 synopsis: synopsis
59 description: description
60 license: BSD3
61 library
62   if impl(ghc >= 7.2 && < 7.6)
63     Build-depends: ghc-a
64   if impl(ghc>=7.2&&<7.6)
65     Build-depends: ghc-b
66   if impl(ghc == 7.8)
67     Build-depends: 
68       HTTP       >= 4000.2.5 && < 4000.3,
69       mtl        >= 2.0      && < 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
76   "name: test-me
77 library
78   -- Choose which library versions to use.
79   if flag(base4point8)
80     Build-depends: base >= 4.8 && < 5
81   else
82     if flag(base4)
83       Build-depends: base >= 4 && < 4.8
84     else
85       if flag(base3)
86         Build-depends: base >= 3 && < 4
87       else
88         Build-depends: base < 3
89   if flag(base4point8) || flag (base4) && flag(base3)
90     Build-depends: random
91   Build-depends : containers
93   -- Modules that are always built.
94   Exposed-Modules:
95     Test.QuickCheck.Exception")
97 (test-begin "hackage")
99 (define* (eval-test-with-cabal test-cabal #:key (cabal-environment '()))
100   (mock
101    ((guix import hackage) hackage-fetch
102     (lambda (name-version)
103       (call-with-input-string test-cabal
104         read-cabal)))
105    (match (hackage->guix-package "foo" #:cabal-environment cabal-environment)
106      (('package
107         ('name "ghc-foo")
108         ('version "1.0.0")
109         ('source
110          ('origin
111            ('method 'url-fetch)
112            ('uri ('string-append
113                   "https://hackage.haskell.org/package/foo/foo-"
114                   'version
115                   ".tar.gz"))
116            ('sha256
117             ('base32
118              (? string? hash)))))
119         ('build-system 'haskell-build-system)
120         ('inputs
121          ('quasiquote
122           (("ghc-http" ('unquote 'ghc-http))
123            ("ghc-mtl" ('unquote 'ghc-mtl)))))
124         ('home-page "http://test.org")
125         ('synopsis (? string?))
126         ('description (? string?))
127         ('license 'bsd-3))
128       #t)
129      (x
130       (pk 'fail x #f)))))
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"))
145       ('section 'library
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")))
156                     ())
157                 ("build-depends" ("containers"))
158                 ("exposed-modules" ("Test.QuickCheck.Exception")))))
159      #t)
160     (x (pk 'fail x #f))))
162 (test-end "hackage")