git.iko.soy/rowtype-yoga/purescript-native
on eaaef21 help sign in
101 lines 2.7 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
15import System.Exit (exitFailure)
16import System.IO (stderr, hPutStrLn)
18findNodeProcess :: IO (Maybe String)
19findNodeProcess = runMaybeT . msum $ map (MaybeT . findExecutable) names
20 where
21 names = ["nodejs", "node"]
23-- |
24-- Fetches code necessary to run the tests with. The resulting support code
25-- should then be checked in, so that npm/bower etc is not required to run the
26-- tests.
27--
28-- Simply rerun this (via ghci is probably easiest) when the support code needs
29-- updating.
30--
31updateSupportCode :: IO ()
32updateSupportCode = do
33 setCurrentDirectory "tests/support"
34 if System.Info.os == "mingw32"
35 then callProcess "setup-win.cmd" []
36 else do
37 callProcess "npm" ["install"]
38 -- bower uses shebang "/usr/bin/env node", but we might have nodejs
39 node <- maybe cannotFindNode pure =<< findNodeProcess
40 -- Sometimes we run as a root (e.g. in simple docker containers)
41 -- And we are non-interactive: https://github.com/bower/bower/issues/1162
42 callProcess node ["node_modules/.bin/bower", "--allow-root", "install", "--config.interactive=false"]
43 setCurrentDirectory "../.."
44 where
45 cannotFindNode :: IO a
46 cannotFindNode = do
47 hPutStrLn stderr "Cannot find node (or nodejs) executable"
48 exitFailure
50-- |
51-- The support modules that should be cached between test cases, to avoid
52-- excessive rebuilding.
53--
54supportModules :: [String]
55supportModules =
56 [ "Control.Applicative"
57 , "Control.Apply"
58 , "Control.Bind"
59 , "Control.Category"
60 , "Control.Monad.Eff.Class"
61 , "Control.Monad.Eff.Console"
62 , "Control.Monad.Eff.Unsafe"
63 , "Control.Monad.Eff"
64 , "Control.Monad.ST"
65 , "Control.Monad"
66 , "Control.Semigroupoid"
67 , "Data.Boolean"
68 , "Data.BooleanAlgebra"
69 , "Data.Bounded"
70 , "Data.CommutativeRing"
71 , "Data.Eq"
72 , "Data.EuclideanRing"
73 , "Data.Field"
74 , "Data.Function.Uncurried"
75 , "Data.Function"
76 , "Data.Functor"
77 , "Data.HeytingAlgebra"
78 , "Data.NaturalTransformation"
79 , "Data.Newtype"
80 , "Data.Ord.Unsafe"
81 , "Data.Ord"
82 , "Data.Ordering"
83 , "Data.Ring"
84 , "Data.Semigroup"
85 , "Data.Semiring"
86 , "Data.Show"
87 , "Data.Unit"
88 , "Data.Void"
89 , "Partial"
90 , "Partial.Unsafe"
91 , "Prelude"
92 , "Test.Assert"
93 ]
95pushd :: forall a. FilePath -> IO a -> IO a
96pushd dir act = do
97 original <- getCurrentDirectory
98 setCurrentDirectory dir
99 result <- try act :: IO (Either IOException a)
100 setCurrentDirectory original
101 either throwIO return result