Make tyPromotedVar pretty-print as 'Abc not Abc. (#44)

Also make it possible for unit tests to change behavior based on the
version of GHC.
This commit is contained in:
Judah Jacobson 2019-08-30 21:32:01 -07:00 committed by GitHub
parent bed038cd28
commit 18f8e8d2c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 1 deletions

View File

@ -28,7 +28,7 @@ import GHC.SourceGen.Type.Internal
-- | A promoted name, for example from the @DataKinds@ extension.
tyPromotedVar :: RdrNameStr -> HsType'
tyPromotedVar = noExt HsTyVar notPromoted . typeRdrName
tyPromotedVar = noExt HsTyVar promoted . typeRdrName
stringTy :: String -> HsType'
stringTy = noExt HsTyLit . noSourceText HsStrTy . fromString

16
tests/GhcVersion.hs Normal file
View File

@ -0,0 +1,16 @@
-- A module for changing behavior based on the version of GHC.
{-# LANGUAGE CPP #-}
module GhcVersion where
import Data.Version
import Text.ParserCombinators.ReadP
ghcVersion :: Version
ghcVersion = case readP_to_S (parseVersion <* eof) VERSION_ghc of
[(v,"")] -> v
_ -> error $ "Unable to parse GHC version " ++ show VERSION_ghc
ifGhc88 :: a -> a -> a
ifGhc88 x y = if makeVersion [8,8] <= ghcVersion
then x
else y

View File

@ -11,6 +11,7 @@ import Test.Tasty
import Test.Tasty.HUnit
import GHC.SourceGen
import GhcVersion
data TestCase a = String :~ a
@ -98,6 +99,11 @@ typesTest dflags = testGroup "Type"
, "[x]" :~ listPromotedTy [var "x"]
, "[y, z]" :~ listPromotedTy [var "y", var "z"]
]
, test "tyPromotedVar"
-- For some reason, older GHC pretty-printed an extra space.
[ ifGhc88 "'Abc" " 'Abc" :~ tyPromotedVar "Abc"
, ifGhc88 "T 'Abc" "T 'Abc" :~ var "T" @@ tyPromotedVar "Abc"
]
]
where
test = testTypes dflags