X-Git-Url: http://git.lukelau.me/?a=blobdiff_plain;f=lsp-test%2FMain.hs;h=ec9cfa4175bac343a3cce7a0bbb7635c16c9391e;hb=54b23e6b7a8aa59e649a807ab286f0808908935a;hp=6dc0690daa268a0262f4fa4c3819de12e6b21cbf;hpb=f01fb33a61da785ec470a204069f718e5e7fef78;p=lsp-test.git diff --git a/lsp-test/Main.hs b/lsp-test/Main.hs index 6dc0690..ec9cfa4 100644 --- a/lsp-test/Main.hs +++ b/lsp-test/Main.hs @@ -9,20 +9,29 @@ import Language.Haskell.LSP.Test.Script import System.Environment import System.FilePath import System.Directory +import System.Exit import Language.Haskell.LSP.Test.Machine -import Language.Haskell.LSP.Test.Parsing ( toJSONMsg ) +import Language.Haskell.LSP.Test.Parsing + ( toJSONMsg ) +import Language.Haskell.LSP.Test.Replay import Language.Haskell.LSP.Messages import qualified Language.Haskell.LSP.Types as LSP main = do - fileName <- head <$> getArgs - blocks <- parseScript <$> readFile fileName - print blocks - rootDir <- getCurrentDirectory - runBlocks rootDir blocks - -runBlocks :: FilePath -> [Block] -> IO () -runBlocks rootDir blocks = runMachine rootDir (map convertBlock blocks) >>= putStrLn + args <- getArgs + curDir <- getCurrentDirectory + case args of + ["replay", cmd] -> replaySession cmd curDir + [file, cmd] -> do + blocks <- parseScript <$> readFile file + success <- runBlocks cmd curDir blocks + if success + then putStrLn "Success ✅" + else putStrLn "Failed ❌" >> exitFailure + _ -> putStrLn "usage: lsp-test (replay )|( )" + +runBlocks :: String -> FilePath -> [Block] -> IO Bool +runBlocks cmd rootDir blocks = runMachine cmd rootDir (map convertBlock blocks) where convertBlock :: Block -> (String, FromServerMessage -> Bool, [Session ()]) convertBlock (Block name w actions) = (name, mkWait w, map mkAction actions)