Merge pull request #10709 from Kleidukos/cabal-3.14.1.1-release-notes
[cabal.git] / cabal-testsuite / PackageTests / TestSuiteTests / ExeV10 / cabal-with-hpc.multitest.hs
blob172b48d8c80e6a8343e03f911adb97db21426972
1 import qualified Control.Exception as E (IOException, catch)
2 import Control.Monad (unless)
3 import Control.Monad.IO.Class (liftIO)
4 import Control.Monad.Trans.Reader (ask)
5 import Data.Maybe (catMaybes)
7 import qualified Distribution.Verbosity as Verbosity
9 import Test.Cabal.Prelude
11 main = do
12 skipIfCIAndOSX 4902
13 cabalTest $ do
14 hasShared <- hasSharedLibraries
15 hasProfiled <- hasProfiledLibraries
16 hpcOk <- correctHpcVersion
18 forM_ (choose4 [True, False]) $ \(libProf, exeProf, exeDyn, shared) ->
20 let
21 opts = catMaybes
22 [ enable libProf "library-profiling"
23 , enable exeProf "profiling"
24 , enable exeDyn "executable-dynamic"
25 , enable shared "shared"
27 where
28 enable cond flag
29 | cond = Just $ "--enable-" ++ flag
30 | otherwise = Nothing
31 args = "test-Short" : "--enable-coverage" : opts
32 recordMode DoNotRecord $ do
33 let
34 skip =
35 not hpcOk
36 || (not hasShared && (exeDyn || shared))
37 || (not hasProfiled && (libProf || exeProf))
38 unless skip $ cabal "v2-test" args
39 where
40 choose4 :: [a] -> [(a, a, a, a)]
41 choose4 xs = liftM4 (,,,) xs xs xs xs
43 -- | Checks for a suitable HPC version for testing.
44 correctHpcVersion :: TestM Bool
45 correctHpcVersion = do
46 let verbosity = Verbosity.normal
47 verRange = orLaterVersion (mkVersion [0,7])
48 progDB <- testProgramDb `fmap` ask
49 liftIO $ (requireProgramVersion verbosity hpcProgram verRange progDB
50 >> return True) `catchIO` (\_ -> return False)
51 where
52 -- Distribution.Compat.Exception is hidden.
53 catchIO :: IO a -> (E.IOException -> IO a) -> IO a
54 catchIO = E.catch