use the Build_doctests module of cabal-doctest to pass the in-place package DB
and only the packages of the test suite.

--- a/checked-literals.cabal
+++ b/checked-literals.cabal
@@ -15,7 +15,7 @@
 author: Martijn Bastiaan
 maintainer: QBayLogic B.V. <devops@qbaylogic.com>
 category: Development
-build-type: Simple
+build-type: Custom
 extra-doc-files:
   CHANGELOG.md
   README.md
@@ -25,6 +25,12 @@
   src-nums/CheckedLiterals/Nums/Signed.hs
   src-nums/CheckedLiterals/Nums/Unsigned.hs
 
+custom-setup
+  setup-depends:
+    base,
+    Cabal,
+    cabal-doctest >=1.0.0,
+
 common warnings
   ghc-options: -Wall
 
@@ -116,6 +122,8 @@
   build-depends:
     base,
     checked-literals,
+    directory,
+    filepath,
     process,
     string-interpolate >=0.3.4.0,
     tasty >=0.10,
--- /dev/null
+++ b/Setup.hs
@@ -0,0 +1,23 @@
+{-# LANGUAGE CPP #-}
+
+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 "unittests"
+
+#else
+
+import Distribution.Simple
+
+main :: IO ()
+main = defaultMain
+
+#endif
--- a/tests/Test/Tasty/AssertGhc.hs
+++ b/tests/Test/Tasty/AssertGhc.hs
@@ -4,9 +4,12 @@
 
 import Prelude
 
+import Build_doctests (pkgs)
 import Data.List (isInfixOf)
 import Data.Maybe (fromMaybe)
+import System.Directory (getCurrentDirectory, makeAbsolute)
 import System.Environment (lookupEnv)
+import System.FilePath ((</>))
 import System.Exit
 import System.IO
 import System.IO.Temp
@@ -48,6 +51,16 @@
   --      system's default.
   hc <- fromMaybe "ghc" <$> lookupEnv "HC"
   srcNums <- getDataFileName "src-nums"
+  -- Only expose the packages of the test suite, from the in-place package
+  -- DB (see the cabal-doctest Build_doctests module).
+  prefix <- getCurrentDirectory >>= makeAbsolute
+  let packageFlags =
+        [ "-package-env=-"
+        , "-hide-all-packages"
+        , "-no-user-package-db"
+        , "-package-db=" ++ prefix </> "dist/package.conf.inplace"
+        ]
+          ++ pkgs
   withSystemTempFile "ShouldError.hs" $ \tempFile tempHandle -> do
     -- Write source with proper Main module structure
     hPutStr tempHandle "module Main where\n"
@@ -57,6 +70,7 @@
     (exitCode, _, stderrOutput) <-
       readProcessWithExitCode
         hc
+        ( packageFlags ++
         [ "-XCPP"
         , "-XDataKinds"
         , "-XTypeOperators"
@@ -73,7 +87,7 @@
         , "-fplugin=GHC.TypeLits.Extra.Solver"
         , "-fplugin=CheckedLiterals"
         , tempFile
-        ]
+        ] )
         ""
     case (exitCode, expected) of
       (ExitSuccess, ExpectSuccess) ->
