From: hololeap <hololeap@protonmail.com>
Signed-off-by: hololeap <hololeap@protonmail.com>
Bug: https://github.com/gentoo-haskell/gentoo-haskell/issues/1231

doctest pulls in the out-of-scope packages if they are installed on the
system. The best workaround is to use migrate to cabal-doctest.

diff -urN dhall-1.40.2/Setup.hs dhall-1.40.2-r2/Setup.hs
--- dhall-1.40.2/Setup.hs	2001-09-08 19:46:40.000000000 -0600
+++ dhall-1.40.2-r2/Setup.hs	2022-02-10 12:18:48.817655566 -0700
@@ -1,2 +1,6 @@
-import Distribution.Simple
-main = defaultMain
+module Main (main) where
+
+import Distribution.Extra.Doctest ( defaultMainWithDoctests )
+
+main :: IO ()
+main = defaultMainWithDoctests "dhall-doctests"
diff -urN dhall-1.40.2/dhall.cabal dhall-1.40.2-r2/dhall.cabal
--- dhall-1.40.2/dhall.cabal	2022-02-05 02:43:37.366742977 -0700
+++ dhall-1.40.2-r2/dhall.cabal	2022-02-10 12:19:18.057601721 -0700
@@ -2,7 +2,7 @@
 Version: 1.40.2
 x-revision: 2
 Cabal-Version: 2.0
-Build-Type: Simple
+Build-Type: Custom
 License: BSD3
 License-File: LICENSE
 Copyright: 2017 Gabriel Gonzalez
@@ -470,6 +470,12 @@
   Default:     False
   Manual:      True
 
+custom-setup
+  setup-depends:
+      base
+    , Cabal
+    , cabal-doctest
+
 Library
     Hs-Source-Dirs: src
     Build-Depends:
@@ -704,13 +710,16 @@
         -DWITH_HTTP
     Default-Language: Haskell2010
 
-Test-Suite doctest
+Test-Suite dhall-doctests
     Type: exitcode-stdio-1.0
     Hs-Source-Dirs: doctest
     Main-Is: Main.hs
     GHC-Options: -Wall
     Build-Depends:
         base                          ,
+        base-compat                   ,
+        QuickCheck >= 2.14 && < 2.15  ,
+        special-values          < 0.2 ,
         directory                     ,
         filepath                < 1.5 ,
         mockery                 < 0.4 ,
diff -urN dhall-1.40.2/doctest/Main.hs dhall-1.40.2-r2/doctest/Main.hs
--- dhall-1.40.2/doctest/Main.hs	2001-09-08 19:46:40.000000000 -0600
+++ dhall-1.40.2-r2/doctest/Main.hs	2022-02-10 12:21:03.037408401 -0700
@@ -10,31 +10,22 @@
 import qualified System.IO
 import qualified Test.DocTest
 import qualified Test.Mockery.Directory
+import Build_doctests (pkgs)
 
 main :: IO ()
 main = do
-
     GHC.IO.Encoding.setLocaleEncoding System.IO.utf8
     pwd    <- System.Directory.getCurrentDirectory
     prefix <- System.Directory.makeAbsolute pwd
 
-    System.Environment.setEnv "XDG_CACHE_HOME" (pwd </> ".cache")
-
-    Test.Mockery.Directory.inTempDirectory $ do
-        writeFile "makeBools.dhall" "λ(n : Bool) → [ n && True, n && False, n || True, n || False ]"
-        writeFile "bool1" "True"
-        writeFile "bool2" "False"
-        writeFile "both" "./bool1 && ./bool2"
-        writeFile "file2" "./file1"
-        writeFile "file1" "./file2"
-        writeFile "simon.dhall" $ unlines
-          [ "let Name = Text"
-          , "let Font = < Arial | `Comic Sans` | Helvetica | `Times New Roman` >"
-          , "let Person = { name : Name, favoriteFont : Font }"
-          , "in  { name = \"Simon\", favoriteFont = Font.`Comic Sans` } : Person"
-          ]
+    let customFlags =
+            [ "-package-env=-"
+            , "-hide-all-packages"
+            , "-no-user-package-db"
+            , "-package-db=" ++ prefix </> "dist/package.conf.inplace"
+            ]
 
-        Test.DocTest.doctest
+    let origArgs =
             [ "-DWITH_HTTP"
             , "-DUSE_HTTP_CLIENT_TLS"
             , "--fast"
@@ -55,3 +46,23 @@
             , prefix </> "src/Dhall/Tags.hs"
             , prefix </> "src/Dhall/Tutorial.hs"
             ]
+
+    let args = customFlags ++ pkgs ++ origArgs
+
+    System.Environment.setEnv "XDG_CACHE_HOME" (pwd </> ".cache")
+
+    Test.Mockery.Directory.inTempDirectory $ do
+        writeFile "makeBools.dhall" "λ(n : Bool) → [ n && True, n && False, n || True, n || False ]"
+        writeFile "bool1" "True"
+        writeFile "bool2" "False"
+        writeFile "both" "./bool1 && ./bool2"
+        writeFile "file2" "./file1"
+        writeFile "file1" "./file2"
+        writeFile "simon.dhall" $ unlines
+          [ "let Name = Text"
+          , "let Font = < Arial | `Comic Sans` | Helvetica | `Times New Roman` >"
+          , "let Person = { name : Name, favoriteFont : Font }"
+          , "in  { name = \"Simon\", favoriteFont = Font.`Comic Sans` } : Person"
+          ]
+
+        Test.DocTest.doctest args
