ghcid-1.0.0: test/Test/API.hs
-- | Test the high level library API
module Test.API(apiTests) where
import Test.Tasty
import Test.Tasty.HUnit
import System.FilePath
import System.IO.Extra
import System.Time.Extra
import Language.Haskell.Ghcid
import Language.Haskell.Ghcid.Util
import Test.Common
import Test.Util
apiTests :: TestTree
apiTests = localOption (mkTimeout 30000000) $ testGroup "API test"
[testCase "No files" $ withTempDir $ \dir -> do
echo <- testEcho
(ghci,load) <- startGhci "ghci -ignore-dot-ghci" (Just dir) echo
load @?= []
showModules ghci >>= (@?= [])
exec ghci "import Data.List"
exec ghci "nub \"test\"" >>= (@?= ["\"tes\""])
stopGhci ghci
,disable19650 $ testCase "Load file" $ withTempDir $ \dir -> do
writeFile (dir </> "File.hs") "module A where\na = 123"
echo <- testEcho
(ghci, load) <- startGhci "ghci -ignore-dot-ghci File.hs" (Just dir) echo
load @?= [Loading "A" "File.hs"]
exec ghci "a + 1" >>= (@?= ["124"])
reload ghci >>= (@?= [])
sleep =<< getModTimeResolution
writeFile (dir </> "File.hs") "module A where\na = 456"
exec ghci "a + 1" >>= (@?= ["124"])
reload ghci >>= (@?= [Loading "A" "File.hs"])
exec ghci "a + 1" >>= (@?= ["457"])
stopGhci ghci
-- ,testCase "Rewrite IDE paths" $ do
-- let projectDir = "/project"
-- rewriteRequestForGhci PathRelative projectDir ":type-at /project/app/Main.hs 5 34 5 38"
-- @?= ":type-at app/Main.hs 5 34 5 38"
-- rewriteRequestForGhci PathRelative projectDir ":type-at /other/Main.hs 5 34 5 38"
-- @?= ":type-at /other/Main.hs 5 34 5 38"
-- rewriteRequestForGhci PathRelative projectDir ":uses /project/dir with spaces/Main.hs 1 1 1 4"
-- @?= ":uses dir with spaces/Main.hs 1 1 1 4"
-- rewriteRequestForGhci PathAbsolute projectDir ":type-at /project/app/Main.hs 5 34 5 38"
-- @?= ":type-at /project/app/Main.hs 5 34 5 38"
-- rewriteResponseFromGhci PathRelative projectDir ["app/Main.hs:(5,34)-(5,38)", "app/Main.hs:5:34-38", "plain text"]
-- @?= ["/project/app/Main.hs:(5,34)-(5,38)", "/project/app/Main.hs:5:34-38", "plain text"]
-- rewriteResponseFromGhci PathAbsolute projectDir ["app/Main.hs:(5,34)-(5,38)"]
-- @?= ["app/Main.hs:(5,34)-(5,38)"]
]
testEcho :: IO (Stream -> String -> IO ())
testEcho = do
verbose <- isVerbose
pure $ if verbose then const putStrLn else \_ _ -> pure ()