jonascarpay/template-haskell

Using doctest

Closed this issue · 4 comments

Hi,

I've applied your template to a small project but can't make doctest to run in GitHub Actions: it works for the stack build, but not for cabal or nix.

Do you have any idea what could be wrong?

I personally don't use doctest, but a coworker who does explained that the issue is that doctest doesn't automatically pick up the project package db. You can try passing it as a flag through the haskell.nix module system like this:

diff --git a/pkgs.nix b/pkgs.nix
index d5871aa..b0d42c3 100644
--- a/pkgs.nix
+++ b/pkgs.nix
@@ -20,6 +20,11 @@ let
         name = "PKGNAME";
       };
       compiler-nix-name = "ghc8104";
+      modules = [{
+        packages.PKGNAME.components.tests.DOCTESTS.testFlags = [
+          "-package-db=${self.hsPkgs.PKGNAME.components.library.configFiles}/lib/ghc-8.10.4/package.conf.d/"
+        ];
+      }];
     };
   };
 in

where PKGNAME and DOCTESTS refer to the actual pkg name and name of the doctest suite, respectively.

Does this mean I have to create a dedicated doctest test-suite in the .cabal file? The name of the test-suite would be what you call DOCTESTS above?

Oh, yeah, I was assuming you had a doctest suite. But calling the binary yourself has the same issue, you need to somehow pass it the package db. All I know is that the solution above has worked for my coworker, but there's also this PR (coincidentally by a different coworker) which might provide some useful insight.

Thank you very much for your answer. From what I understand, the support for doctest is not really there yet and developers are actively working on it. I will give up for now.

I don't think there is much to be done in template-haskell so I'm also closing this issue. Feel free to reopen it if you want to.