tests: hackage: Factor out package pattern.

* tests/hackage.scm: Import result pattern matching via helper.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
Robert Vollmert 2019-05-31 23:22:41 +02:00 committed by Ludovic Courtès
parent 87399dfc20
commit 55c98f3261
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
1 changed files with 66 additions and 67 deletions

View File

@ -155,14 +155,14 @@ library
(test-begin "hackage") (test-begin "hackage")
(define* (eval-test-with-cabal test-cabal #:key (cabal-environment '())) (define-syntax-rule (define-package-matcher name pattern)
(mock (define* (name obj)
((guix import hackage) hackage-fetch (match obj
(lambda (name-version) (pattern #t)
(call-with-input-string test-cabal (x (pk 'fail x #f)))))
read-cabal)))
(match (hackage->guix-package "foo" #:cabal-environment cabal-environment) (define-package-matcher match-ghc-foo
(('package ('package
('name "ghc-foo") ('name "ghc-foo")
('version "1.0.0") ('version "1.0.0")
('source ('source
@ -183,37 +183,36 @@ library
('home-page "http://test.org") ('home-page "http://test.org")
('synopsis (? string?)) ('synopsis (? string?))
('description (? string?)) ('description (? string?))
('license 'bsd-3)) ('license 'bsd-3)))
#t)
(x
(pk 'fail x #f)))))
(test-assert "hackage->guix-package test 1" (define* (eval-test-with-cabal test-cabal matcher #:key (cabal-environment '()))
(eval-test-with-cabal test-cabal-1))
(test-assert "hackage->guix-package test 2"
(eval-test-with-cabal test-cabal-2))
(test-assert "hackage->guix-package test 3"
(eval-test-with-cabal test-cabal-3
#:cabal-environment '(("impl" . "ghc-7.8"))))
(test-assert "hackage->guix-package test 4"
(eval-test-with-cabal test-cabal-4
#:cabal-environment '(("impl" . "ghc-7.8"))))
(test-assert "hackage->guix-package test 5"
(eval-test-with-cabal test-cabal-5
#:cabal-environment '(("impl" . "ghc-7.8"))))
(test-assert "hackage->guix-package test 6"
(mock (mock
((guix import hackage) hackage-fetch ((guix import hackage) hackage-fetch
(lambda (name-version) (lambda (name-version)
(call-with-input-string test-cabal-6 (call-with-input-string test-cabal
read-cabal))) read-cabal)))
(match (hackage->guix-package "foo") (matcher (hackage->guix-package "foo" #:cabal-environment cabal-environment))))
(('package
(test-assert "hackage->guix-package test 1"
(eval-test-with-cabal test-cabal-1 match-ghc-foo))
(test-assert "hackage->guix-package test 2"
(eval-test-with-cabal test-cabal-2 match-ghc-foo))
(test-assert "hackage->guix-package test 3"
(eval-test-with-cabal test-cabal-3 match-ghc-foo
#:cabal-environment '(("impl" . "ghc-7.8"))))
(test-assert "hackage->guix-package test 4"
(eval-test-with-cabal test-cabal-4 match-ghc-foo
#:cabal-environment '(("impl" . "ghc-7.8"))))
(test-assert "hackage->guix-package test 5"
(eval-test-with-cabal test-cabal-5 match-ghc-foo
#:cabal-environment '(("impl" . "ghc-7.8"))))
(define-package-matcher match-ghc-foo-6
('package
('name "ghc-foo") ('name "ghc-foo")
('version "1.0.0") ('version "1.0.0")
('source ('source
@ -238,10 +237,10 @@ library
('home-page "http://test.org") ('home-page "http://test.org")
('synopsis (? string?)) ('synopsis (? string?))
('description (? string?)) ('description (? string?))
('license 'bsd-3)) ('license 'bsd-3)))
#t)
(x (test-assert "hackage->guix-package test 6"
(pk 'fail x #f))))) (eval-test-with-cabal test-cabal-6 match-ghc-foo-6))
(test-assert "read-cabal test 1" (test-assert "read-cabal test 1"
(match (call-with-input-string test-read-cabal-1 read-cabal) (match (call-with-input-string test-read-cabal-1 read-cabal)