Make Markdown example a code block
[cabal.git] / Cabal-tests / tests / UnitTests / Distribution / Simple / Program / GHC.hs
blobd66b2eb4316298d22208c96ca0c264be4b348830
1 module UnitTests.Distribution.Simple.Program.GHC (tests) where
3 import qualified Data.Map as Map
4 import Data.Algorithm.Diff (PolyDiff (..), getDiff)
5 import Test.Tasty (TestTree, testGroup)
6 import Test.Tasty.HUnit
8 import Distribution.System (Platform(..), Arch(X86_64), OS(Linux))
9 import Distribution.Types.ParStrat
10 import Distribution.Simple.Flag
11 import Distribution.Simple.Compiler (Compiler(..), CompilerId(..), CompilerFlavor(..), AbiTag(NoAbiTag))
12 import Distribution.PackageDescription (emptyPackageDescription)
13 import Distribution.Simple.Program.GHC (normaliseGhcArgs, renderGhcOptions, ghcOptNumJobs)
14 import Distribution.Version (mkVersion)
16 tests :: TestTree
17 tests = testGroup "Distribution.Simple.Program.GHC"
18 [ testGroup "normaliseGhcArgs"
19 [ testCase "options added in GHC-8.8" $ do
20 let flags :: [String]
21 flags = normaliseGhcArgs
22 (Just $ mkVersion [8,8,1])
23 emptyPackageDescription
24 options_8_8_all
26 assertListEquals flags options_8_8_affects
28 , testCase "options added in GHC-8.10" $ do
29 let flags :: [String]
30 flags = normaliseGhcArgs
31 (Just $ mkVersion [8,10,1])
32 emptyPackageDescription
33 options_8_10_all
35 assertListEquals flags options_8_10_affects
37 , testCase "options added in GHC-9.0" $ do
38 let flags :: [String]
39 flags = normaliseGhcArgs
40 (Just $ mkVersion [9,0,1])
41 emptyPackageDescription
42 options_9_0_all
44 assertListEquals flags options_9_0_affects
46 , testGroup "renderGhcOptions"
47 [ testCase "options" $ do
48 let flags :: [String]
49 flags = renderGhcOptions
50 (Compiler
51 { compilerId = CompilerId GHC (mkVersion [9,8,1])
52 , compilerAbiTag = NoAbiTag
53 , compilerCompat = []
54 , compilerLanguages = []
55 , compilerExtensions = []
56 , compilerProperties = Map.singleton "Support parallel --make" "YES"
58 (Platform X86_64 Linux)
59 (mempty { ghcOptNumJobs = Flag (NumJobs (Just 4)) })
60 assertListEquals flags ["-j4", "-clear-package-db"]
64 assertListEquals :: (Eq a, Show a) => [a] -> [a] -> Assertion
65 assertListEquals xs ys
66 | xs == ys = return ()
67 | otherwise = assertFailure $ unlines $
68 "Lists are not equal" :
69 [ case d of
70 First x -> "- " ++ show x
71 Second y -> "+ " ++ show y
72 Both x _ -> " " ++ show x
73 | d <- getDiff xs ys
76 -------------------------------------------------------------------------------
77 -- GHC 8.8
78 -------------------------------------------------------------------------------
80 -- | Options added in GHC-8.8, to generate:
82 -- @
83 -- ghc-8.6.5 --show-options | sort > 8.6.5.txt
84 -- ghc-8.8.1 --show-options | sort > 8.8.1.txt
85 -- diff -u 8.6.5 8.8.1
86 -- @
88 -- - remove -W(no-)error=, -W(no-)warn flags.
89 -- - split into all and flags which may affect artifacts
90 options_8_8_all :: [String]
91 options_8_8_all =
92 [ "-ddump-cfg-weights"
93 , "-dno-suppress-stg-exts"
94 , "-dsuppress-stg-exts"
95 , "-Wmissed-extra-shared-lib"
96 , "-Wmissing-deriving-strategies"
97 , "-Wmissing-space-after-bang"
98 , "-Wno-missed-extra-shared-lib"
99 , "-Wno-missing-deriving-strategies"
100 , "-Wno-missing-space-after-bang"
101 , "-fno-show-docs-of-hole-fits"
102 , "-fshow-docs-of-hole-fits"
103 ] ++ options_8_8_affects
105 options_8_8_affects :: [String]
106 options_8_8_affects =
107 [ "-fblock-layout-cfg"
108 , "-fblock-layout-weightless"
109 , "-fblock-layout-weights"
110 , "-fclear-plugins"
111 , "-fkeep-cafs"
112 , "-fno-block-layout-cfg"
113 , "-fno-block-layout-weightless"
114 , "-fno-keep-cafs"
115 , "-fno-safe-haskell"
116 , "-fno-stg-lift-lams"
117 , "-fno-stg-lift-lams-known"
118 , "-fno-validate-ide-info"
119 , "-fno-write-ide-info"
120 , "-fstg-lift-lams"
121 , "-fstg-lift-lams-known"
122 , "-fstg-lift-lams-non-rec-args"
123 , "-fstg-lift-lams-non-rec-args-any"
124 , "-fstg-lift-lams-rec-args"
125 , "-fstg-lift-lams-rec-args-any"
126 , "-fvalidate-ide-info"
127 , "-fwrite-ide-info"
128 , "-hiedir"
129 , "-hiesuf"
130 , "-keep-hscpp-file"
131 , "-keep-hscpp-files"
134 -------------------------------------------------------------------------------
135 -- GHC 8.10
136 -------------------------------------------------------------------------------
138 options_8_10_all :: [String]
139 options_8_10_all =
140 [ "-ddump-cmm-verbose-by-proc"
141 , "-ddump-stg-final"
142 , "-ddump-stg-unarised"
143 , "-Wderiving-defaults"
144 , "-Winferred-safe-imports"
145 , "-Wmissing-safe-haskell-mode"
146 , "-Wno-deriving-defaults"
147 , "-Wno-inferred-safe-imports"
148 , "-Wno-missing-safe-haskell-mode"
149 , "-Wno-prepositive-qualified-module"
150 , "-Wno-redundant-record-wildcards"
151 , "-Wno-unused-packages"
152 , "-Wno-unused-record-wildcards"
153 , "-Wprepositive-qualified-module"
154 , "-Wredundant-record-wildcards"
155 , "-Wunused-packages"
156 , "-Wunused-record-wildcards"
157 , "-fdefer-diagnostics"
158 , "-fkeep-going"
159 , "-fprint-axiom-incomps"
160 , "-fno-defer-diagnostics"
161 , "-fno-keep-going"
162 , "-fno-print-axiom-incomps"
163 ] ++ options_8_10_affects
165 options_8_10_affects :: [String]
166 options_8_10_affects =
167 [ "-dno-typeable-binds"
168 , "-fbinary-blob-threshold"
169 , "-fmax-pmcheck-models"
170 , "-fplugin-trustworthy"
171 , "-include-cpp-deps"
172 , "-optcxx"
175 -------------------------------------------------------------------------------
176 -- GHC-9.0
177 -------------------------------------------------------------------------------
179 options_9_0_all :: [String]
180 options_9_0_all =
181 [ "-ddump-cmm-opt"
182 , "-ddump-cpranal"
183 , "-ddump-cpr-signatures"
184 , "-ddump-hie"
185 -- NOTE: we filter out -dlinear-core-lint
186 -- we filter, -dcore-lint, -dstg-lint etc.
187 , "-dlinear-core-lint"
188 ] ++ options_9_0_affects
190 options_9_0_affects :: [String]
191 options_9_0_affects =
192 [ "-fcmm-static-pred"