diff --git a/tests/Main.hs b/tests/Main.hs index 33483cc..13547b3 100644 --- a/tests/Main.hs +++ b/tests/Main.hs @@ -1,38 +1,8 @@ module Main where -import Data.Functor ((<$>)) -import Data.Traversable (traverse) -import System.FilePath.Find (find, (==?), extension) import Test.Framework -import Test.Framework.Providers.HUnit (testCase) -import Test.HUnit ((@=?), Assertion) -import Elm.Internal.Utils as Elm +import Tests.Compiler main :: IO () -main = defaultMain [compilerTests] - -compilerTests :: Test -compilerTests = buildTest $ do - goods <- getElms "tests/good" >>= mkTests True - bads <- getElms "tests/bad" >>= mkTests False - - return $ testGroup "Compile Tests" - [ - testGroup "Good Tests" goods - , testGroup "Bad Tests" bads - ] - - where getElms :: FilePath -> IO [FilePath] - getElms = find (return True) (extension ==? ".elm") - - mkTests :: Bool -> [FilePath] -> IO [Test] - mkTests b = traverse setupTest - where setupTest f = testCase f . mkCompileTest b <$> readFile f - -mkCompileTest :: Bool -- ^ Expect success? - -> String -- ^ File Contents - -> Assertion -mkCompileTest succ modul = noCompileErr @=? succ - where noCompileErr = either (const False) (const True) . Elm.compile $ modul - expectation = "Compile " ++ if succ then "Success" else "Error" +main = defaultMain [ compilerTests ] diff --git a/tests/Tests/Compiler.hs b/tests/Tests/Compiler.hs new file mode 100644 index 0000000..81162c8 --- /dev/null +++ b/tests/Tests/Compiler.hs @@ -0,0 +1,36 @@ +module Tests.Compiler (compilerTests) + where + +import Data.Functor ((<$>)) +import Data.Traversable (traverse) +import System.FilePath.Find (find, (==?), extension) +import Test.Framework +import Test.Framework.Providers.HUnit (testCase) +import Test.HUnit ((@=?), Assertion) + +import Elm.Internal.Utils as Elm + +compilerTests :: Test +compilerTests = buildTest $ do + goods <- getElms "tests/data/good" >>= mkTests True + bads <- getElms "tests/data/bad" >>= mkTests False + + return $ testGroup "Compile Tests" + [ + testGroup "Good Tests" goods + , testGroup "Bad Tests" bads + ] + + where getElms :: FilePath -> IO [FilePath] + getElms = find (return True) (extension ==? ".elm") + + mkTests :: Bool -> [FilePath] -> IO [Test] + mkTests b = traverse setupTest + where setupTest f = testCase f . mkCompileTest b <$> readFile f + +mkCompileTest :: Bool -- ^ Expect success? + -> String -- ^ File Contents + -> Assertion +mkCompileTest succ modul = noCompileErr @=? succ + where noCompileErr = either (const False) (const True) . Elm.compile $ modul + expectation = "Compile " ++ if succ then "Success" else "Error" diff --git a/tests/bad/BBTArgs b/tests/data/bad/BBTArgs similarity index 100% rename from tests/bad/BBTArgs rename to tests/data/bad/BBTArgs diff --git a/tests/bad/InfiniteType.elm b/tests/data/bad/InfiniteType.elm similarity index 100% rename from tests/bad/InfiniteType.elm rename to tests/data/bad/InfiniteType.elm diff --git a/tests/bad/NonElementMain.elm b/tests/data/bad/NonElementMain.elm similarity index 100% rename from tests/bad/NonElementMain.elm rename to tests/data/bad/NonElementMain.elm diff --git a/tests/good/AliasSubstitution.elm b/tests/data/good/AliasSubstitution.elm similarity index 100% rename from tests/good/AliasSubstitution.elm rename to tests/data/good/AliasSubstitution.elm diff --git a/tests/good/NoExpressions.elm b/tests/data/good/NoExpressions.elm similarity index 100% rename from tests/good/NoExpressions.elm rename to tests/data/good/NoExpressions.elm diff --git a/tests/good/Otherwise.elm b/tests/data/good/Otherwise.elm similarity index 100% rename from tests/good/Otherwise.elm rename to tests/data/good/Otherwise.elm diff --git a/tests/good/QuotesAndComments.elm b/tests/data/good/QuotesAndComments.elm similarity index 100% rename from tests/good/QuotesAndComments.elm rename to tests/data/good/QuotesAndComments.elm diff --git a/tests/good/Soundness/Apply.elm b/tests/data/good/Soundness/Apply.elm similarity index 100% rename from tests/good/Soundness/Apply.elm rename to tests/data/good/Soundness/Apply.elm diff --git a/tests/good/Soundness/ApplyAnnotated.elm b/tests/data/good/Soundness/ApplyAnnotated.elm similarity index 100% rename from tests/good/Soundness/ApplyAnnotated.elm rename to tests/data/good/Soundness/ApplyAnnotated.elm diff --git a/tests/good/Soundness/Id.elm b/tests/data/good/Soundness/Id.elm similarity index 100% rename from tests/good/Soundness/Id.elm rename to tests/data/good/Soundness/Id.elm diff --git a/tests/good/Soundness/IdAnnotated.elm b/tests/data/good/Soundness/IdAnnotated.elm similarity index 100% rename from tests/good/Soundness/IdAnnotated.elm rename to tests/data/good/Soundness/IdAnnotated.elm diff --git a/tests/good/Soundness/TrickyId.elm b/tests/data/good/Soundness/TrickyId.elm similarity index 100% rename from tests/good/Soundness/TrickyId.elm rename to tests/data/good/Soundness/TrickyId.elm diff --git a/tests/good/Soundness/TrickyIdAnnotated.elm b/tests/data/good/Soundness/TrickyIdAnnotated.elm similarity index 100% rename from tests/good/Soundness/TrickyIdAnnotated.elm rename to tests/data/good/Soundness/TrickyIdAnnotated.elm diff --git a/tests/good/Unify/LockedVars.elm b/tests/data/good/Unify/LockedVars.elm similarity index 100% rename from tests/good/Unify/LockedVars.elm rename to tests/data/good/Unify/LockedVars.elm diff --git a/tests/good/Unify/NonHomogeneousRecords.elm b/tests/data/good/Unify/NonHomogeneousRecords.elm similarity index 100% rename from tests/good/Unify/NonHomogeneousRecords.elm rename to tests/data/good/Unify/NonHomogeneousRecords.elm