on master help sign in
Whitespace (do on newline)
commitc6d490eea67d9b61a8e0372356f13fde4a7256cc authorLaszlo Pandy <laszlo.pandy@prezi.com> dateWed 2 Sep 2015, 11:02 (11 years ago) parentfac1c25
1 file changed+54−54
tests/Test/Compiler.hs+54−54
tests/Test/Compiler.hs+54−54
@@ -27,16 +27,16 @@ writeExpectedJsEnvVarName =
2727
2828compilerTests :: Test
2929compilerTests =
30− buildTest $ do
31− goods <- testIf isSuccess =<< getElms "good"
32− bads <- testIf isFailure =<< getElms "bad"
33− expectedJsTests <- testMatchesExpected "good" "good-expected-js"
34− return $
35− testGroup "Compile Tests"
36− [ testGroup "Good Tests" goods
37− , testGroup "Bad Tests" bads
38− , testGroup "Expected JS Tests" expectedJsTests
39− ]
30+ buildTest $
31+ do goods <- testIf isSuccess =<< getElms "good"
32+ bads <- testIf isFailure =<< getElms "bad"
33+ expectedJsTests <- testMatchesExpected "good" "good-expected-js"
34+ return $
35+ testGroup "Compile Tests"
36+ [ testGroup "Good Tests" goods
37+ , testGroup "Bad Tests" bads
38+ , testGroup "Expected JS Tests" expectedJsTests
39+ ]
4040
4141
4242-- GATHER ELM FILES
@@ -75,22 +75,22 @@ testIf
7575testIf handleResult filePaths =
7676 traverse setupTest filePaths
7777 where
78− setupTest filePath = do
79− source <- readFile filePath
80− let formattedResult = compileString filePath source
78+ setupTest filePath =
79+ do source <- readFile filePath
80+ let formattedResult = compileString filePath source
8181
82− return $ testCase filePath (handleResult formattedResult)
82+ return $ testCase filePath (handleResult formattedResult)
8383
8484
8585testMatchesExpected :: String -> String -> IO [Test]
86−testMatchesExpected elmDir expectedJsDir = do
87− elmFiles <- getElms elmDir
88− envVar <- lookupEnv writeExpectedJsEnvVarName
89− if isJust envVar
90− then
91− traverse writeNewExpected elmFiles
92− else
93− traverse doTest elmFiles
86+testMatchesExpected elmDir expectedJsDir =
87+ do elmFiles <- getElms elmDir
88+ envVar <- lookupEnv writeExpectedJsEnvVarName
89+ if isJust envVar
90+ then
91+ traverse writeNewExpected elmFiles
92+ else
93+ traverse doTest elmFiles
9494 where
9595 getExpectedFilePath filePath =
9696 testsDir
@@ -98,38 +98,38 @@ testMatchesExpected elmDir expectedJsDir = do
9898 </> joinPath (drop 3 (splitDirectories filePath))
9999 <.> ".js"
100100
101− readFileOrErrorStr filePath = do
102− strOrExc <- try $ readFile filePath
103− case strOrExc of
104− Right s ->
105− return s
106−
107− Left (e :: IOException) ->
108− return (show e)
109−
110− doTest filePath = do
111− source <- readFile filePath
112− expectedJs <- readFileOrErrorStr (getExpectedFilePath filePath)
113−
114− let formattedResult = compileString filePath source
115− assertion = matchesExpected expectedJs formattedResult
116−
117− return $ testCase filePath assertion
118−
119− writeNewExpected filePath = do
120− source <- readFile filePath
121− let formattedResult = compileString filePath source
122− expectedFilePath = getExpectedFilePath filePath
123− assertion =
124− case formattedResult of
125− Right (Compiler.Result _ _ js) -> do
126− createDirectoryIfMissing True (dropFileName expectedFilePath)
127− writeFile expectedFilePath js
128− assertFailure ("Wrote new expected js: " ++ expectedFilePath)
129−
130− _ ->
131− assertFailure "Compile failed. Could not write new expected js."
132− return $ testCase filePath assertion
101+ readFileOrErrorStr filePath =
102+ do strOrExc <- try $ readFile filePath
103+ case strOrExc of
104+ Right s ->
105+ return s
106+
107+ Left (e :: IOException) ->
108+ return (show e)
109+
110+ doTest filePath =
111+ do source <- readFile filePath
112+ expectedJs <- readFileOrErrorStr (getExpectedFilePath filePath)
113+
114+ let formattedResult = compileString filePath source
115+ let assertion = matchesExpected expectedJs formattedResult
116+
117+ return $ testCase filePath assertion
118+
119+ writeNewExpected filePath =
120+ do source <- readFile filePath
121+ let formattedResult = compileString filePath source
122+ let expectedFilePath = getExpectedFilePath filePath
123+ let assertion =
124+ case formattedResult of
125+ Right (Compiler.Result _ _ js) ->
126+ do createDirectoryIfMissing True (dropFileName expectedFilePath)
127+ writeFile expectedFilePath js
128+ assertFailure ("Wrote new expected js: " ++ expectedFilePath)
129+
130+ _ ->
131+ assertFailure "Compile failed. Could not write new expected js."
132+ return $ testCase filePath assertion
133133
134134
135135-- CHECK RESULTS