@@ -61,13 +61,13 @@ main = hspec spec
61spec :: Spec
61spec :: Spec
64− (supportExterns, passingTestCases, warningTestCases, failingTestCases) <- runIO $ do
64+ (supportExterns, supportForeigns, passingTestCases, warningTestCases, failingTestCases) <- runIO $ do
65 cwd <- getCurrentDirectory
65 cwd <- getCurrentDirectory
66 let passing = cwd </> "examples" </> "passing"
66 let passing = cwd </> "examples" </> "passing"
67 let warning = cwd </> "examples" </> "warning"
67 let warning = cwd </> "examples" </> "warning"
68 let failing = cwd </> "examples" </> "failing"
68 let failing = cwd </> "examples" </> "failing"
69 let supportDir = cwd </> "tests" </> "support" </> "bower_components"
69 let supportDir = cwd </> "tests" </> "support" </> "bower_components"
70− let supportFiles ext = Glob.globDir1 (Glob.compile ("purescript-*/**/*." ++ ext)) supportDir
70+ let supportFiles ext = Glob.globDir1 (Glob.compile ("purescript-*/src/**/*." ++ ext)) supportDir
71 passingFiles <- getTestFiles passing <$> testGlob passing
71 passingFiles <- getTestFiles passing <$> testGlob passing
72 warningFiles <- getTestFiles warning <$> testGlob warning
72 warningFiles <- getTestFiles warning <$> testGlob warning
73 failingFiles <- getTestFiles failing <$> testGlob failing
73 failingFiles <- getTestFiles failing <$> testGlob failing
@@ -77,10 +77,10 @@ spec = do
77 modules <- ExceptT . return $ P.parseModulesFromFiles id supportPursFiles
77 modules <- ExceptT . return $ P.parseModulesFromFiles id supportPursFiles
78 foreigns <- inferForeignModules modules
78 foreigns <- inferForeignModules modules
79 externs <- ExceptT . fmap fst . runTest $ P.make (makeActions foreigns) (map snd modules)
79 externs <- ExceptT . fmap fst . runTest $ P.make (makeActions foreigns) (map snd modules)
80− return (zip (map snd modules) externs)
80+ return (zip (map snd modules) externs, foreigns)
81 case supportExterns of
81 case supportExterns of
82 Left errs -> fail (P.prettyPrintMultipleErrors P.defaultPPEOptions errs)
82 Left errs -> fail (P.prettyPrintMultipleErrors P.defaultPPEOptions errs)
83− Right externs -> return (externs, passingFiles, warningFiles, failingFiles)
83+ Right (externs, foreigns) -> return (externs, foreigns, passingFiles, warningFiles, failingFiles)
85 outputFile <- runIO $ do
85 outputFile <- runIO $ do
86 tmp <- getTemporaryDirectory
86 tmp <- getTemporaryDirectory
@@ -90,21 +90,21 @@ spec = do
90 context "Passing examples" $
90 context "Passing examples" $
91 forM_ passingTestCases $ \testPurs ->
91 forM_ passingTestCases $ \testPurs ->
92 it ("'" <> takeFileName (getTestMain testPurs) <> "' should compile and run without error") $
92 it ("'" <> takeFileName (getTestMain testPurs) <> "' should compile and run without error") $
93− assertCompiles supportExterns testPurs outputFile
93+ assertCompiles supportExterns supportForeigns testPurs outputFile
95 context "Warning examples" $
95 context "Warning examples" $
96 forM_ warningTestCases $ \testPurs -> do
96 forM_ warningTestCases $ \testPurs -> do
97 let mainPath = getTestMain testPurs
97 let mainPath = getTestMain testPurs
98 expectedWarnings <- runIO $ getShouldWarnWith mainPath
98 expectedWarnings <- runIO $ getShouldWarnWith mainPath
99 it ("'" <> takeFileName mainPath <> "' should compile with warning(s) '" <> intercalate "', '" expectedWarnings <> "'") $
99 it ("'" <> takeFileName mainPath <> "' should compile with warning(s) '" <> intercalate "', '" expectedWarnings <> "'") $
100− assertCompilesWithWarnings supportExterns testPurs expectedWarnings
100+ assertCompilesWithWarnings supportExterns supportForeigns testPurs expectedWarnings
102 context "Failing examples" $
102 context "Failing examples" $
103 forM_ failingTestCases $ \testPurs -> do
103 forM_ failingTestCases $ \testPurs -> do
104 let mainPath = getTestMain testPurs
104 let mainPath = getTestMain testPurs
105 expectedFailures <- runIO $ getShouldFailWith mainPath
105 expectedFailures <- runIO $ getShouldFailWith mainPath
106 it ("'" <> takeFileName mainPath <> "' should fail with '" <> intercalate "', '" expectedFailures <> "'") $
106 it ("'" <> takeFileName mainPath <> "' should fail with '" <> intercalate "', '" expectedFailures <> "'") $
107− assertDoesNotCompile supportExterns testPurs expectedFailures
107+ assertDoesNotCompile supportExterns supportForeigns testPurs expectedFailures
@@ -197,27 +197,29 @@ runTest = P.runMake P.defaultOptions
199 :: [(P.Module, P.ExternsFile)]
199 :: [(P.Module, P.ExternsFile)]
200+ -> M.Map P.ModuleName FilePath
200 -> [FilePath]
201 -> [FilePath]
201 -> ([P.Module] -> IO ())
202 -> ([P.Module] -> IO ())
202 -> IO (Either P.MultipleErrors [P.ExternsFile], P.MultipleErrors)
203 -> IO (Either P.MultipleErrors [P.ExternsFile], P.MultipleErrors)
203−compile supportExterns inputFiles check = silence $ runTest $ do
204+compile supportExterns supportForeigns inputFiles check = silence $ runTest $ do
204 fs <- liftIO $ readInput inputFiles
205 fs <- liftIO $ readInput inputFiles
205 ms <- P.parseModulesFromFiles id fs
206 ms <- P.parseModulesFromFiles id fs
206 foreigns <- inferForeignModules ms
207 foreigns <- inferForeignModules ms
207 liftIO (check (map snd ms))
208 liftIO (check (map snd ms))
208− let actions = makeActions foreigns
209+ let actions = makeActions (foreigns `M.union` supportForeigns)
209 case ms of
210 case ms of
210 [singleModule] -> pure <$> P.rebuildModule actions (map snd supportExterns) (snd singleModule)
211 [singleModule] -> pure <$> P.rebuildModule actions (map snd supportExterns) (snd singleModule)
211 _ -> P.make actions (map fst supportExterns ++ map snd ms)
212 _ -> P.make actions (map fst supportExterns ++ map snd ms)
214 :: [(P.Module, P.ExternsFile)]
215 :: [(P.Module, P.ExternsFile)]
216+ -> M.Map P.ModuleName FilePath
215 -> [FilePath]
217 -> [FilePath]
216 -> ([P.Module] -> IO ())
218 -> ([P.Module] -> IO ())
217 -> (Either P.MultipleErrors P.MultipleErrors -> IO (Maybe String))
219 -> (Either P.MultipleErrors P.MultipleErrors -> IO (Maybe String))
218 -> Expectation
220 -> Expectation
219−assert supportExterns inputFiles check f = do
221+assert supportExterns supportForeigns inputFiles check f = do
220− (e, w) <- compile supportExterns inputFiles check
222+ (e, w) <- compile supportExterns supportForeigns inputFiles check
221 maybeErr <- f (const w <$> e)
223 maybeErr <- f (const w <$> e)
222 maybe (return ()) expectationFailure maybeErr
224 maybe (return ()) expectationFailure maybeErr
@@ -235,11 +237,12 @@ checkShouldFailWith expected errs =
236assertCompiles
238assertCompiles
237 :: [(P.Module, P.ExternsFile)]
239 :: [(P.Module, P.ExternsFile)]
240+ -> M.Map P.ModuleName FilePath
238 -> [FilePath]
241 -> [FilePath]
239 -> Handle
242 -> Handle
240 -> Expectation
243 -> Expectation
241−assertCompiles supportExterns inputFiles outputFile =
244+assertCompiles supportExterns supportForeigns inputFiles outputFile =
242− assert supportExterns inputFiles checkMain $ \e ->
245+ assert supportExterns supportForeigns inputFiles checkMain $ \e ->
243 case e of
246 case e of
244 Left errs -> return . Just . P.prettyPrintMultipleErrors P.defaultPPEOptions $ errs
247 Left errs -> return . Just . P.prettyPrintMultipleErrors P.defaultPPEOptions $ errs
245 Right _ -> do
248 Right _ -> do
@@ -260,11 +263,12 @@ assertCompiles supportExterns inputFiles outputFile =
261assertCompilesWithWarnings
264assertCompilesWithWarnings
262 :: [(P.Module, P.ExternsFile)]
265 :: [(P.Module, P.ExternsFile)]
266+ -> M.Map P.ModuleName FilePath
263 -> [FilePath]
267 -> [FilePath]
264 -> [String]
268 -> [String]
265 -> Expectation
269 -> Expectation
266−assertCompilesWithWarnings supportExterns inputFiles shouldWarnWith =
270+assertCompilesWithWarnings supportExterns supportForeigns inputFiles shouldWarnWith =
267− assert supportExterns inputFiles checkMain $ \e ->
271+ assert supportExterns supportForeigns inputFiles checkMain $ \e ->
268 case e of
272 case e of
269 Left errs ->
273 Left errs ->
270 return . Just . P.prettyPrintMultipleErrors P.defaultPPEOptions $ errs
274 return . Just . P.prettyPrintMultipleErrors P.defaultPPEOptions $ errs
@@ -279,11 +283,12 @@ assertCompilesWithWarnings supportExterns inputFiles shouldWarnWith =
280assertDoesNotCompile
284assertDoesNotCompile
281 :: [(P.Module, P.ExternsFile)]
285 :: [(P.Module, P.ExternsFile)]
286+ -> M.Map P.ModuleName FilePath
282 -> [FilePath]
287 -> [FilePath]
283 -> [String]
288 -> [String]
284 -> Expectation
289 -> Expectation
285−assertDoesNotCompile supportExterns inputFiles shouldFailWith =
290+assertDoesNotCompile supportExterns supportForeigns inputFiles shouldFailWith =
286− assert supportExterns inputFiles noPreCheck $ \e ->
291+ assert supportExterns supportForeigns inputFiles noPreCheck $ \e ->
287 case e of
292 case e of
288 Left errs ->
293 Left errs ->
289 return $ if null shouldFailWith
294 return $ if null shouldFailWith