Skip to content

Commit 54831da

Browse files
committed
Install test support code automatically
1 parent ee3035f commit 54831da

18 files changed

+27
-1791
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ cabal.sandbox.config
1313
bower_components/
1414
tmp/
1515
.stack-work/
16+
tests/support/flattened/

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Please follow the following guidelines:
99
- Add at least a test to `examples/passing/` and possibly to `examples/failing`.
1010
- Build the binaries and libs with `cabal build`
1111
- Install the binaries and libs with `cabal install`.
12-
- Run `cabal configure --enable-tests && cabal build && cabal test` to build the test suite.
13-
- Build the core libraries by running the script in `core-tests`
12+
- Run `cabal configure --enable-tests && cabal build && cabal test` to build the test suite. You will need `npm`, `node`, and `bower` on your PATH to run the tests.
13+
- Build the core libraries by running the script in `core-tests`.
1414

1515
If you would like to contribute, please consider the issues in the current milestone first. If you are a new contributor, you may want to have a go at the ["easy" issues](https://github.com/purescript/purescript/labels/easy) to get started.
1616

tests/Main.hs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
-----------------------------------------------------------------------------
1414

1515
{-# LANGUAGE DataKinds #-}
16-
{-# LANGUAGE DoAndIfThenElse #-}
16+
{-# LANGUAGE DoAndIfThenElse #-}
1717
{-# LANGUAGE TupleSections #-}
1818
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
1919
{-# LANGUAGE FlexibleInstances #-}
@@ -61,23 +61,23 @@ makeActions :: M.Map P.ModuleName (FilePath, P.ForeignJS) -> P.MakeActions Test
6161
makeActions foreigns = P.MakeActions getInputTimestamp getOutputTimestamp readExterns codegen progress
6262
where
6363
getInputTimestamp :: P.ModuleName -> Test (Either P.RebuildPolicy (Maybe UTCTime))
64-
getInputTimestamp mn
64+
getInputTimestamp mn
6565
| isSupportModule (P.runModuleName mn) = return (Left P.RebuildNever)
6666
| otherwise = return (Left P.RebuildAlways)
6767
where
6868
isSupportModule = flip elem supportModules
69-
69+
7070
getOutputTimestamp :: P.ModuleName -> Test (Maybe UTCTime)
7171
getOutputTimestamp mn = do
7272
let filePath = modulesDir </> P.runModuleName mn
7373
exists <- liftIO $ doesDirectoryExist filePath
7474
return (if exists then Just (error "getOutputTimestamp: read timestamp") else Nothing)
75-
75+
7676
readExterns :: P.ModuleName -> Test (FilePath, String)
7777
readExterns mn = do
7878
let filePath = modulesDir </> P.runModuleName mn </> "externs.purs"
7979
(filePath, ) <$> readTextFile filePath
80-
80+
8181
codegen :: CF.Module CF.Ann -> P.Environment -> P.SupplyVar -> P.Externs -> Test ()
8282
codegen m _ nextVar exts = do
8383
let mn = CF.moduleName m
@@ -94,15 +94,15 @@ makeActions foreigns = P.MakeActions getInputTimestamp getOutputTimestamp readEx
9494
writeTextFile jsFile pjs
9595
maybe (return ()) (writeTextFile foreignFile . snd) $ CF.moduleName m `M.lookup` foreigns
9696
writeTextFile externsFile exts
97-
97+
9898
readTextFile :: FilePath -> Test String
9999
readTextFile path = liftIO $ readFile path
100-
100+
101101
writeTextFile :: FilePath -> String -> Test ()
102102
writeTextFile path text = liftIO $ do
103103
createDirectoryIfMissing True (takeDirectory path)
104104
writeFile path text
105-
105+
106106
progress :: String -> Test ()
107107
progress = liftIO . putStrLn
108108

@@ -117,9 +117,9 @@ compile inputFiles foreigns = runTest $ do
117117
ms <- P.parseModulesFromFiles id fs
118118
P.make (makeActions foreigns) (map (\(k, v) -> (Right k, v)) ms)
119119

120-
assert :: [FilePath] ->
121-
M.Map P.ModuleName (FilePath, P.ForeignJS) ->
122-
(Either P.MultipleErrors P.Environment -> IO (Maybe String)) ->
120+
assert :: [FilePath] ->
121+
M.Map P.ModuleName (FilePath, P.ForeignJS) ->
122+
(Either P.MultipleErrors P.Environment -> IO (Maybe String)) ->
123123
IO ()
124124
assert inputFiles foreigns f = do
125125
e <- compile inputFiles foreigns
@@ -132,7 +132,7 @@ assertCompiles :: [FilePath] -> M.Map P.ModuleName (FilePath, P.ForeignJS) -> IO
132132
assertCompiles inputFiles foreigns = do
133133
putStrLn $ "Assert " ++ last inputFiles ++ " compiles successfully"
134134
assert inputFiles foreigns $ \e ->
135-
case e of
135+
case e of
136136
Left errs -> return . Just . P.prettyPrintMultipleErrors False $ errs
137137
Right _ -> do
138138
process <- findNodeProcess
@@ -154,13 +154,14 @@ assertDoesNotCompile inputFiles foreigns = do
154154

155155
findNodeProcess :: IO (Maybe String)
156156
findNodeProcess = runMaybeT . msum $ map (MaybeT . findExecutable) names
157-
where
157+
where
158158
names = ["nodejs", "node"]
159159

160160
main :: IO ()
161161
main = do
162+
fetchSupportCode
162163
cwd <- getCurrentDirectory
163-
164+
164165
let supportDir = cwd </> "tests" </> "support" </> "flattened"
165166
let supportFiles ext = Glob.globDir1 (Glob.compile ("*." ++ ext)) supportDir
166167

@@ -169,7 +170,7 @@ main = do
169170

170171
foreignFiles <- forM supportJS (\f -> (f,) <$> readFile f)
171172
Right (foreigns, _) <- runExceptT $ runWriterT $ P.parseForeignModulesFromFiles foreignFiles
172-
173+
173174
let passing = cwd </> "examples" </> "passing"
174175
passingTestCases <- getDirectoryContents passing
175176
forM_ passingTestCases $ \inputFile -> when (".purs" `isSuffixOf` inputFile) $
@@ -180,6 +181,14 @@ main = do
180181
assertDoesNotCompile (supportPurs ++ [failing </> inputFile]) foreigns
181182
exitSuccess
182183

184+
fetchSupportCode :: IO ()
185+
fetchSupportCode = do
186+
setCurrentDirectory "tests/support"
187+
callProcess "npm" ["install"]
188+
callProcess "bower" ["install"]
189+
callProcess "node" ["setup.js"]
190+
setCurrentDirectory "../.."
191+
183192
supportModules :: [String]
184193
supportModules =
185194
[ "Control.Monad.Eff.Class"

tests/support/flattened/Control-Monad-Eff-Class.purs

Lines changed: 0 additions & 24 deletions
This file was deleted.

tests/support/flattened/Control-Monad-Eff-Console.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/support/flattened/Control-Monad-Eff-Console.purs

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/support/flattened/Control-Monad-Eff-Unsafe.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/support/flattened/Control-Monad-Eff-Unsafe.purs

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/support/flattened/Control-Monad-Eff.js

Lines changed: 0 additions & 62 deletions
This file was deleted.

tests/support/flattened/Control-Monad-Eff.purs

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)