summaryrefslogtreecommitdiff
path: root/tests/examples/ghc88/T4437.hs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/examples/ghc88/T4437.hs')
-rwxr-xr-xtests/examples/ghc88/T4437.hs57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/examples/ghc88/T4437.hs b/tests/examples/ghc88/T4437.hs
new file mode 100755
index 0000000..da2de38
--- /dev/null
+++ b/tests/examples/ghc88/T4437.hs
@@ -0,0 +1,57 @@
+-- | 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.
+
+module Main (main) where
+
+import Control.Monad
+import Data.List
+import DynFlags
+import Language.Haskell.Extension
+
+main :: IO ()
+main = do
+ let ghcExtensions = map flagSpecName xFlags
+ 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
+
+-- See Note [Adding a language extension] in compiler/main/DynFlags.hs.
+expectedGhcOnlyExtensions :: [String]
+expectedGhcOnlyExtensions = ["RelaxedLayout",
+ "AlternativeLayoutRule",
+ "AlternativeLayoutRuleTransitional",
+ "EmptyDataDeriving",
+ "GeneralisedNewtypeDeriving"]
+
+expectedCabalOnlyExtensions :: [String]
+expectedCabalOnlyExtensions = ["Generics",
+ "ExtensibleRecords",
+ "RestrictedTypeSynonyms",
+ "HereDocuments",
+ "NewQualifiedOperators",
+ "XmlSyntax",
+ "RegularPatterns",
+ "SafeImports",
+ "Safe",
+ "Unsafe",
+ "Trustworthy"]
+