diff --git a/SJW.cabal b/SJW.cabal index 4bcd8b7..339cb71 100644 --- a/SJW.cabal +++ b/SJW.cabal @@ -60,3 +60,16 @@ benchmark big-src , time default-language: Haskell2010 ghc-options: -Wall + +test-suite tests + type: detailed-0.9 + test-module: Tests + build-depends: base >=4.11 && <4.13 + , Cabal + , directory + , filepath + , random + , SJW + hs-source-dirs: test + default-language: Haskell2010 + ghc-options: -Wall diff --git a/test/Tests.hs b/test/Tests.hs new file mode 100644 index 0000000..0c0d491 --- /dev/null +++ b/test/Tests.hs @@ -0,0 +1,42 @@ +module Tests ( + tests + ) where + +import Distribution.TestSuite +import SJW (compile, source) +import System.FilePath (()) +import Text.Printf (printf) + +testData :: FilePath +testData = "test" "data" + +checkResult :: (String, Bool) -> IO Progress +checkResult (dirName, expected) = do + result <- either failed passed =<< compile (source [testData dirName]) + return . Finished $ if result == expected then Pass else Fail (explain message) + where + failed s = putStrLn s>> return False + passed _ = return True + explain = uncurry (printf "Compilation %sed when it was expected to %s") + message = if expected then ("fail", "succeed") else ("succeed", "fail") + +makeTest :: (String, Bool) -> TestInstance +makeTest (patternName, expected) = testInstance + where + testInstance = TestInstance { + run = checkResult (patternName, expected) + , name = patternName + , tags = [] + , options = [] + , setOption = \_ _ -> Right testInstance + } + +tests :: IO [Test] +tests = return $ (Test . makeTest) <$> [ + ("cycle", False) + , ("diamond", True) + , ("loop", False) + , ("q", False) + , ("simple", True) + , ("triangle", True) + ] diff --git a/tests/cycle/A.js b/test/data/cycle/A.js similarity index 100% rename from tests/cycle/A.js rename to test/data/cycle/A.js diff --git a/tests/cycle/B.js b/test/data/cycle/B.js similarity index 100% rename from tests/cycle/B.js rename to test/data/cycle/B.js diff --git a/tests/cycle/C.js b/test/data/cycle/C.js similarity index 100% rename from tests/cycle/C.js rename to test/data/cycle/C.js diff --git a/tests/cycle/Main.js b/test/data/cycle/Main.js similarity index 100% rename from tests/cycle/Main.js rename to test/data/cycle/Main.js diff --git a/tests/diamond/A.js b/test/data/diamond/A.js similarity index 100% rename from tests/diamond/A.js rename to test/data/diamond/A.js diff --git a/tests/diamond/B.js b/test/data/diamond/B.js similarity index 100% rename from tests/diamond/B.js rename to test/data/diamond/B.js diff --git a/tests/diamond/C.js b/test/data/diamond/C.js similarity index 100% rename from tests/diamond/C.js rename to test/data/diamond/C.js diff --git a/tests/diamond/Main.js b/test/data/diamond/Main.js similarity index 100% rename from tests/diamond/Main.js rename to test/data/diamond/Main.js diff --git a/tests/loop/A.js b/test/data/loop/A.js similarity index 100% rename from tests/loop/A.js rename to test/data/loop/A.js diff --git a/tests/loop/Main.js b/test/data/loop/Main.js similarity index 100% rename from tests/loop/Main.js rename to test/data/loop/Main.js diff --git a/tests/q/A.js b/test/data/q/A.js similarity index 100% rename from tests/q/A.js rename to test/data/q/A.js diff --git a/tests/q/B.js b/test/data/q/B.js similarity index 100% rename from tests/q/B.js rename to test/data/q/B.js diff --git a/tests/q/C.js b/test/data/q/C.js similarity index 100% rename from tests/q/C.js rename to test/data/q/C.js diff --git a/tests/q/D.js b/test/data/q/D.js similarity index 100% rename from tests/q/D.js rename to test/data/q/D.js diff --git a/tests/q/Main.js b/test/data/q/Main.js similarity index 100% rename from tests/q/Main.js rename to test/data/q/Main.js diff --git a/tests/simple/A.js b/test/data/simple/A.js similarity index 100% rename from tests/simple/A.js rename to test/data/simple/A.js diff --git a/tests/simple/B.js b/test/data/simple/B.js similarity index 100% rename from tests/simple/B.js rename to test/data/simple/B.js diff --git a/tests/simple/Main.js b/test/data/simple/Main.js similarity index 100% rename from tests/simple/Main.js rename to test/data/simple/Main.js diff --git a/tests/triangle/Main.js b/test/data/triangle/Main.js similarity index 100% rename from tests/triangle/Main.js rename to test/data/triangle/Main.js diff --git a/tests/triangle/N.js b/test/data/triangle/N.js similarity index 100% rename from tests/triangle/N.js rename to test/data/triangle/N.js diff --git a/tests/triangle/O.js b/test/data/triangle/O.js similarity index 100% rename from tests/triangle/O.js rename to test/data/triangle/O.js