git.iko.soy/rowtype-yoga/purescript-native
on eb5d4e4 help sign in
65 lines 1.9 kB history raw
1-----------------------------------------------------------------------------
2--
3-- Module : Main
4-- License : MIT (http://opensource.org/licenses/MIT)
5--
6-- Maintainer : Phil Freeman <paf31@cantab.net>
7-- Stability : experimental
8-- Portability :
9--
10-- |
11--
12-----------------------------------------------------------------------------
13{-# LANGUAGE ScopedTypeVariables #-}
15module TestUtils where
17import Prelude ()
18import Prelude.Compat
20import Data.Maybe (fromMaybe)
21import Control.Monad
22import Control.Monad.Trans.Maybe
23import Control.Exception
25import System.Process
26import System.Directory
27import System.Info
29import Language.PureScript.Crash
31findNodeProcess :: IO (Maybe String)
32findNodeProcess = runMaybeT . msum $ map (MaybeT . findExecutable) names
33 where
34 names = ["nodejs", "node"]
36-- |
37-- Fetches code necessary to run the tests with. The resulting support code
38-- should then be checked in, so that npm/bower etc is not required to run the
39-- tests.
40--
41-- Simply rerun this (via ghci is probably easiest) when the support code needs
42-- updating.
43--
44updateSupportCode :: IO ()
45updateSupportCode = do
46 node <- fromMaybe (internalError "cannot find node executable") <$> findNodeProcess
47 setCurrentDirectory "tests/support"
48 if System.Info.os == "mingw32"
49 then callProcess "setup-win.cmd" []
50 else do
51 callProcess "npm" ["install"]
52 -- Sometimes we run as a root (e.g. in simple docker containers)
53 -- And we are non-interactive: https://github.com/bower/bower/issues/1162
54 callProcess "node_modules/.bin/bower" ["--allow-root", "install", "--config.interactive=false"]
55 callProcess node ["setup.js"]
56 setCurrentDirectory "../.."
58pushd :: forall a. FilePath -> IO a -> IO a
59pushd dir act = do
60 original <- getCurrentDirectory
61 setCurrentDirectory dir
62 result <- try act :: IO (Either IOException a)
63 setCurrentDirectory original
64 either throwIO return result