on 5e33985 help sign in
elk/tests/libraries/LibraryTest.hs
48 lines 1.4 kB history raw
1module Main where
3import Control.Monad (unless)
4import Data.List (isInfixOf)
5import System.Directory
6import System.Exit
7import System.FilePath
8import System.Process
10import Elm.Internal.Paths as Elm
12main :: IO ()
13main = do
14 top <- getCurrentDirectory
16 -- setup submodules and npm
17 runCmd "git" ["submodule", "update", "--init"]
18 out <- readProcess "npm" ["ls", "--parseable"] ""
19 unless ("jsdom" `isInfixOf` out) $ runCmd "npm" ["install","jsdom"]
21 -- setup actual library tests
22 setCurrentDirectory $ top </> "tests" </> "libraries"
23 let localCompiler = joinPath [ top, "dist", "build", "elm", "elm" ]
24 runCmd localCompiler [ "--make"
25 , "--only-js"
26 , "--src-dir=" ++ top </> "IO"
27 , "--src-dir=" ++ top </> "Elm-Test"
28 , "Test.elm"
29 ]
31 -- run tests
32 let ioScript s = top </> "IO" </> s
33 files = [ ioScript "prescript.js"
34 , Elm.runtime
35 , "build" </> "Test.js"
36 , ioScript "handler.js"
37 ]
38 exe <- readProcess "cat" files ""
39 writeFile "exe.js" exe
40 exitWith =<< waitForProcess =<< (runCommand "node exe.js")
42runCmd :: String -> [String] -> IO ()
43runCmd cmd args = do
44 putStrLn (cmd ++ " " ++ unwords args)
45 (exitCode, _stdout, stderr) <- readProcessWithExitCode cmd args ""
46 case exitCode of
47 ExitSuccess -> return ()
48 ExitFailure _ -> error stderr