on master help sign in
Whitespace (do on newline)
c6d490eLaszlo Pandy
tests/Test/Compiler.hs+54−54
@@ -27,16 +27,16 @@ writeExpectedJsEnvVarName =
27
27
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"
34− return $
34+ return $
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
39− ]
39+ ]
40
40
41
41
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
77 where
77 where
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
81
81
82− return $ testCase filePath (handleResult formattedResult)
82+ return $ testCase filePath (handleResult formattedResult)
83
83
84
84
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
90− then
90+ then
91− traverse writeNewExpected elmFiles
91+ traverse writeNewExpected elmFiles
92− else
92+ else
93− traverse doTest elmFiles
93+ traverse doTest elmFiles
94 where
94 where
95 getExpectedFilePath filePath =
95 getExpectedFilePath filePath =
96 testsDir
96 testsDir
@@ -98,38 +98,38 @@ testMatchesExpected elmDir expectedJsDir = do
98 </> joinPath (drop 3 (splitDirectories filePath))
98 </> joinPath (drop 3 (splitDirectories filePath))
99 <.> ".js"
99 <.> ".js"
100
100
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
106−
106+
107− Left (e :: IOException) ->
107+ Left (e :: IOException) ->
108− return (show e)
108+ return (show e)
109−
109+
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)
113−
113+
114− let formattedResult = compileString filePath source
114+ let formattedResult = compileString filePath source
115− assertion = matchesExpected expectedJs formattedResult
115+ let assertion = matchesExpected expectedJs formattedResult
116−
116+
117− return $ testCase filePath assertion
117+ return $ testCase filePath assertion
118−
118+
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)
129−
129+
130− _ ->
130+ _ ->
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
133
133
134
134
135-- CHECK RESULTS
135-- CHECK RESULTS