| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 |
|
| 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 |
|
| 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
|
| 37 | ")
|
| 38 |
|
| 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
|
| 50 | }
|
| 51 | ")
|
| 52 |
|
| 53 | |
| 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
|
| 70 | ")
|
| 71 |
|
| 72 | |
| 73 | |
| 74 | |
| 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
|
| 92 |
|
| 93 | -- Modules that are always built.
|
| 94 | Exposed-Modules:
|
| 95 | Test.QuickCheck.Exception")
|
| 96 |
|
| 97 | (test-begin "hackage")
|
| 98 |
|
| 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)))))
|
| 131 |
|
| 132 | (test-assert "hackage->guix-package test 1"
|
| 133 | (eval-test-with-cabal test-cabal-1))
|
| 134 |
|
| 135 | (test-assert "hackage->guix-package test 2"
|
| 136 | (eval-test-with-cabal test-cabal-2))
|
| 137 |
|
| 138 | (test-assert "hackage->guix-package test 3"
|
| 139 | (eval-test-with-cabal test-cabal-3
|
| 140 | #:cabal-environment '(("impl" . "ghc-7.8"))))
|
| 141 |
|
| 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))))
|
| 161 |
|
| 162 | (test-end "hackage")
|