Add a note describing the protocol for adding a language extension
[ghc.git] / testsuite / tests / driver / T4437.hs
1 -- | A test for ensuring that GHC's supporting language extensions remains in
2 -- sync with Cabal's own extension list.
3 --
4 -- If you have ended up here due to a test failure, please see
5 -- Note [Adding a language extension] in compiler/main/DynFlags.hs.
6
7 module Main (main) where
8
9 import Control.Monad
10 import Data.List
11 import DynFlags
12 import Language.Haskell.Extension
13
14 main :: IO ()
15 main = do
16 let ghcExtensions = map flagSpecName xFlags
17 cabalExtensions = map show [ toEnum 0 :: KnownExtension .. ]
18 ghcOnlyExtensions = ghcExtensions \\ cabalExtensions
19 cabalOnlyExtensions = cabalExtensions \\ ghcExtensions
20 check "GHC-only flags" expectedGhcOnlyExtensions ghcOnlyExtensions
21 check "Cabal-only flags" expectedCabalOnlyExtensions cabalOnlyExtensions
22
23 check :: String -> [String] -> [String] -> IO ()
24 check title expected got
25 = do let unexpected = got \\ expected
26 missing = expected \\ got
27 showProblems problemType problems
28 = unless (null problems) $
29 do putStrLn (title ++ ": " ++ problemType)
30 putStrLn "-----"
31 mapM_ putStrLn problems
32 putStrLn "-----"
33 putStrLn ""
34 showProblems "Unexpected flags" unexpected
35 showProblems "Missing flags" missing
36
37 -- See Note [Adding a language extension] in compiler/main/DynFlags.hs.
38 expectedGhcOnlyExtensions :: [String]
39 expectedGhcOnlyExtensions = ["RelaxedLayout",
40 "AlternativeLayoutRule",
41 "AlternativeLayoutRuleTransitional"]
42
43 expectedCabalOnlyExtensions :: [String]
44 expectedCabalOnlyExtensions = ["Generics",
45 "ExtensibleRecords",
46 "RestrictedTypeSynonyms",
47 "HereDocuments",
48 "NewQualifiedOperators",
49 "XmlSyntax",
50 "RegularPatterns",
51 "SafeImports",
52 "Safe",
53 "Unsafe",
54 "Trustworthy"]