git.iko.soy/rowtype-yoga/purescript-native
on 4e7cfee help sign in
167 lines 4.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.Biapplicative"
61 , "Control.Biapply"
62 , "Control.Bind"
63 , "Control.Category"
64 , "Control.Comonad"
65 , "Control.Extend"
66 , "Control.Lazy"
67 , "Control.Monad"
68 , "Control.Monad.Eff"
69 , "Control.Monad.Eff.Class"
70 , "Control.Monad.Eff.Console"
71 , "Control.Monad.Eff.Unsafe"
72 , "Control.Monad.Rec.Class"
73 , "Control.Monad.ST"
74 , "Control.MonadPlus"
75 , "Control.MonadZero"
76 , "Control.Plus"
77 , "Control.Semigroupoid"
78 , "Data.Array"
79 , "Data.Array.Partial"
80 , "Data.Array.ST"
81 , "Data.Array.ST.Iterator"
82 , "Data.Bifoldable"
83 , "Data.Bifunctor"
84 , "Data.Bifunctor.Clown"
85 , "Data.Bifunctor.Flip"
86 , "Data.Bifunctor.Join"
87 , "Data.Bifunctor.Joker"
88 , "Data.Bifunctor.Product"
89 , "Data.Bifunctor.Wrap"
90 , "Data.Bitraversable"
91 , "Data.Boolean"
92 , "Data.BooleanAlgebra"
93 , "Data.Bounded"
94 , "Data.Char"
95 , "Data.CommutativeRing"
96 , "Data.Either"
97 , "Data.Either.Nested"
98 , "Data.Eq"
99 , "Data.EuclideanRing"
100 , "Data.Field"
101 , "Data.Foldable"
102 , "Data.Function"
103 , "Data.Function.Uncurried"
104 , "Data.Functor"
105 , "Data.Functor.Invariant"
106 , "Data.Generic"
107 , "Data.Generic.Rep"
108 , "Data.Generic.Rep.Eq"
109 , "Data.Generic.Rep.Monoid"
110 , "Data.Generic.Rep.Ord"
111 , "Data.Generic.Rep.Semigroup"
112 , "Data.Generic.Rep.Show"
113 , "Data.HeytingAlgebra"
114 , "Data.Identity"
115 , "Data.Maybe"
116 , "Data.Maybe.First"
117 , "Data.Maybe.Last"
118 , "Data.Monoid"
119 , "Data.Monoid.Additive"
120 , "Data.Monoid.Alternate"
121 , "Data.Monoid.Conj"
122 , "Data.Monoid.Disj"
123 , "Data.Monoid.Dual"
124 , "Data.Monoid.Endo"
125 , "Data.Monoid.Multiplicative"
126 , "Data.NaturalTransformation"
127 , "Data.Newtype"
128 , "Data.NonEmpty"
129 , "Data.Ord"
130 , "Data.Ord.Unsafe"
131 , "Data.Ordering"
132 , "Data.Ring"
133 , "Data.Semigroup"
134 , "Data.Semiring"
135 , "Data.Show"
136 , "Data.String"
137 , "Data.String.CaseInsensitive"
138 , "Data.String.Regex"
139 , "Data.String.Regex.Flags"
140 , "Data.String.Regex.Unsafe"
141 , "Data.String.Unsafe"
142 , "Data.Symbol"
143 , "Data.Traversable"
144 , "Data.Tuple"
145 , "Data.Tuple.Nested"
146 , "Data.Unfoldable"
147 , "Data.Unit"
148 , "Data.Void"
149 , "Partial"
150 , "Partial.Unsafe"
151 , "Prelude"
152 , "Test.Assert"
153 , "Type.Data.Ordering"
154 , "Type.Data.Symbol"
155 , "Type.Equality"
156 , "Type.Prelude"
157 , "Type.Proxy"
158 , "Unsafe.Coerce"
159 ]
161pushd :: forall a. FilePath -> IO a -> IO a
162pushd dir act = do
163 original <- getCurrentDirectory
164 setCurrentDirectory dir
165 result <- try act :: IO (Either IOException a)
166 setCurrentDirectory original
167 either throwIO return result