unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#35929] [PATCH] tests: hackage: avoid mock, and extract test data
@ 2019-05-27 19:45 Robert Vollmert
  2019-05-29 21:16 ` Ludovic Courtès
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: Robert Vollmert @ 2019-05-27 19:45 UTC (permalink / raw)
  To: 35929; +Cc: Robert Vollmert

This is partially in order to make tests depend less on the
implementation of `hackage-fetch`, in preparation for hackage
revision import.

* tests/hackage.scm: Provide cabal input port directly, instead
of mocking hackage-fetch. And make cabal tests more explicit and
consistent by defining package pattern per test.
---
 tests/hackage.scm | 135 ++++++++++++++++++++++------------------------
 1 file changed, 63 insertions(+), 72 deletions(-)

diff --git a/tests/hackage.scm b/tests/hackage.scm
index 0efad0638d..a6d039afaa 100644
--- a/tests/hackage.scm
+++ b/tests/hackage.scm
@@ -155,93 +155,84 @@ library
 
 (test-begin "hackage")
 
-(define* (eval-test-with-cabal test-cabal #:key (cabal-environment '()))
-  (mock
-   ((guix import hackage) hackage-fetch
-    (lambda (name-version)
-      (call-with-input-string test-cabal
-        read-cabal)))
-   (match (hackage->guix-package "foo" #:cabal-environment cabal-environment)
-     (('package
-        ('name "ghc-foo")
-        ('version "1.0.0")
-        ('source
-         ('origin
-           ('method 'url-fetch)
-           ('uri ('string-append
-                  "https://hackage.haskell.org/package/foo/foo-"
-                  'version
-                  ".tar.gz"))
-           ('sha256
-            ('base32
-             (? string? hash)))))
-        ('build-system 'haskell-build-system)
-        ('inputs
-         ('quasiquote
-          (("ghc-http" ('unquote 'ghc-http))
-           ("ghc-mtl" ('unquote 'ghc-mtl)))))
-        ('home-page "http://test.org")
-        ('synopsis (? string?))
-        ('description (? string?))
-        ('license 'bsd-3))
-      #t)
-     (x
-      (pk 'fail x #f)))))
+(define ghc-foo-pattern
+ '('package
+    ('name "ghc-foo")
+    ('version "1.0.0")
+    ('source
+     ('origin
+      ('method 'url-fetch)
+       ('uri ('string-append
+              "https://hackage.haskell.org/package/foo/foo-"
+              'version
+              ".tar.gz"))
+       ('sha256
+        ('base32
+         (? string? hash)))))
+    ('build-system 'haskell-build-system)
+    ('inputs
+     ('quasiquote
+      (("ghc-http" ('unquote 'ghc-http))
+       ("ghc-mtl" ('unquote 'ghc-mtl)))))
+    ('home-page "http://test.org")
+    ('synopsis (? string?))
+    ('description (? string?))
+    ('license 'bsd-3)))
+
+(define* (eval-test-with-cabal test-cabal package-pattern #:key (cabal-environment '()))
+  (define port (open-input-string test-cabal))
+  (match (hackage->guix-package "foo" #:port port #:cabal-environment cabal-environment)
+    (package-pattern #t)
+    (x               (pk 'fail x #f))))
 
 (test-assert "hackage->guix-package test 1"
-  (eval-test-with-cabal test-cabal-1))
+  (eval-test-with-cabal test-cabal-1 ghc-foo-pattern))
 
 (test-assert "hackage->guix-package test 2"
-  (eval-test-with-cabal test-cabal-2))
+  (eval-test-with-cabal test-cabal-2 ghc-foo-pattern))
 
 (test-assert "hackage->guix-package test 3"
-  (eval-test-with-cabal test-cabal-3
+  (eval-test-with-cabal test-cabal-3 ghc-foo-pattern
                         #:cabal-environment '(("impl" . "ghc-7.8"))))
 
 (test-assert "hackage->guix-package test 4"
-  (eval-test-with-cabal test-cabal-4
+  (eval-test-with-cabal test-cabal-4 ghc-foo-pattern
                         #:cabal-environment '(("impl" . "ghc-7.8"))))
 
 (test-assert "hackage->guix-package test 5"
-  (eval-test-with-cabal test-cabal-5
+  (eval-test-with-cabal test-cabal-5 ghc-foo-pattern
                         #:cabal-environment '(("impl" . "ghc-7.8"))))
 
+(define ghc-foo-pattern-6
+ '('package
+    ('name "ghc-foo")
+    ('version "1.0.0")
+    ('source
+     ('origin
+      ('method 'url-fetch)
+       ('uri ('string-append
+              "https://hackage.haskell.org/package/foo/foo-"
+              'version
+              ".tar.gz"))
+       ('sha256
+        ('base32
+         (? string? hash)))))
+    ('build-system 'haskell-build-system)
+    ('inputs
+     ('quasiquote
+      (("ghc-b" ('unquote 'ghc-b))
+       ("ghc-http" ('unquote 'ghc-http))
+       ("ghc-mtl" ('unquote 'ghc-mtl)))))
+    ('native-inputs
+     ('quasiquote
+      (("ghc-haskell-gi" ('unquote 'ghc-haskell-gi)))))
+    ('home-page "http://test.org")
+    ('synopsis (? string?))
+    ('description (? string?))
+    ('license 'bsd-3)))
+
 (test-assert "hackage->guix-package test 6"
-  (mock
-   ((guix import hackage) hackage-fetch
-    (lambda (name-version)
-      (call-with-input-string test-cabal-6
-        read-cabal)))
-   (match (hackage->guix-package "foo")
-     (('package
-        ('name "ghc-foo")
-        ('version "1.0.0")
-        ('source
-         ('origin
-           ('method 'url-fetch)
-           ('uri ('string-append
-                  "https://hackage.haskell.org/package/foo/foo-"
-                  'version
-                  ".tar.gz"))
-           ('sha256
-            ('base32
-             (? string? hash)))))
-        ('build-system 'haskell-build-system)
-        ('inputs
-         ('quasiquote
-          (("ghc-b" ('unquote 'ghc-b))
-           ("ghc-http" ('unquote 'ghc-http))
-           ("ghc-mtl" ('unquote 'ghc-mtl)))))
-        ('native-inputs
-         ('quasiquote
-          (("ghc-haskell-gi" ('unquote 'ghc-haskell-gi)))))
-        ('home-page "http://test.org")
-        ('synopsis (? string?))
-        ('description (? string?))
-        ('license 'bsd-3))
-      #t)
-     (x
-      (pk 'fail x #f)))))
+  (eval-test-with-cabal test-cabal-6 ghc-foo-pattern-6))
 
 (test-assert "read-cabal test 1"
   (match (call-with-input-string test-read-cabal-1 read-cabal)
-- 
2.20.1 (Apple Git-117)

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2019-06-01 12:56 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-27 19:45 [bug#35929] [PATCH] tests: hackage: avoid mock, and extract test data Robert Vollmert
2019-05-29 21:16 ` Ludovic Courtès
2019-05-29 21:25   ` Robert Vollmert
2019-05-30 11:42   ` Robert Vollmert
2019-05-31 17:57     ` Ludovic Courtès
2019-05-30 11:46 ` [bug#35929] [PATCH 1/2] tests: hackage: Factor out package pattern Robert Vollmert
2019-05-30 11:46   ` [bug#35929] [PATCH 2/2] tests: hackage: Don't mock hackage-fetch Robert Vollmert
2019-05-31 19:36 ` [bug#35929] [PATCH 1/2] tests: hackage: Factor out package pattern Robert Vollmert
2019-05-31 19:36   ` [bug#35929] [PATCH 2/2] tests: hackage: Don't mock hackage-fetch Robert Vollmert
2019-05-31 21:22 ` [bug#35929] [PATCH 1/3] tests: hackage: Factor out package pattern Robert Vollmert
2019-05-31 21:22   ` [bug#35929] [PATCH 2/3] tests: hackage: Don't mock hackage-fetch Robert Vollmert
2019-05-31 21:22   ` [bug#35929] [PATCH 3/3] tests: Indent hackage tests Robert Vollmert
2019-05-31 21:23   ` [bug#35929] [PATCH 1/3] tests: hackage: Factor out package pattern Robert Vollmert
2019-06-01 12:53     ` bug#35929: " Ludovic Courtès

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).