git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Check that passing tests have a Main module
c6d2465Harry Garrood
examples/passing/ExportedInstanceDeclarations.purs+45−44
@@ -1,44 +1,45 @@
1−-- Tests that instances for non-exported classes / types do not appear in the
1+-- Tests that instances for non-exported classes / types do not appear in the
2−-- result of `exportedDeclarations`.
2+-- result of `exportedDeclarations`.
3−module ExportedInstanceDeclarations
3+module Main
4− ( Const(..)
4+ ( Const(..)
5− , class Foo
5+ , class Foo
6− , foo
6+ , foo
7+ , main
7− ) where
8+ ) where
8−
9+
9−import Prelude
10+import Prelude
10−import Control.Monad.Eff.Console (log)
11+import Control.Monad.Eff.Console (log)
11−
12+
12−data Const a b = Const a
13+data Const a b = Const a
13−
14+
14−class Foo a where
15+class Foo a where
15− foo :: a
16+ foo :: a
16−
17+
17−data NonexportedType = NonexportedType
18+data NonexportedType = NonexportedType
18−
19+
19−class NonexportedClass a where
20+class NonexportedClass a where
20− notExported :: a
21+ notExported :: a
21−
22+
22−-- There are three places that a nonexported type or type class can occur,
23+-- There are three places that a nonexported type or type class can occur,
23−-- leading an instance to count as non-exported:
24+-- leading an instance to count as non-exported:
24−-- * Constraints
25+-- * Constraints
25−-- * The type class itself
26+-- * The type class itself
26−-- * The instance types
27+-- * The instance types
27−
28+
28−-- Case 1: constraints
29+-- Case 1: constraints
29−instance nonExportedFoo :: (NonexportedClass a) => Foo a where
30+instance nonExportedFoo :: (NonexportedClass a) => Foo a where
30− foo = notExported
31+ foo = notExported
31−
32+
32−-- Another instance of case 1:
33+-- Another instance of case 1:
33−instance nonExportedFoo2 :: (Foo NonexportedType) => Foo (a -> a) where
34+instance nonExportedFoo2 :: (Foo NonexportedType) => Foo (a -> a) where
34− foo = id
35+ foo = id
35−
36+
36−-- Case 2: type class
37+-- Case 2: type class
37−instance nonExportedNonexportedType :: NonexportedClass (Const Int a) where
38+instance nonExportedNonexportedType :: NonexportedClass (Const Int a) where
38− notExported = Const 0
39+ notExported = Const 0
39−
40+
40−-- Case 3: instance types
41+-- Case 3: instance types
41−instance constFoo :: Foo (Const NonexportedType b) where
42+instance constFoo :: Foo (Const NonexportedType b) where
42− foo = Const NonexportedType
43+ foo = Const NonexportedType
43−
44+
44−main = log "Done"
45+main = log "Done"
tests/TestCompiler.hs+17−8
@@ -176,10 +176,12 @@ compile
176 :: [(P.Module, P.ExternsFile)]
176 :: [(P.Module, P.ExternsFile)]
177 -> [FilePath]
177 -> [FilePath]
178 -> M.Map P.ModuleName FilePath
178 -> M.Map P.ModuleName FilePath
179+ -> ([P.Module] -> IO ())
179 -> IO (Either P.MultipleErrors [P.ExternsFile])
180 -> IO (Either P.MultipleErrors [P.ExternsFile])
180−compile supportExterns inputFiles foreigns = silence $ runTest $ do
181+compile supportExterns inputFiles foreigns check = silence $ runTest $ do
181 fs <- liftIO $ readInput inputFiles
182 fs <- liftIO $ readInput inputFiles
182 ms <- P.parseModulesFromFiles id fs
183 ms <- P.parseModulesFromFiles id fs
184+ liftIO (check (map snd ms))
183 let actions = makeActions foreigns
185 let actions = makeActions foreigns
184 case ms of
186 case ms of
185 [singleModule] -> pure <$> P.rebuildModule actions (map snd supportExterns) (snd singleModule)
187 [singleModule] -> pure <$> P.rebuildModule actions (map snd supportExterns) (snd singleModule)
@@ -189,10 +191,11 @@ assert
189 :: [(P.Module, P.ExternsFile)]
191 :: [(P.Module, P.ExternsFile)]
190 -> [FilePath]
192 -> [FilePath]
191 -> M.Map P.ModuleName FilePath
193 -> M.Map P.ModuleName FilePath
194+ -> ([P.Module] -> IO ())
192 -> (Either P.MultipleErrors [P.ExternsFile] -> IO (Maybe String))
195 -> (Either P.MultipleErrors [P.ExternsFile] -> IO (Maybe String))
193 -> Expectation
196 -> Expectation
194−assert supportExterns inputFiles foreigns f = do
197+assert supportExterns inputFiles foreigns check f = do
195− e <- compile supportExterns inputFiles foreigns
198+ e <- compile supportExterns inputFiles foreigns check
196 maybeErr <- f e
199 maybeErr <- f e
197 maybe (return ()) expectationFailure maybeErr
200 maybe (return ()) expectationFailure maybeErr
198
201
@@ -201,8 +204,8 @@ assertCompiles
201 -> [FilePath]
204 -> [FilePath]
202 -> M.Map P.ModuleName FilePath
205 -> M.Map P.ModuleName FilePath
203 -> Expectation
206 -> Expectation
204−assertCompiles supportExterns inputFiles foreigns = do
207+assertCompiles supportExterns inputFiles foreigns =
205− assert supportExterns inputFiles foreigns $ \e ->
208+ assert supportExterns inputFiles foreigns checkMain $ \e ->
206 case e of
209 case e of
207 Left errs -> return . Just . P.prettyPrintMultipleErrors False $ errs
210 Left errs -> return . Just . P.prettyPrintMultipleErrors False $ errs
208 Right _ -> do
211 Right _ -> do
@@ -217,6 +220,10 @@ assertCompiles supportExterns inputFiles foreigns = do
217 | otherwise -> return $ Just $ "Test did not finish with 'Done':\n\n" <> out
220 | otherwise -> return $ Just $ "Test did not finish with 'Done':\n\n" <> out
218 Just (ExitFailure _, _, err) -> return $ Just err
221 Just (ExitFailure _, _, err) -> return $ Just err
219 Nothing -> return $ Just "Couldn't find node.js executable"
222 Nothing -> return $ Just "Couldn't find node.js executable"
223+ where
224+ checkMain ms =
225+ unless (any ((== P.moduleNameFromString "Main") . P.getModuleName) ms)
226+ (fail "Main module missing")
220
227
221assertDoesNotCompile
228assertDoesNotCompile
222 :: [(P.Module, P.ExternsFile)]
229 :: [(P.Module, P.ExternsFile)]
@@ -224,10 +231,10 @@ assertDoesNotCompile
224 -> M.Map P.ModuleName FilePath
231 -> M.Map P.ModuleName FilePath
225 -> [String]
232 -> [String]
226 -> Expectation
233 -> Expectation
227−assertDoesNotCompile supportExterns inputFiles foreigns shouldFailWith = do
234+assertDoesNotCompile supportExterns inputFiles foreigns shouldFailWith =
228− assert supportExterns inputFiles foreigns $ \e ->
235+ assert supportExterns inputFiles foreigns noPreCheck $ \e ->
229 case e of
236 case e of
230− Left errs -> do
237+ Left errs ->
231 return $ if null shouldFailWith
238 return $ if null shouldFailWith
232 then Just $ "shouldFailWith declaration is missing (errors were: "
239 then Just $ "shouldFailWith declaration is missing (errors were: "
233 ++ show (map P.errorCode (P.runMultipleErrors errs))
240 ++ show (map P.errorCode (P.runMultipleErrors errs))
@@ -237,6 +244,8 @@ assertDoesNotCompile supportExterns inputFiles foreigns shouldFailWith = do
237 return $ Just "Should not have compiled"
244 return $ Just "Should not have compiled"
238
245
239 where
246 where
247+ noPreCheck = const (return ())
248+
240 checkShouldFailWith expected errs =
249 checkShouldFailWith expected errs =
241 let actual = map P.errorCode $ P.runMultipleErrors errs
250 let actual = map P.errorCode $ P.runMultipleErrors errs
242 in if sort expected == sort actual
251 in if sort expected == sort actual