summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPhilFreeman <>2016-04-21 03:55:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2016-04-21 03:55:00 (GMT)
commit164b1a98130296e0cb0d4eb3b04066ccbfdb2394 (patch)
treeefe662c186085590e00c6cf07da34d2eba627251 /tests
parenteedee6382a33ad7ca6c1fe36c7c02798f20e2086 (diff)
version 0.8.5.00.8.5.0
Diffstat (limited to 'tests')
-rw-r--r--tests/Language/PureScript/Ide/Integration.hs14
-rw-r--r--tests/Language/PureScript/Ide/RebuildSpec.hs62
-rw-r--r--tests/Main.hs18
-rw-r--r--tests/TestDocs.hs23
-rw-r--r--tests/TestPsci.hs3
-rw-r--r--tests/support/pscide/src/RebuildSpecDep.purs3
-rw-r--r--tests/support/pscide/src/RebuildSpecSingleModule.fail3
-rw-r--r--tests/support/pscide/src/RebuildSpecSingleModule.purs4
-rw-r--r--tests/support/pscide/src/RebuildSpecWithDeps.purs5
-rw-r--r--tests/support/pscide/src/RebuildSpecWithForeign.js3
-rw-r--r--tests/support/pscide/src/RebuildSpecWithForeign.purs3
-rw-r--r--tests/support/pscide/src/RebuildSpecWithMissingForeign.fail3
12 files changed, 124 insertions, 20 deletions
diff --git a/tests/Language/PureScript/Ide/Integration.hs b/tests/Language/PureScript/Ide/Integration.hs
index 7a57662..cea69fd 100644
--- a/tests/Language/PureScript/Ide/Integration.hs
+++ b/tests/Language/PureScript/Ide/Integration.hs
@@ -27,11 +27,13 @@ module Language.PureScript.Ide.Integration
, projectDirectory
, deleteFileIfExists
-- sending commands
+ , loadModule
, loadModuleWithDeps
, getFlexCompletions
, getType
, addImport
, addImplicitImport
+ , rebuildModule
-- checking results
, resultIsSuccess
, parseCompletions
@@ -131,6 +133,9 @@ quitServer = do
loadModuleWithDeps :: String -> IO String
loadModuleWithDeps m = sendCommand $ load [] [m]
+loadModule :: String -> IO String
+loadModule m = sendCommand $ load [m] []
+
getFlexCompletions :: String -> IO [(String, String, String)]
getFlexCompletions q = parseCompletions <$> sendCommand (completion [] (Just (flexMatcher q)))
@@ -143,6 +148,9 @@ addImport identifier fp outfp = sendCommand (addImportC identifier fp outfp)
addImplicitImport :: String -> FilePath -> FilePath -> IO String
addImplicitImport mn fp outfp = sendCommand (addImplicitImportC mn fp outfp)
+rebuildModule :: FilePath -> IO String
+rebuildModule m = sendCommand (rebuildC m Nothing)
+
-- Command Encoding
commandWrapper :: String -> Value -> Value
@@ -166,6 +174,12 @@ addImplicitImportC mn = addImportW $
, "module" .= mn
]
+rebuildC :: FilePath -> Maybe FilePath -> Value
+rebuildC file outFile =
+ commandWrapper "rebuild" (object [ "file" .= file
+ , "outfile" .= outFile
+ ])
+
addImportW :: Value -> FilePath -> FilePath -> Value
addImportW importCommand fp outfp =
commandWrapper "import" (object [ "file" .= fp
diff --git a/tests/Language/PureScript/Ide/RebuildSpec.hs b/tests/Language/PureScript/Ide/RebuildSpec.hs
new file mode 100644
index 0000000..f7370af
--- /dev/null
+++ b/tests/Language/PureScript/Ide/RebuildSpec.hs
@@ -0,0 +1,62 @@
+module Language.PureScript.Ide.RebuildSpec where
+
+import Control.Monad
+import qualified Language.PureScript.Ide.Integration as Integration
+import Test.Hspec
+
+import System.FilePath
+
+compile :: IO ()
+compile = do
+ Integration.deleteOutputFolder
+ s <- Integration.compileTestProject
+ unless s $ fail "Failed to compile .purs sources"
+
+teardown :: IO ()
+teardown = Integration.quitServer
+
+restart :: IO ()
+restart = Integration.quitServer *> (void Integration.startServer)
+
+shouldBeSuccess :: String -> IO ()
+shouldBeSuccess = shouldBe True . Integration.resultIsSuccess
+
+shouldBeFailure :: String -> IO ()
+shouldBeFailure = shouldBe False . Integration.resultIsSuccess
+
+spec :: Spec
+spec = beforeAll_ compile $ afterAll_ teardown $ before_ restart $ do
+ describe "Rebuilding single modules" $ do
+ it "rebuilds a correct module without dependencies successfully" $ do
+ _ <- Integration.loadModuleWithDeps "RebuildSpecSingleModule"
+ pdir <- Integration.projectDirectory
+ let file = pdir </> "src" </> "RebuildSpecSingleModule.purs"
+ Integration.rebuildModule file >>= shouldBeSuccess
+ it "fails to rebuild an incorrect module without dependencies and returns the errors" $ do
+ pdir <- Integration.projectDirectory
+ let file = pdir </> "src" </> "RebuildSpecSingleModule.fail"
+ Integration.rebuildModule file >>= shouldBeFailure
+ it "rebuilds a correct module with its dependencies successfully" $ do
+ _ <- Integration.loadModuleWithDeps "RebuildSpecWithDeps"
+ pdir <- Integration.projectDirectory
+ let file = pdir </> "src" </> "RebuildSpecWithDeps.purs"
+ Integration.rebuildModule file >>= shouldBeSuccess
+ it "rebuilds a correct module that has reverse dependencies" $ do
+ _ <- Integration.loadModuleWithDeps "RebuildSpecWithDeps"
+ pdir <- Integration.projectDirectory
+ let file = pdir </> "src" </> "RebuildSpecDep.purs"
+ Integration.rebuildModule file >>= shouldBeSuccess
+ it "fails to rebuild a module if its dependencies are not loaded" $ do
+ _ <- Integration.loadModule "RebuildSpecWithDeps"
+ pdir <- Integration.projectDirectory
+ let file = pdir </> "src" </> "RebuildSpecWithDeps.purs"
+ Integration.rebuildModule file >>= shouldBeFailure
+ it "rebuilds a correct module with a foreign file" $ do
+ _ <- Integration.loadModuleWithDeps "RebuildSpecWithForeign"
+ pdir <- Integration.projectDirectory
+ let file = pdir </> "src" </> "RebuildSpecWithForeign.purs"
+ Integration.rebuildModule file >>= shouldBeSuccess
+ it "fails to rebuild a module with a foreign import but no file" $ do
+ pdir <- Integration.projectDirectory
+ let file = pdir </> "src" </> "RebuildSpecWithMissingForeign.fail"
+ Integration.rebuildModule file >>= shouldBeFailure
diff --git a/tests/Main.hs b/tests/Main.hs
index 152cd44..2a246ef 100644
--- a/tests/Main.hs
+++ b/tests/Main.hs
@@ -1,16 +1,3 @@
------------------------------------------------------------------------------
---
--- Module : Main
--- License : MIT (http://opensource.org/licenses/MIT)
---
--- Maintainer : Phil Freeman <paf31@cantab.net>
--- Stability : experimental
--- Portability :
---
--- |
---
------------------------------------------------------------------------------
-
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DoAndIfThenElse #-}
{-# LANGUAGE TupleSections #-}
@@ -27,8 +14,13 @@ import qualified TestDocs
import qualified TestPsci
import qualified TestPscIde
+import System.IO (hSetEncoding, stdout, stderr, utf8)
+
main :: IO ()
main = do
+ hSetEncoding stdout utf8
+ hSetEncoding stderr utf8
+
heading "Main compiler test suite"
TestCompiler.main
heading "Documentation test suite"
diff --git a/tests/TestDocs.hs b/tests/TestDocs.hs
index 1af8bd4..dff2da4 100644
--- a/tests/TestDocs.hs
+++ b/tests/TestDocs.hs
@@ -285,12 +285,20 @@ testCases =
, ValueShouldHaveTypeSignature (n "ExplicitTypeSignatures") "aNumber" (ShowFn (P.tyNumber ==))
])
- , ("ConstrainedArgument",
- [ TypeSynonymShouldRenderAs (n "ConstrainedArgument") "WithoutArgs" "forall a. (Partial => a) -> a"
- , TypeSynonymShouldRenderAs (n "ConstrainedArgument") "WithArgs" "forall a. (Foo a => a) -> a"
- , TypeSynonymShouldRenderAs (n "ConstrainedArgument") "MultiWithoutArgs" "forall a. ((Partial, Partial) => a) -> a"
- , TypeSynonymShouldRenderAs (n "ConstrainedArgument") "MultiWithArgs" "forall a b. ((Foo a, Foo b) => a) -> a"
- ])
+ , ("ConstrainedArgument",
+ [ TypeSynonymShouldRenderAs (n "ConstrainedArgument") "WithoutArgs" "forall a. (Partial => a) -> a"
+ , TypeSynonymShouldRenderAs (n "ConstrainedArgument") "WithArgs" "forall a. (Foo a => a) -> a"
+ , TypeSynonymShouldRenderAs (n "ConstrainedArgument") "MultiWithoutArgs" "forall a. ((Partial, Partial) => a) -> a"
+ , TypeSynonymShouldRenderAs (n "ConstrainedArgument") "MultiWithArgs" "forall a b. ((Foo a, Foo b) => a) -> a"
+ ])
+
+ , ("TypeOpAliases",
+ [ ValueShouldHaveTypeSignature (n "TypeOpAliases") "test1" (renderedType "forall a b. a ~> b")
+ , ValueShouldHaveTypeSignature (n "TypeOpAliases") "test2" (renderedType "forall a b c. a ~> b ~> c")
+ , ValueShouldHaveTypeSignature (n "TypeOpAliases") "test3" (renderedType "forall a b c d. a ~> (b ~> c) ~> d")
+ , ValueShouldHaveTypeSignature (n "TypeOpAliases") "test4" (renderedType "forall a b c d. ((a ~> b) ~> c) ~> d")
+ , ValueShouldHaveTypeSignature (n "TypeOpAliases") "third" (renderedType "forall a b c. a × b × c -> c")
+ ])
]
where
@@ -301,3 +309,6 @@ testCases =
isVar varName (P.TypeVar name) | varName == name = True
isVar _ _ = False
+
+ renderedType expected =
+ ShowFn $ \ty -> codeToString (Docs.renderType ty) == expected
diff --git a/tests/TestPsci.hs b/tests/TestPsci.hs
index 3d058df..ee0a2c1 100644
--- a/tests/TestPsci.hs
+++ b/tests/TestPsci.hs
@@ -17,6 +17,7 @@ import System.Exit (exitFailure)
import System.Console.Haskeline
import System.FilePath ((</>))
import System.Directory (getCurrentDirectory)
+import System.IO.UTF8 (readUTF8File)
import qualified System.FilePath.Glob as Glob
import Test.HUnit
@@ -132,7 +133,7 @@ getPSCiState = do
jsFiles <- supportFiles "js"
modulesOrFirstError <- loadAllModules pursFiles
- foreignFiles <- forM jsFiles (\f -> (f,) <$> readFile f)
+ foreignFiles <- forM jsFiles (\f -> (f,) <$> readUTF8File f)
Right (foreigns, _) <- runExceptT $ runWriterT $ P.parseForeignModulesFromFiles foreignFiles
case modulesOrFirstError of
Left err ->
diff --git a/tests/support/pscide/src/RebuildSpecDep.purs b/tests/support/pscide/src/RebuildSpecDep.purs
new file mode 100644
index 0000000..afd29a8
--- /dev/null
+++ b/tests/support/pscide/src/RebuildSpecDep.purs
@@ -0,0 +1,3 @@
+module RebuildSpecDep where
+
+dep = 42
diff --git a/tests/support/pscide/src/RebuildSpecSingleModule.fail b/tests/support/pscide/src/RebuildSpecSingleModule.fail
new file mode 100644
index 0000000..b411eb4
--- /dev/null
+++ b/tests/support/pscide/src/RebuildSpecSingleModule.fail
@@ -0,0 +1,3 @@
+module RebuildSpecSingleModule where
+
+let anerror \ No newline at end of file
diff --git a/tests/support/pscide/src/RebuildSpecSingleModule.purs b/tests/support/pscide/src/RebuildSpecSingleModule.purs
new file mode 100644
index 0000000..4059629
--- /dev/null
+++ b/tests/support/pscide/src/RebuildSpecSingleModule.purs
@@ -0,0 +1,4 @@
+module RebuildSpecSingleModule where
+
+id x = x
+const x y = x
diff --git a/tests/support/pscide/src/RebuildSpecWithDeps.purs b/tests/support/pscide/src/RebuildSpecWithDeps.purs
new file mode 100644
index 0000000..c095a92
--- /dev/null
+++ b/tests/support/pscide/src/RebuildSpecWithDeps.purs
@@ -0,0 +1,5 @@
+module RebuildSpecWithDeps where
+
+import RebuildSpecDep (dep)
+
+x = dep
diff --git a/tests/support/pscide/src/RebuildSpecWithForeign.js b/tests/support/pscide/src/RebuildSpecWithForeign.js
new file mode 100644
index 0000000..7c82dc8
--- /dev/null
+++ b/tests/support/pscide/src/RebuildSpecWithForeign.js
@@ -0,0 +1,3 @@
+// module RebuildSpecWithForeign
+
+exports.f = 5;
diff --git a/tests/support/pscide/src/RebuildSpecWithForeign.purs b/tests/support/pscide/src/RebuildSpecWithForeign.purs
new file mode 100644
index 0000000..2f425ef
--- /dev/null
+++ b/tests/support/pscide/src/RebuildSpecWithForeign.purs
@@ -0,0 +1,3 @@
+module RebuildSpecWithForeign where
+
+foreign import f :: Int
diff --git a/tests/support/pscide/src/RebuildSpecWithMissingForeign.fail b/tests/support/pscide/src/RebuildSpecWithMissingForeign.fail
new file mode 100644
index 0000000..c75fdea
--- /dev/null
+++ b/tests/support/pscide/src/RebuildSpecWithMissingForeign.fail
@@ -0,0 +1,3 @@
+module RebuildSpecWithMissingForeign where
+
+foreign import f :: Int