diff options
| author | Robert Vollmert <rob@vllmrt.net> | 2019-05-31 23:22:41 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2019-06-01 15:26:30 +0200 |
| commit | 55c98f3261b6ced2c38e060566e1eb952bd3e42b (patch) | |
| tree | ab3b123cca30606f24f6ffac26c3aac1a9a28361 /tests | |
| parent | 87399dfc209fdec523947e7b45a1ad348afa4d46 (diff) | |
tests: hackage: Factor out package pattern.
* tests/hackage.scm: Import result pattern matching via helper.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/hackage.scm | 133 |
1 files changed, 66 insertions, 67 deletions
diff --git a/tests/hackage.scm b/tests/hackage.scm index 0efad0638d2..41e3b2dcd38 100644 --- a/tests/hackage.scm +++ b/tests/hackage.scm | |||
| @@ -155,93 +155,92 @@ library | |||
| 155 | 155 | ||
| 156 | (test-begin "hackage") | 156 | (test-begin "hackage") |
| 157 | 157 | ||
| 158 | (define* (eval-test-with-cabal test-cabal #:key (cabal-environment '())) | 158 | (define-syntax-rule (define-package-matcher name pattern) |
| 159 | (define* (name obj) | ||
| 160 | (match obj | ||
| 161 | (pattern #t) | ||
| 162 | (x (pk 'fail x #f))))) | ||
| 163 | |||
| 164 | (define-package-matcher match-ghc-foo | ||
| 165 | ('package | ||
| 166 | ('name "ghc-foo") | ||
| 167 | ('version "1.0.0") | ||
| 168 | ('source | ||
| 169 | ('origin | ||
| 170 | ('method 'url-fetch) | ||
| 171 | ('uri ('string-append | ||
| 172 | "https://hackage.haskell.org/package/foo/foo-" | ||
| 173 | 'version | ||
| 174 | ".tar.gz")) | ||
| 175 | ('sha256 | ||
| 176 | ('base32 | ||
| 177 | (? string? hash))))) | ||
| 178 | ('build-system 'haskell-build-system) | ||
| 179 | ('inputs | ||
| 180 | ('quasiquote | ||
| 181 | (("ghc-http" ('unquote 'ghc-http)) | ||
| 182 | ("ghc-mtl" ('unquote 'ghc-mtl))))) | ||
| 183 | ('home-page "http://test.org") | ||
| 184 | ('synopsis (? string?)) | ||
| 185 | ('description (? string?)) | ||
| 186 | ('license 'bsd-3))) | ||
| 187 | |||
| 188 | (define* (eval-test-with-cabal test-cabal matcher #:key (cabal-environment '())) | ||
| 159 | (mock | 189 | (mock |
| 160 | ((guix import hackage) hackage-fetch | 190 | ((guix import hackage) hackage-fetch |
| 161 | (lambda (name-version) | 191 | (lambda (name-version) |
| 162 | (call-with-input-string test-cabal | 192 | (call-with-input-string test-cabal |
| 163 | read-cabal))) | 193 | read-cabal))) |
| 164 | (match (hackage->guix-package "foo" #:cabal-environment cabal-environment) | 194 | (matcher (hackage->guix-package "foo" #:cabal-environment cabal-environment)))) |
| 165 | (('package | ||
| 166 | ('name "ghc-foo") | ||
| 167 | ('version "1.0.0") | ||
| 168 | ('source | ||
| 169 | ('origin | ||
| 170 | ('method 'url-fetch) | ||
| 171 | ('uri ('string-append | ||
| 172 | "https://hackage.haskell.org/package/foo/foo-" | ||
| 173 | 'version | ||
| 174 | ".tar.gz")) | ||
| 175 | ('sha256 | ||
| 176 | ('base32 | ||
| 177 | (? string? hash))))) | ||
| 178 | ('build-system 'haskell-build-system) | ||
| 179 | ('inputs | ||
| 180 | ('quasiquote | ||
| 181 | (("ghc-http" ('unquote 'ghc-http)) | ||
| 182 | ("ghc-mtl" ('unquote 'ghc-mtl))))) | ||
| 183 | ('home-page "http://test.org") | ||
| 184 | ('synopsis (? string?)) | ||
| 185 | ('description (? string?)) | ||
| 186 | ('license 'bsd-3)) | ||
| 187 | #t) | ||
| 188 | (x | ||
| 189 | (pk 'fail x #f))))) | ||
| 190 | 195 | ||
| 191 | (test-assert "hackage->guix-package test 1" | 196 | (test-assert "hackage->guix-package test 1" |
| 192 | (eval-test-with-cabal test-cabal-1)) | 197 | (eval-test-with-cabal test-cabal-1 match-ghc-foo)) |
| 193 | 198 | ||
| 194 | (test-assert "hackage->guix-package test 2" | 199 | (test-assert "hackage->guix-package test 2" |
| 195 | (eval-test-with-cabal test-cabal-2)) | 200 | (eval-test-with-cabal test-cabal-2 match-ghc-foo)) |
| 196 | 201 | ||
| 197 | (test-assert "hackage->guix-package test 3" | 202 | (test-assert "hackage->guix-package test 3" |
| 198 | (eval-test-with-cabal test-cabal-3 | 203 | (eval-test-with-cabal test-cabal-3 match-ghc-foo |
| 199 | #:cabal-environment '(("impl" . "ghc-7.8")))) | 204 | #:cabal-environment '(("impl" . "ghc-7.8")))) |
| 200 | 205 | ||
| 201 | (test-assert "hackage->guix-package test 4" | 206 | (test-assert "hackage->guix-package test 4" |
| 202 | (eval-test-with-cabal test-cabal-4 | 207 | (eval-test-with-cabal test-cabal-4 match-ghc-foo |
| 203 | #:cabal-environment '(("impl" . "ghc-7.8")))) | 208 | #:cabal-environment '(("impl" . "ghc-7.8")))) |
| 204 | 209 | ||
| 205 | (test-assert "hackage->guix-package test 5" | 210 | (test-assert "hackage->guix-package test 5" |
| 206 | (eval-test-with-cabal test-cabal-5 | 211 | (eval-test-with-cabal test-cabal-5 match-ghc-foo |
| 207 | #:cabal-environment '(("impl" . "ghc-7.8")))) | 212 | #:cabal-environment '(("impl" . "ghc-7.8")))) |
| 208 | 213 | ||
| 214 | (define-package-matcher match-ghc-foo-6 | ||
| 215 | ('package | ||
| 216 | ('name "ghc-foo") | ||
| 217 | ('version "1.0.0") | ||
| 218 | ('source | ||
| 219 | ('origin | ||
| 220 | ('method 'url-fetch) | ||
| 221 | ('uri ('string-append | ||
| 222 | "https://hackage.haskell.org/package/foo/foo-" | ||
| 223 | 'version | ||
| 224 | ".tar.gz")) | ||
| 225 | ('sha256 | ||
| 226 | ('base32 | ||
| 227 | (? string? hash))))) | ||
| 228 | ('build-system 'haskell-build-system) | ||
| 229 | ('inputs | ||
| 230 | ('quasiquote | ||
| 231 | (("ghc-b" ('unquote 'ghc-b)) | ||
| 232 | ("ghc-http" ('unquote 'ghc-http)) | ||
| 233 | ("ghc-mtl" ('unquote 'ghc-mtl))))) | ||
| 234 | ('native-inputs | ||
| 235 | ('quasiquote | ||
| 236 | (("ghc-haskell-gi" ('unquote 'ghc-haskell-gi))))) | ||
| 237 | ('home-page "http://test.org") | ||
| 238 | ('synopsis (? string?)) | ||
| 239 | ('description (? string?)) | ||
| 240 | ('license 'bsd-3))) | ||
| 241 | |||
| 209 | (test-assert "hackage->guix-package test 6" | 242 | (test-assert "hackage->guix-package test 6" |
| 210 | (mock | 243 | (eval-test-with-cabal test-cabal-6 match-ghc-foo-6)) |
| 211 | ((guix import hackage) hackage-fetch | ||
| 212 | (lambda (name-version) | ||
| 213 | (call-with-input-string test-cabal-6 | ||
| 214 | read-cabal))) | ||
| 215 | (match (hackage->guix-package "foo") | ||
| 216 | (('package | ||
| 217 | ('name "ghc-foo") | ||
| 218 | ('version "1.0.0") | ||
| 219 | ('source | ||
| 220 | ('origin | ||
| 221 | ('method 'url-fetch) | ||
| 222 | ('uri ('string-append | ||
| 223 | "https://hackage.haskell.org/package/foo/foo-" | ||
| 224 | 'version | ||
| 225 | ".tar.gz")) | ||
| 226 | ('sha256 | ||
| 227 | ('base32 | ||
| 228 | (? string? hash))))) | ||
| 229 | ('build-system 'haskell-build-system) | ||
| 230 | ('inputs | ||
| 231 | ('quasiquote | ||
| 232 | (("ghc-b" ('unquote 'ghc-b)) | ||
| 233 | ("ghc-http" ('unquote 'ghc-http)) | ||
| 234 | ("ghc-mtl" ('unquote 'ghc-mtl))))) | ||
| 235 | ('native-inputs | ||
| 236 | ('quasiquote | ||
| 237 | (("ghc-haskell-gi" ('unquote 'ghc-haskell-gi))))) | ||
| 238 | ('home-page "http://test.org") | ||
| 239 | ('synopsis (? string?)) | ||
| 240 | ('description (? string?)) | ||
| 241 | ('license 'bsd-3)) | ||
| 242 | #t) | ||
| 243 | (x | ||
| 244 | (pk 'fail x #f))))) | ||
| 245 | 244 | ||
| 246 | (test-assert "read-cabal test 1" | 245 | (test-assert "read-cabal test 1" |
| 247 | (match (call-with-input-string test-read-cabal-1 read-cabal) | 246 | (match (call-with-input-string test-read-cabal-1 read-cabal) |
