Skip to content

Commit 233ba19

Browse files
committed
Expose package library when running tests
1 parent 8a0cf68 commit 233ba19

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ Bug fixes:
5353
* Set the `HASKELL_DIST_DIR` environment to a proper package dist
5454
directory so `doctest` is able to load modules autogenerated by Cabal.
5555

56+
* Expose package library when running tests.
57+
5658
## v2.1.1.1
5759

5860
Hackage-only release that removes `stack.yaml` from the sdist. This is because

src/Stack/Build/Execute.hs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1927,6 +1927,18 @@ singleTest topts testsToRun ac ee task installedMap = do
19271927
tixPath <- liftM (pkgDir </>) $ parseRelFile $ exeName ++ ".tix"
19281928
exePath <- liftM (buildDir </>) $ parseRelFile $ "build/" ++ testName' ++ "/" ++ exeName
19291929
exists <- doesFileExist exePath
1930+
-- in Stack.Package.packageFromPackageDescription we filter out
1931+
-- package itself of any dependencies so any tests requiring loading
1932+
-- of their own package library will fail
1933+
-- so to prevent this we return it back here but unfortunately unconditionally
1934+
installed <- case Map.lookup pname installedMap of
1935+
Just (_, installed) -> pure $ Just installed
1936+
Nothing -> do
1937+
idMap <- liftIO $ readTVarIO (eeGhcPkgIds ee)
1938+
pure $ Map.lookup (taskProvides task) idMap
1939+
let pkgGhcIdList = case installed of
1940+
Just (Library _ ghcPkgId _) -> [ghcPkgId]
1941+
_ -> []
19301942
-- doctest relies on template-haskell in QuickCheck-based tests
19311943
thGhcId <- case find ((== "template-haskell") . pkgName . dpPackageIdent. snd)
19321944
(Map.toList $ eeGlobalDumpPkgs ee) of
@@ -1949,7 +1961,7 @@ singleTest topts testsToRun ac ee task installedMap = do
19491961
"package-db " <> fromString snapDBPath <> "\n" <>
19501962
"package-db " <> fromString localDBPath <> "\n" <>
19511963
foldMap (\ghcId -> "package-id " <> RIO.display (unGhcPkgId ghcId) <> "\n")
1952-
(thGhcId:M.elems allDepsMap)
1964+
(pkgGhcIdList ++ thGhcId:M.elems allDepsMap)
19531965
writeFileUtf8Builder fp ghcEnv
19541966
menv <- liftIO $ setEnv fp =<< configProcessContextSettings config EnvSettings
19551967
{ esIncludeLocals = taskLocation task == Local

0 commit comments

Comments
 (0)