@@ -27,16 +27,16 @@ writeExpectedJsEnvVarName =
28compilerTests :: Test
28compilerTests :: Test
29compilerTests =
29compilerTests =
30− buildTest $ do
30+ buildTest $
31− goods <- testIf isSuccess =<< getElms "good"
31+ do goods <- testIf isSuccess =<< getElms "good"
32− bads <- testIf isFailure =<< getElms "bad"
32+ bads <- testIf isFailure =<< getElms "bad"
33− expectedJsTests <- testMatchesExpected "good" "good-expected-js"
33+ expectedJsTests <- testMatchesExpected "good" "good-expected-js"
35− testGroup "Compile Tests"
35+ testGroup "Compile Tests"
36− [ testGroup "Good Tests" goods
36+ [ testGroup "Good Tests" goods
37− , testGroup "Bad Tests" bads
37+ , testGroup "Bad Tests" bads
38− , testGroup "Expected JS Tests" expectedJsTests
38+ , testGroup "Expected JS Tests" expectedJsTests
42-- GATHER ELM FILES
42-- GATHER ELM FILES
@@ -75,22 +75,22 @@ testIf
75testIf handleResult filePaths =
75testIf handleResult filePaths =
76 traverse setupTest filePaths
76 traverse setupTest filePaths
78− setupTest filePath = do
78+ setupTest filePath =
79− source <- readFile filePath
79+ do source <- readFile filePath
80− let formattedResult = compileString filePath source
80+ let formattedResult = compileString filePath source
82− return $ testCase filePath (handleResult formattedResult)
82+ return $ testCase filePath (handleResult formattedResult)
85testMatchesExpected :: String -> String -> IO [Test]
85testMatchesExpected :: String -> String -> IO [Test]
86−testMatchesExpected elmDir expectedJsDir = do
86+testMatchesExpected elmDir expectedJsDir =
87− elmFiles <- getElms elmDir
87+ do elmFiles <- getElms elmDir
88− envVar <- lookupEnv writeExpectedJsEnvVarName
88+ envVar <- lookupEnv writeExpectedJsEnvVarName
89− if isJust envVar
89+ if isJust envVar
91− traverse writeNewExpected elmFiles
91+ traverse writeNewExpected elmFiles
93− traverse doTest elmFiles
93+ traverse doTest elmFiles
95 getExpectedFilePath filePath =
95 getExpectedFilePath filePath =
@@ -98,38 +98,38 @@ testMatchesExpected elmDir expectedJsDir = do
98 </> joinPath (drop 3 (splitDirectories filePath))
98 </> joinPath (drop 3 (splitDirectories filePath))
101− readFileOrErrorStr filePath = do
101+ readFileOrErrorStr filePath =
102− strOrExc <- try $ readFile filePath
102+ do strOrExc <- try $ readFile filePath
103− case strOrExc of
103+ case strOrExc of
104− Right s ->
104+ Right s ->
105− return s
105+ return s
107− Left (e :: IOException) ->
107+ Left (e :: IOException) ->
108− return (show e)
108+ return (show e)
110− doTest filePath = do
110+ doTest filePath =
111− source <- readFile filePath
111+ do source <- readFile filePath
112− expectedJs <- readFileOrErrorStr (getExpectedFilePath filePath)
112+ expectedJs <- readFileOrErrorStr (getExpectedFilePath filePath)
114− let formattedResult = compileString filePath source
114+ let formattedResult = compileString filePath source
115− assertion = matchesExpected expectedJs formattedResult
115+ let assertion = matchesExpected expectedJs formattedResult
117− return $ testCase filePath assertion
117+ return $ testCase filePath assertion
119− writeNewExpected filePath = do
119+ writeNewExpected filePath =
120− source <- readFile filePath
120+ do source <- readFile filePath
121− let formattedResult = compileString filePath source
121+ let formattedResult = compileString filePath source
122− expectedFilePath = getExpectedFilePath filePath
122+ let expectedFilePath = getExpectedFilePath filePath
123− assertion =
123+ let assertion =
124− case formattedResult of
124+ case formattedResult of
125− Right (Compiler.Result _ _ js) -> do
125+ Right (Compiler.Result _ _ js) ->
126− createDirectoryIfMissing True (dropFileName expectedFilePath)
126+ do createDirectoryIfMissing True (dropFileName expectedFilePath)
127− writeFile expectedFilePath js
127+ writeFile expectedFilePath js
128− assertFailure ("Wrote new expected js: " ++ expectedFilePath)
128+ assertFailure ("Wrote new expected js: " ++ expectedFilePath)
131− assertFailure "Compile failed. Could not write new expected js."
131+ assertFailure "Compile failed. Could not write new expected js."
132− return $ testCase filePath assertion
132+ return $ testCase filePath assertion
135-- CHECK RESULTS
135-- CHECK RESULTS