git.iko.soy/rowtype-yoga/purescript-native
on cd4c708 help sign in
90 lines 2.3 kB history raw
1{-# LANGUAGE ScopedTypeVariables #-}
3module TestUtils where
5import Prelude ()
6import Prelude.Compat
8import Control.Monad
9import Control.Monad.Trans.Maybe
10import Control.Exception
12import System.Process
13import System.Directory
14import System.Info
16findNodeProcess :: IO (Maybe String)
17findNodeProcess = runMaybeT . msum $ map (MaybeT . findExecutable) names
18 where
19 names = ["nodejs", "node"]
21-- |
22-- Fetches code necessary to run the tests with. The resulting support code
23-- should then be checked in, so that npm/bower etc is not required to run the
24-- tests.
25--
26-- Simply rerun this (via ghci is probably easiest) when the support code needs
27-- updating.
28--
29updateSupportCode :: IO ()
30updateSupportCode = do
31 setCurrentDirectory "tests/support"
32 if System.Info.os == "mingw32"
33 then callProcess "setup-win.cmd" []
34 else do
35 callProcess "npm" ["install"]
36 -- Sometimes we run as a root (e.g. in simple docker containers)
37 -- And we are non-interactive: https://github.com/bower/bower/issues/1162
38 callProcess "node_modules/.bin/bower" ["--allow-root", "install", "--config.interactive=false"]
39 setCurrentDirectory "../.."
41-- |
42-- The support modules that should be cached between test cases, to avoid
43-- excessive rebuilding.
44--
45supportModules :: [String]
46supportModules =
47 [ "Control.Applicative"
48 , "Control.Apply"
49 , "Control.Bind"
50 , "Control.Category"
51 , "Control.Monad.Eff.Class"
52 , "Control.Monad.Eff.Console"
53 , "Control.Monad.Eff.Unsafe"
54 , "Control.Monad.Eff"
55 , "Control.Monad.ST"
56 , "Control.Monad"
57 , "Control.Semigroupoid"
58 , "Data.Boolean"
59 , "Data.BooleanAlgebra"
60 , "Data.Bounded"
61 , "Data.CommutativeRing"
62 , "Data.Eq"
63 , "Data.EuclideanRing"
64 , "Data.Field"
65 , "Data.Function.Uncurried"
66 , "Data.Function"
67 , "Data.Functor"
68 , "Data.HeytingAlgebra"
69 , "Data.Ord.Unsafe"
70 , "Data.Ord"
71 , "Data.Ordering"
72 , "Data.Ring"
73 , "Data.Semigroup"
74 , "Data.Semiring"
75 , "Data.Show"
76 , "Data.Unit"
77 , "Data.Void"
78 , "Partial"
79 , "Partial.Unsafe"
80 , "Prelude"
81 , "Test.Assert"
82 ]
84pushd :: forall a. FilePath -> IO a -> IO a
85pushd dir act = do
86 original <- getCurrentDirectory
87 setCurrentDirectory dir
88 result <- try act :: IO (Either IOException a)
89 setCurrentDirectory original
90 either throwIO return result