From 52cdbcdc3b510bb46f989ff618c256306d429095 Mon Sep 17 00:00:00 2001
From: hololeap <hololeap@protonmail.com>
Date: Fri, 28 Feb 2025 19:20:40 -0700
Subject: [PATCH 1/1] Migrate to cabal-doctest

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.

Bug: https://github.com/gentoo-haskell/gentoo-haskell/issues/1231
Signed-off-by: hololeap <hololeap@protonmail.com>
--- /dev/null
+++ b/Setup.hs
@@ -0,0 +1,33 @@
+{-# LANGUAGE CPP #-}
+{-# OPTIONS_GHC -Wall #-}
+module Main (main) where
+
+#ifndef MIN_VERSION_cabal_doctest
+#define MIN_VERSION_cabal_doctest(x,y,z) 0
+#endif
+
+#if MIN_VERSION_cabal_doctest(1,0,0)
+
+import Distribution.Extra.Doctest ( defaultMainWithDoctests )
+main :: IO ()
+main = defaultMainWithDoctests "doctests"
+
+#else
+
+#ifdef MIN_VERSION_Cabal
+-- If the macro is defined, we have new cabal-install,
+-- but for some reason we don't have cabal-doctest in package-db
+--
+-- Probably we are running cabal sdist, when otherwise using new-build
+-- workflow
+#warning You are configuring this package without cabal-doctest installed. \
+         The doctests test-suite will not work as a result. \
+         To fix this, install cabal-doctest before configuring.
+#endif
+
+import Distribution.Simple
+
+main :: IO ()
+main = defaultMain
+
+#endif
--- a/fixed-vector-hetero.cabal
+++ b/fixed-vector-hetero.cabal
@@ -13,10 +13,15 @@ Author:         Aleksey Khudyakov <alexey.skladnoy@gmail.com>
 Maintainer:     Aleksey Khudyakov <alexey.skladnoy@gmail.com>
 Homepage:       http://github.org/Shimuuar/fixed-vector-hetero
 Category:       Data
-Build-Type:     Simple
+Build-Type:     Custom
 extra-source-files:
   ChangeLog.md
 
+custom-setup
+  setup-depends:
+      base           < 5
+    , cabal-doctest  >=1.0.9 && <1.1
+
 tested-with:
     GHC ==8.4.4
      || ==8.6.5
@@ -63,6 +68,7 @@ test-suite doctests
   default-language: Haskell2010
   build-depends:
         base                >=4.9  && <5
+      , base-compat         >=0.10.5 && <1
       , doctest             >=0.15 && <0.24
       , fixed-vector        >=1.0
       , fixed-vector-hetero -any
--- a/test/doctests.hs
+++ b/test/doctests.hs
@@ -1,12 +1,14 @@
 module Main where
 
+import Build_doctests (flags, pkgs, module_sources)
 import Data.Foldable  (traverse_)
+import System.Environment.Compat (unsetEnv)
 import Test.DocTest   (doctest)
 
 main :: IO ()
 main = do
     traverse_ putStrLn args
+    unsetEnv "GHC_ENVIRONMENT"
     doctest args
   where
-    args = ["Data"]
-
+    args = flags ++ pkgs ++ module_sources
-- 
2.45.3

