| 1 |
Index: b/test/TH/Include.hs |
| 2 |
=================================================================== |
| 3 |
--- /dev/null |
| 4 |
+++ b/test/TH/Include.hs |
| 5 |
@@ -0,0 +1,46 @@ |
| 6 |
+-- This template expects CPP definitions for: |
| 7 |
+-- PLATFORM_NAME = Posix | Windows |
| 8 |
+ |
| 9 |
+{-# LANGUAGE MultiParamTypeClasses #-} |
| 10 |
+{-# LANGUAGE QuasiQuotes #-} |
| 11 |
+{-# LANGUAGE TemplateHaskell #-} |
| 12 |
+{-# OPTIONS_GHC -Wno-unused-top-binds #-} |
| 13 |
+ |
| 14 |
+-- | Test functions to check the template haskell bits. |
| 15 |
+module TH.PLATFORM_NAME where |
| 16 |
+ |
| 17 |
+import qualified Language.Haskell.TH.Syntax as TH |
| 18 |
+ |
| 19 |
+import Path.Internal.PLATFORM_NAME |
| 20 |
+import Path.PLATFORM_NAME |
| 21 |
+ |
| 22 |
+-- | This is a helper type class that checks that splices produce a 'Path' with |
| 23 |
+-- all type variables instantiated to a type. |
| 24 |
+-- This ensures that bugs like https://github.com/commercialhaskell/path/issues/159 |
| 25 |
+-- cannot happen. |
| 26 |
+class CheckInstantiated a b where |
| 27 |
+ checkInstantiated :: Path a b -> FilePath |
| 28 |
+ checkInstantiated = toFilePath |
| 29 |
+ |
| 30 |
+instance CheckInstantiated Abs Dir |
| 31 |
+instance CheckInstantiated Abs File |
| 32 |
+instance CheckInstantiated Rel Dir |
| 33 |
+instance CheckInstantiated Rel File |
| 34 |
+ |
| 35 |
+qqRelDir :: FilePath |
| 36 |
+qqRelDir = checkInstantiated [reldir|name/|] |
| 37 |
+ |
| 38 |
+qqRelFile :: FilePath |
| 39 |
+qqRelFile = checkInstantiated [relfile|name|] |
| 40 |
+ |
| 41 |
+thRelDir :: FilePath |
| 42 |
+thRelDir = checkInstantiated $(mkRelDir "name/") |
| 43 |
+ |
| 44 |
+thRelFile :: FilePath |
| 45 |
+thRelFile = checkInstantiated $(mkRelFile "name") |
| 46 |
+ |
| 47 |
+liftRelDir :: FilePath |
| 48 |
+liftRelDir = checkInstantiated $(TH.lift (Path "name/" :: Path Rel Dir)) |
| 49 |
+ |
| 50 |
+liftRelFile :: FilePath |
| 51 |
+liftRelFile = checkInstantiated $(TH.lift (Path "name" :: Path Rel File)) |
| 52 |
Index: b/test-ospath/TH/Include.hs |
| 53 |
=================================================================== |
| 54 |
--- /dev/null |
| 55 |
+++ b/test-ospath/TH/Include.hs |
| 56 |
@@ -0,0 +1,50 @@ |
| 57 |
+-- This template expects CPP definitions for: |
| 58 |
+-- PLATFORM_NAME = Posix | Windows |
| 59 |
+-- PLATFORM_PATH = PosixPath | WindowsPath |
| 60 |
+ |
| 61 |
+{-# LANGUAGE MultiParamTypeClasses #-} |
| 62 |
+{-# LANGUAGE QuasiQuotes #-} |
| 63 |
+{-# LANGUAGE TemplateHaskell #-} |
| 64 |
+ |
| 65 |
+{-# OPTIONS_GHC -Wno-unused-top-binds #-} |
| 66 |
+ |
| 67 |
+-- | Test functions to check the template haskell bits. |
| 68 |
+module TH.PLATFORM_NAME where |
| 69 |
+ |
| 70 |
+import qualified Language.Haskell.TH.Syntax as TH |
| 71 |
+import System.OsPath.PLATFORM_NAME (PLATFORM_PATH) |
| 72 |
+ |
| 73 |
+import OsPath.Internal.PLATFORM_NAME |
| 74 |
+import OsPath.PLATFORM_NAME |
| 75 |
+import qualified System.OsString.Compat.PLATFORM_NAME as OsString |
| 76 |
+ |
| 77 |
+-- | This is a helper type class that checks that splices produce a 'Path' with |
| 78 |
+-- all type variables instantiated to a type. |
| 79 |
+-- This ensures that bugs like https://github.com/commercialhaskell/path/issues/159 |
| 80 |
+-- cannot happen. |
| 81 |
+class CheckInstantiated a b where |
| 82 |
+ checkInstantiated :: Path a b -> PLATFORM_PATH |
| 83 |
+ checkInstantiated = toOsPath |
| 84 |
+ |
| 85 |
+instance CheckInstantiated Abs Dir |
| 86 |
+instance CheckInstantiated Abs File |
| 87 |
+instance CheckInstantiated Rel Dir |
| 88 |
+instance CheckInstantiated Rel File |
| 89 |
+ |
| 90 |
+qqRelDir :: PLATFORM_PATH |
| 91 |
+qqRelDir = checkInstantiated [reldir|name/|] |
| 92 |
+ |
| 93 |
+qqRelFile :: PLATFORM_PATH |
| 94 |
+qqRelFile = checkInstantiated [relfile|name|] |
| 95 |
+ |
| 96 |
+thRelDir :: PLATFORM_PATH |
| 97 |
+thRelDir = checkInstantiated $(mkRelDir [OsString.pstr|name/|]) |
| 98 |
+ |
| 99 |
+thRelFile :: PLATFORM_PATH |
| 100 |
+thRelFile = checkInstantiated $(mkRelFile [OsString.pstr|name|]) |
| 101 |
+ |
| 102 |
+liftRelDir :: PLATFORM_PATH |
| 103 |
+liftRelDir = checkInstantiated $(TH.lift (Path [OsString.pstr|name/|] :: Path Rel Dir)) |
| 104 |
+ |
| 105 |
+liftRelFile :: PLATFORM_PATH |
| 106 |
+liftRelFile = checkInstantiated $(TH.lift (Path [OsString.pstr|name|] :: Path Rel File)) |