Explicit export lists for Main (#9890)
[cabal.git] / cabal-testsuite / PackageTests / InternalLibraries / Executable / setup-static.test.hs
blob1c12fd03a7acf8ae69d789f0e173394e329fa9d6
1 {-# LANGUAGE CPP #-}
3 import Test.Cabal.Prelude
4 import Control.Monad.IO.Class
5 import Control.Monad
6 import Distribution.System (buildPlatform)
7 import Distribution.Package
8 import Distribution.Simple.Configure
9 import Distribution.Simple.BuildPaths
10 import Distribution.Simple.LocalBuildInfo
11 import Distribution.Simple.InstallDirs
12 import Distribution.Simple.Compiler
13 import Distribution.Types.TargetInfo
14 import Distribution.Types.LocalBuildInfo
15 import Distribution.Types.UnqualComponentName
16 #if MIN_VERSION_Cabal(3,11,0)
17 import Distribution.Utils.Path (makeSymbolicPath)
18 #endif
20 import System.Directory
22 -- Internal libraries used by a statically linked executable:
23 -- no libraries should get installed or registered. (Note,
24 -- this does build shared libraries just to make sure they
25 -- don't get installed, so this test doesn't work on Windows.)
26 main = setupAndCabalTest $ do
27 skipIfNoSharedLibraries
28 withPackageDb $ do
29 -- MULTI
30 forM_ [False, True] $ \is_dynamic -> do
31 setup_install $ [ if is_dynamic then "--enable-executable-dynamic"
32 else "--disable-executable-dynamic"
33 , "--enable-shared"]
34 dist_dir <- fmap testDistDir getTestEnv
35 lbi <- liftIO $
36 getPersistBuildConfig
37 #if MIN_VERSION_Cabal(3,11,0)
38 Nothing $ makeSymbolicPath
39 #endif
40 dist_dir
41 let pkg_descr = localPkgDescr lbi
42 compiler_id = compilerId (compiler lbi)
43 cname = CLibName $ LSubLibName $ mkUnqualComponentName "foo-internal"
44 [target] = componentNameTargets' pkg_descr lbi cname
45 uid = componentUnitId (targetCLBI target)
46 InstallDirs{libdir=dir,dynlibdir=dyndir} =
47 absoluteComponentInstallDirs pkg_descr lbi uid NoCopyDest
48 assertBool "interface files should be installed"
49 =<< liftIO (doesFileExist (dir </> "Foo.hi"))
50 assertBool "static library should be installed"
51 =<< liftIO (doesFileExist (dir </> mkLibName uid))
52 if is_dynamic
53 then
54 assertBool "dynamic library MUST be installed"
55 =<< liftIO (doesFileExist (dyndir </> mkSharedLibName
56 buildPlatform compiler_id uid))
57 else
58 assertBool "dynamic library should be installed"
59 =<< liftIO (doesFileExist (dyndir </> mkSharedLibName
60 buildPlatform compiler_id uid))
61 fails $ ghcPkg "describe" ["foo"]
62 -- clean away the dist directory so that we catch accidental
63 -- dependence on the inplace files
64 setup "clean" []
65 runInstalledExe' "foo" [] >>= assertOutputContains "46"