Add a check of the current behaviour importing duplicates
[cabal.git] / cabal-testsuite / PackageTests / ProfShared / setup.test.hs
blob54147e34575dab1d891e6096a9d86e607f6b6fb5
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 -- Tests are not robust against missing dynamic libraries yet. Would
12 -- be better to fix this.
13 skipIfNoSharedLibraries
15 let analyse_result expected r = do
17 let ls = lines (resultOutput r)
19 library_prefix = "Wanted module build ways(library): "
20 executable_prefix = "Wanted module build ways(executable 'Prof'): "
22 get_ways prefix = map (drop (length prefix)) (filter (prefix `isPrefixOf`) ls)
23 library_ways = read_ways (get_ways library_prefix)
24 executable_ways = read_ways (get_ways executable_prefix)
26 read_ways raw_ways =
27 case raw_ways of
28 -- There should only be one
29 [x] -> (read :: String -> [BuildWay]) x
30 -- Unless there are none, when we don't built the executable for example
31 [] -> []
32 xs -> error "Unexpected number of log lines"
34 way = (library_ways, executable_ways)
36 unless (bimap (nub . sort) (nub . sort) expected == bimap (nub . sort) (nub . sort) way) $
37 assertFailure $ "Expected:" ++ show expected ++ "\n" ++ "Got:" ++ show way
39 requireSuccess r
40 setupTest $ recordMode DoNotRecord $ do
42 has_prof_shared <- hasProfiledSharedLibraries
43 has_shared <- hasSharedLibraries
45 let v = [ StaticWay ]
46 dyn = [ DynWay | has_shared ]
47 p_dyn = if has_prof_shared then [ProfDynWay] else p
48 p = [ ProfWay ]
49 none = []
51 let run_test args expected = do
52 setup "configure" args
53 res <- setup' "build" []
54 analyse_result expected res
55 setup "clean" []
58 run_test []
59 (v <> dyn, v)
62 run_test ["--disable-library-vanilla", "--enable-executable-dynamic"]
63 (dyn, dyn)
65 run_test ["--enable-profiling-shared"]
66 (v <> dyn <> p_dyn, v)
68 run_test ["--enable-profiling-shared", "--enable-executable-dynamic"]
69 (v <> dyn <> p_dyn, dyn)
71 run_test ["--enable-executable-dynamic", "--disable-library-vanilla"]
72 (dyn, dyn)
74 run_test ["--enable-profiling"]
75 (v <> dyn <> p, p)
77 run_test ["--enable-executable-profiling"]
78 (v <> dyn <> p, p)
80 run_test ["--enable-executable-profiling", "--enable-executable-dynamic"]
81 (v <> dyn <> p_dyn, p_dyn)
83 run_test ["--enable-profiling", "--enable-executable-dynamic"]
84 (v <> dyn <> p_dyn, p_dyn)
86 --v dyn p (p exe)
87 run_test ["--enable-library-profiling", "--enable-executable-profiling"]
88 (v <> dyn <> p, p)
90 run_test ["prof-shared", "--enable-profiling-shared", "--disable-library-vanilla", "--disable-shared"]
91 (p_dyn, none)
93 -- p p_dyn
94 run_test ["prof-shared", "--enable-profiling-shared", "--enable-library-profiling", "--disable-library-vanilla", "--disable-shared"]
95 (p <> p_dyn, [])
97 -- v p p_dyn
98 run_test ["prof-shared","--enable-profiling-shared", "--enable-library-profiling", "--enable-library-vanilla", "--disable-shared"]
99 (v <> p <> p_dyn, none)
101 -- v dyn p p_dyn
102 run_test ["prof-shared", "--enable-profiling-shared", "--enable-library-profiling", "--enable-library-vanilla", "--enable-shared"]
103 (v <> dyn <> p <> p_dyn, none)
105 let run_cabal_test args expected = cabalTest $ recordMode DoNotRecord $ do
106 has_prof_shared <- hasProfiledSharedLibraries
107 has_shared <- hasSharedLibraries
108 -- See GHC commit e400b9babdcf11669f963aeec20078fe7ccfca0d
109 -- Only installing profiled library is broken on very old ghc-pkg versions
110 broken_ghc_pkg <- isGhcVersion "<= 8.6.5"
112 let cvt_l StaticWay = [ StaticWay ]
113 cvt_l DynWay = [ DynWay | has_shared ]
114 cvt_l ProfDynWay = [ProfDynWay | has_prof_shared ]
115 cvt_l ProfWay = [ ProfWay ]
117 let cvt_e StaticWay = StaticWay
118 cvt_e DynWay = if has_shared then DynWay else error "DynWay"
119 cvt_e ProfDynWay = if has_prof_shared then ProfDynWay else ProfWay
120 cvt_e ProfWay = ProfWay
122 unless (broken_ghc_pkg && (fst expected == [ProfWay])) $ do
123 res <- cabal' "v2-build" args
124 void $ analyse_result (bimap (concatMap cvt_l) (map cvt_e) expected) res
126 run_cabal_test ["--disable-shared"] ([StaticWay], [StaticWay])
127 run_cabal_test ["--disable-shared", "--disable-executable-dynamic"] ([StaticWay], [StaticWay])
128 run_cabal_test ["--enable-shared"] ([DynWay, StaticWay], [StaticWay])
129 run_cabal_test ["--enable-executable-dynamic"] ([DynWay, StaticWay], [DynWay])
130 run_cabal_test ["--enable-shared", "--disable-library-vanilla", "--enable-executable-dynamic"] ([DynWay], [DynWay])
132 run_cabal_test ["--disable-shared", "--disable-library-vanilla", "--enable-profiling"] ([ProfWay], [ProfWay])
134 run_cabal_test ["--disable-shared", "--enable-profiling"] ([ProfWay, StaticWay], [ProfWay])
136 run_cabal_test ["--disable-shared", "--enable-profiling-shared", "--enable-profiling"] ([ProfDynWay, ProfWay, StaticWay], [ProfWay])
138 run_cabal_test ["--disable-shared", "--enable-profiling", "--enable-profiling-shared", "--enable-executable-dynamic"] ([ProfWay, ProfDynWay, StaticWay], [ProfDynWay])
140 run_cabal_test ["--enable-profiling", "--enable-executable-dynamic"] ([ProfDynWay, ProfWay, DynWay, StaticWay], [ProfDynWay])
142 run_cabal_test ["prof-shared", "--disable-library-profiling", "--enable-profiling", "--enable-executable-dynamic"] ([ProfDynWay, DynWay, StaticWay], [])