T4437.hs 2.26 KB
Newer Older
1
2
3
4
5
-- | A test for ensuring that GHC's supporting language extensions remains in
-- sync with Cabal's own extension list.
--
-- If you have ended up here due to a test failure, please see
-- Note [Adding a language extension] in compiler/main/DynFlags.hs.
6
7
8

module Main (main) where

9
import Control.Monad
10
11
12
13
14
import Data.List
import DynFlags
import Language.Haskell.Extension

main :: IO ()
15
main = do
16
    let ghcExtensions = map flagSpecName xFlags
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
        cabalExtensions = map show [ toEnum 0 :: KnownExtension .. ]
        ghcOnlyExtensions = ghcExtensions \\ cabalExtensions
        cabalOnlyExtensions = cabalExtensions \\ ghcExtensions
    check "GHC-only flags" expectedGhcOnlyExtensions ghcOnlyExtensions
    check "Cabal-only flags" expectedCabalOnlyExtensions cabalOnlyExtensions

check :: String -> [String] -> [String] -> IO ()
check title expected got
    = do let unexpected = got \\ expected
             missing = expected \\ got
             showProblems problemType problems
                 = unless (null problems) $
                       do putStrLn (title ++ ": " ++ problemType)
                          putStrLn "-----"
                          mapM_ putStrLn problems
                          putStrLn "-----"
                          putStrLn ""
         showProblems "Unexpected flags" unexpected
         showProblems "Missing flags" missing

37
-- See Note [Adding a language extension] in compiler/main/DynFlags.hs.
38
expectedGhcOnlyExtensions :: [String]
39
expectedGhcOnlyExtensions = ["RelaxedLayout",
40
                             "AlternativeLayoutRule",
41
                             "AlternativeLayoutRuleTransitional",
42
                             "EmptyDataDeriving",
43
                             "GeneralisedNewtypeDeriving"]
44
45
46
47
48
49
50
51
52
53
54

expectedCabalOnlyExtensions :: [String]
expectedCabalOnlyExtensions = ["Generics",
                               "ExtensibleRecords",
                               "RestrictedTypeSynonyms",
                               "HereDocuments",
                               "NewQualifiedOperators",
                               "XmlSyntax",
                               "RegularPatterns",
                               "SafeImports",
                               "Safe",
55
                               "Unsafe",
56
                               "Trustworthy"]