on master help sign in
Get .hs test files working with the perf changes
8491faeEvan Czaplicki
tests/Test/Compiler.hs+20−16
@@ -1,13 +1,17 @@
1{-# OPTIONS_GHC -W #-}
1{-# OPTIONS_GHC -W #-}
2+{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE ScopedTypeVariables #-}
3module Test.Compiler (compilerTests) where
4module Test.Compiler (compilerTests) where
4
5
5import Control.Exception (try, IOException)
6import Control.Exception (try, IOException)
6
7
7−import qualified Data.Text.Lazy as Text
8+import qualified Data.Text.Lazy as LText
8−import qualified Data.Text.Lazy.IO as Text
9+import qualified Data.Text.Lazy.IO as LText
9import qualified Data.Map as Map
10import qualified Data.Map as Map
10import Data.Maybe (isJust)
11import Data.Maybe (isJust)
12+import qualified Data.Text as Text
13+import qualified Data.Text.IO as Text
14+import Data.Text (Text)
11
15
12import System.Directory (createDirectoryIfMissing)
16import System.Directory (createDirectoryIfMissing)
13import System.Environment (lookupEnv)
17import System.Environment (lookupEnv)
@@ -77,7 +81,7 @@ essentialInterfaces :: Module.Interfaces
77essentialInterfaces =
81essentialInterfaces =
78 Map.fromList
82 Map.fromList
79 [
83 [
80− (ModuleName.inCore ["Debug"],
84+ (ModuleName.inCore "Debug",
81 buildCoreInterface
85 buildCoreInterface
82 [
86 [
83 ("crash", Type.Lambda (Type.Var "String") (Type.Var "a"))
87 ("crash", Type.Lambda (Type.Var "String") (Type.Var "a"))
@@ -86,7 +90,7 @@ essentialInterfaces =
86 ]
90 ]
87
91
88
92
89−buildCoreInterface :: [(String, Type.Canonical)] -> Module.Interface
93+buildCoreInterface :: [(Text, Type.Canonical)] -> Module.Interface
90buildCoreInterface members =
94buildCoreInterface members =
91 let
95 let
92 exports = map (Variable.Value . fst) members
96 exports = map (Variable.Value . fst) members
@@ -99,8 +103,8 @@ buildCoreInterface members =
99 Module.Interface Compiler.version Package.core exports imports types adts aliases fixities
103 Module.Interface Compiler.version Package.core exports imports types adts aliases fixities
100
104
101
105
102−compileString :: FilePath -> String -> Either String Compiler.Result
106+compile :: FilePath -> Text -> Either String Compiler.Result
103−compileString filePath source =
107+compile filePath source =
104 let dependentModuleNames =
108 let dependentModuleNames =
105 Map.keys essentialInterfaces
109 Map.keys essentialInterfaces
106 context =
110 context =
@@ -108,7 +112,7 @@ compileString filePath source =
108 (dealiaser, _warnings, result) =
112 (dealiaser, _warnings, result) =
109 Compiler.compile context source essentialInterfaces
113 Compiler.compile context source essentialInterfaces
110 formatErrors errors =
114 formatErrors errors =
111− concatMap (Compiler.errorToString dealiaser filePath source) errors
115+ concatMap (Compiler.errorToString dealiaser filePath (Text.unpack source)) errors
112 in
116 in
113 either (Left . formatErrors) Right result
117 either (Left . formatErrors) Right result
114
118
@@ -134,8 +138,8 @@ testIf
134 -> IO [Test]
138 -> IO [Test]
135testIf handleResult filePaths =
139testIf handleResult filePaths =
136 let doTest filePath =
140 let doTest filePath =
137− do source <- readFile filePath
141+ do source <- Text.readFile filePath
138− let formattedResult = compileString filePath source
142+ let formattedResult = compile filePath source
139 return $ testCase filePath (handleResult formattedResult)
143 return $ testCase filePath (handleResult formattedResult)
140 in
144 in
141 traverse doTest filePaths
145 traverse doTest filePaths
@@ -143,10 +147,10 @@ testIf handleResult filePaths =
143
147
144doMatchesExpectedTest :: String -> FilePath -> IO Test
148doMatchesExpectedTest :: String -> FilePath -> IO Test
145doMatchesExpectedTest expectedJsDir filePath =
149doMatchesExpectedTest expectedJsDir filePath =
146− do source <- readFile filePath
150+ do source <- Text.readFile filePath
147 expectedJs <- readFileOrErrorStr (convertToExpectedJsFilePath expectedJsDir filePath)
151 expectedJs <- readFileOrErrorStr (convertToExpectedJsFilePath expectedJsDir filePath)
148
152
149− let formattedResult = compileString filePath source
153+ let formattedResult = compile filePath source
150 let assertion = matchesExpected expectedJs formattedResult
154 let assertion = matchesExpected expectedJs formattedResult
151
155
152 return $ testCase filePath assertion
156 return $ testCase filePath assertion
@@ -154,8 +158,8 @@ doMatchesExpectedTest expectedJsDir filePath =
154
158
155doWriteNewExpectedTest :: String -> FilePath -> IO Test
159doWriteNewExpectedTest :: String -> FilePath -> IO Test
156doWriteNewExpectedTest expectedJsDir filePath =
160doWriteNewExpectedTest expectedJsDir filePath =
157− do source <- readFile filePath
161+ do source <- Text.readFile filePath
158− let formattedResult = compileString filePath source
162+ let formattedResult = compile filePath source
159 let expectedFilePath = convertToExpectedJsFilePath expectedJsDir filePath
163 let expectedFilePath = convertToExpectedJsFilePath expectedJsDir filePath
160 let assertion =
164 let assertion =
161 case formattedResult of
165 case formattedResult of
@@ -164,8 +168,8 @@ doWriteNewExpectedTest expectedJsDir filePath =
164 -- Force the evaluation of `js` before `writeFile`
168 -- Force the evaluation of `js` before `writeFile`
165 -- so that if an error is raised we do not unintentionally write an empty file.
169 -- so that if an error is raised we do not unintentionally write an empty file.
166 -- NB: `js` can be an empty string in the case of NoExpressions.elm
170 -- NB: `js` can be an empty string in the case of NoExpressions.elm
167− assertBool "" (Text.length js >= 0)
171+ assertBool "" (LText.length js >= 0)
168− Text.writeFile expectedFilePath js
172+ LText.writeFile expectedFilePath js
169 assertFailure ("Wrote new expected js: " ++ expectedFilePath)
173 assertFailure ("Wrote new expected js: " ++ expectedFilePath)
170
174
171 _ ->
175 _ ->
@@ -212,7 +216,7 @@ matchesExpected :: String -> Either String Compiler.Result -> Assertion
212matchesExpected expectedJs result =
216matchesExpected expectedJs result =
213 case result of
217 case result of
214 Right (Compiler.Result _ _ js) ->
218 Right (Compiler.Result _ _ js) ->
215− assertEqual matchFailureMessage (Text.pack expectedJs) js
219+ assertEqual matchFailureMessage (LText.pack expectedJs) js
216
220
217 Left errorMessages ->
221 Left errorMessages ->
218 assertFailure $ "Compile failed:\n" ++ errorMessages
222 assertFailure $ "Compile failed:\n" ++ errorMessages