Improve online docs for `includes:` field
[cabal.git] / cabal-testsuite / PackageTests / ProfShared / setup.test.hs
blob754ff7a290db52b8b1af25fb3c0bccfe889faa97
1 import Test.Cabal.Prelude
2 import Data.List
3 import Data.Bifunctor
5 data BuildWay = StaticWay | DynWay | ProfWay | ProfDynWay
6 deriving (Eq, Ord, Show, Read, Enum)
8 -- Test building with profiling shared support
9 main = do
10 setupTest $ recordMode DoNotRecord $ do
11 has_prof_shared <- hasProfiledSharedLibraries
12 has_shared <- hasSharedLibraries
13 -- Tests are not robust against missing dynamic libraries yet. Would
14 -- be better to fix this.
15 skipUnless "Missing shared libraries" has_shared
17 let analyse_result expected r = do
19 let ls = lines (resultOutput r)
21 library_prefix = "Wanted build ways(True): "
22 executable_prefix = "Wanted build ways(False): "
24 get_ways prefix = map (drop (length prefix)) (filter (prefix `isPrefixOf`) ls)
25 library_ways = read_ways (get_ways library_prefix)
26 executable_ways = read_ways (get_ways executable_prefix)
28 read_ways raw_ways =
29 case raw_ways of
30 -- There should only be one
31 [x] -> (read :: String -> [BuildWay]) x
32 -- Unless there are none, when we don't built the executable for example
33 [] -> []
34 xs -> error "Unexpected number of log lines"
36 way = (library_ways, executable_ways)
38 unless (bimap (nub . sort) (nub . sort) expected == bimap (nub . sort) (nub . sort) way) $
39 assertFailure $ "Expected:" ++ show expected ++ "\n" ++ "Got:" ++ show way
41 requireSuccess r
42 setupTest $ recordMode DoNotRecord $ do
44 has_prof_shared <- hasProfiledSharedLibraries
45 has_shared <- hasSharedLibraries
47 let v = [ StaticWay ]
48 dyn = [ DynWay | has_shared ]
49 p_dyn = if has_prof_shared then [ProfDynWay] else p
50 p = [ ProfWay ]
51 none = []
53 let run_test args expected = do
54 setup "configure" args
55 res <- setup' "build" []
56 analyse_result expected res
57 setup "clean" []
60 run_test []
61 (v <> dyn, v)
64 run_test ["--disable-library-vanilla", "--enable-executable-dynamic"]
65 (dyn, dyn)
67 run_test ["--enable-profiling-shared"]
68 (v <> dyn <> p_dyn, v)
70 run_test ["--enable-profiling-shared", "--enable-executable-dynamic"]
71 (v <> dyn <> p_dyn, dyn)
73 run_test ["--enable-executable-dynamic", "--disable-library-vanilla"]
74 (dyn, dyn)
76 run_test ["--enable-profiling"]
77 (v <> dyn <> p, p)
79 run_test ["--enable-executable-profiling"]
80 (v <> dyn <> p, p)
82 run_test ["--enable-executable-profiling", "--enable-executable-dynamic"]
83 (v <> dyn <> p_dyn, p_dyn)
85 run_test ["--enable-profiling", "--enable-executable-dynamic"]
86 (v <> dyn <> p_dyn, p_dyn)
88 --v dyn p (p exe)
89 run_test ["--enable-library-profiling", "--enable-executable-profiling"]
90 (v <> dyn <> p, p)
92 run_test ["prof-shared", "--enable-profiling-shared", "--disable-library-vanilla", "--disable-shared"]
93 (p_dyn, none)
95 -- p p_dyn
96 run_test ["prof-shared", "--enable-profiling-shared", "--enable-library-profiling", "--disable-library-vanilla", "--disable-shared"]
97 (p <> p_dyn, [])
99 -- v p p_dyn
100 run_test ["prof-shared","--enable-profiling-shared", "--enable-library-profiling", "--enable-library-vanilla", "--disable-shared"]
101 (v <> p <> p_dyn, none)
103 -- v dyn p p_dyn
104 run_test ["prof-shared", "--enable-profiling-shared", "--enable-library-profiling", "--enable-library-vanilla", "--enable-shared"]
105 (v <> dyn <> p <> p_dyn, none)
107 let run_cabal_test args expected = cabalTest $ recordMode DoNotRecord $ do
108 has_prof_shared <- hasProfiledSharedLibraries
109 has_shared <- hasSharedLibraries
110 -- See GHC commit e400b9babdcf11669f963aeec20078fe7ccfca0d
111 -- Only installing profiled library is broken on very old ghc-pkg versions
112 broken_ghc_pkg <- isGhcVersion "<= 8.6.5"
114 let cvt_l StaticWay = [ StaticWay ]
115 cvt_l DynWay = [ DynWay | has_shared ]
116 cvt_l ProfDynWay = [ProfDynWay | has_prof_shared ]
117 cvt_l ProfWay = [ ProfWay ]
119 let cvt_e StaticWay = StaticWay
120 cvt_e DynWay = if has_shared then DynWay else error "DynWay"
121 cvt_e ProfDynWay = if has_prof_shared then ProfDynWay else ProfWay
122 cvt_e ProfWay = ProfWay
124 unless (broken_ghc_pkg && (fst expected == [ProfWay])) $ do
125 res <- cabal' "v2-build" args
126 void $ analyse_result (bimap (concatMap cvt_l) (map cvt_e) expected) res
128 run_cabal_test ["--disable-shared"] ([StaticWay], [StaticWay])
129 run_cabal_test ["--disable-shared", "--disable-executable-dynamic"] ([StaticWay], [StaticWay])
130 run_cabal_test ["--enable-shared"] ([DynWay, StaticWay], [StaticWay])
131 run_cabal_test ["--enable-executable-dynamic"] ([DynWay, StaticWay], [DynWay])
132 run_cabal_test ["--enable-shared", "--disable-library-vanilla", "--enable-executable-dynamic"] ([DynWay], [DynWay])
134 run_cabal_test ["--disable-shared", "--disable-library-vanilla", "--enable-profiling"] ([ProfWay], [ProfWay])
136 run_cabal_test ["--disable-shared", "--enable-profiling"] ([ProfWay, StaticWay], [ProfWay])
138 run_cabal_test ["--disable-shared", "--enable-profiling-shared", "--enable-profiling"] ([ProfDynWay, ProfWay, StaticWay], [ProfWay])
140 run_cabal_test ["--disable-shared", "--enable-profiling", "--enable-profiling-shared", "--enable-executable-dynamic"] ([ProfWay, ProfDynWay, StaticWay], [ProfDynWay])
142 run_cabal_test ["--enable-profiling", "--enable-executable-dynamic"] ([ProfDynWay, ProfWay, DynWay, StaticWay], [ProfDynWay])
144 run_cabal_test ["prof-shared", "--disable-library-profiling", "--enable-profiling", "--enable-executable-dynamic"] ([ProfDynWay, DynWay, StaticWay], [])