git.iko.soy/rowtype-yoga/purescript-native
on fcd2158 help sign in
123 lines 3.2 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.Alt"
57 , "Control.Alternative"
58 , "Control.Applicative"
59 , "Control.Apply"
60 , "Control.Bind"
61 , "Control.Category"
62 , "Control.Comonad"
63 , "Control.Extend"
64 , "Control.Lazy"
65 , "Control.Monad"
66 , "Control.Monad.Eff"
67 , "Control.Monad.Eff.Class"
68 , "Control.Monad.Eff.Console"
69 , "Control.Monad.Eff.Unsafe"
70 , "Control.Monad.ST"
71 , "Control.MonadPlus"
72 , "Control.MonadZero"
73 , "Control.Plus"
74 , "Control.Semigroupoid"
75 , "Data.Boolean"
76 , "Data.BooleanAlgebra"
77 , "Data.Bounded"
78 , "Data.CommutativeRing"
79 , "Data.Eq"
80 , "Data.EuclideanRing"
81 , "Data.Field"
82 , "Data.Function"
83 , "Data.Function.Uncurried"
84 , "Data.Functor"
85 , "Data.Functor.Invariant"
86 , "Data.Generic.Rep"
87 , "Data.Generic.Rep.Monoid"
88 , "Data.Generic.Rep.Eq"
89 , "Data.Generic.Rep.Ord"
90 , "Data.Generic.Rep.Semigroup"
91 , "Data.HeytingAlgebra"
92 , "Data.Monoid"
93 , "Data.Monoid.Additive"
94 , "Data.Monoid.Conj"
95 , "Data.Monoid.Disj"
96 , "Data.Monoid.Dual"
97 , "Data.Monoid.Endo"
98 , "Data.Monoid.Multiplicative"
99 , "Data.NaturalTransformation"
100 , "Data.Newtype"
101 , "Data.Ord"
102 , "Data.Ord.Unsafe"
103 , "Data.Ordering"
104 , "Data.Ring"
105 , "Data.Semigroup"
106 , "Data.Semiring"
107 , "Data.Show"
108 , "Data.Unit"
109 , "Data.Void"
110 , "Partial"
111 , "Partial.Unsafe"
112 , "Prelude"
113 , "Test.Assert"
114 , "Test.Main"
115 ]
117pushd :: forall a. FilePath -> IO a -> IO a
118pushd dir act = do
119 original <- getCurrentDirectory
120 setCurrentDirectory dir
121 result <- try act :: IO (Either IOException a)
122 setCurrentDirectory original
123 either throwIO return result