{-# LANGUAGE Safe #-}
module Test.SourceFile (tests) where
import System.FilePath
import Base.CompileError
import Base.CompileInfo
import Parser.SourceFile
import Test.Common
tests :: [IO (CompileInfo ())]
tests :: [IO (CompileInfo ())]
tests = [
String
-> ((String, String)
-> CompileInfo ([Pragma SourcePos], [AnyCategory SourcePos]))
-> IO (CompileInfo ())
forall a.
String
-> ((String, String) -> CompileInfo a) -> IO (CompileInfo ())
checkParseSuccess (String
"testfiles" String -> String -> String
</> String
"public.0rp") (String, String)
-> CompileInfo ([Pragma SourcePos], [AnyCategory SourcePos])
forall (m :: * -> *).
CompileErrorM m =>
(String, String) -> m ([Pragma SourcePos], [AnyCategory SourcePos])
parsePublicSource,
String
-> ((String, String)
-> CompileInfo
([Pragma SourcePos], [AnyCategory SourcePos],
[DefinedCategory SourcePos]))
-> IO (CompileInfo ())
forall a.
String
-> ((String, String) -> CompileInfo a) -> IO (CompileInfo ())
checkParseSuccess (String
"testfiles" String -> String -> String
</> String
"internal.0rx") (String, String)
-> CompileInfo
([Pragma SourcePos], [AnyCategory SourcePos],
[DefinedCategory SourcePos])
forall (m :: * -> *).
CompileErrorM m =>
(String, String)
-> m ([Pragma SourcePos], [AnyCategory SourcePos],
[DefinedCategory SourcePos])
parseInternalSource,
String
-> ((String, String)
-> CompileInfo ([Pragma SourcePos], [IntegrationTest SourcePos]))
-> IO (CompileInfo ())
forall a.
String
-> ((String, String) -> CompileInfo a) -> IO (CompileInfo ())
checkParseSuccess (String
"testfiles" String -> String -> String
</> String
"test.0rt") (String, String)
-> CompileInfo ([Pragma SourcePos], [IntegrationTest SourcePos])
forall (m :: * -> *).
CompileErrorM m =>
(String, String)
-> m ([Pragma SourcePos], [IntegrationTest SourcePos])
parseTestSource
]
checkParseSuccess :: String -> ((FilePath,String) -> CompileInfo a) -> IO (CompileInfo ())
checkParseSuccess :: String
-> ((String, String) -> CompileInfo a) -> IO (CompileInfo ())
checkParseSuccess String
f (String, String) -> CompileInfo a
p = do
String
contents <- String -> IO String
loadFile String
f
let parsed :: CompileInfo a
parsed = (String, String) -> CompileInfo a
p (String
f,String
contents)
CompileInfo () -> IO (CompileInfo ())
forall (m :: * -> *) a. Monad m => a -> m a
return (CompileInfo () -> IO (CompileInfo ()))
-> CompileInfo () -> IO (CompileInfo ())
forall a b. (a -> b) -> a -> b
$ CompileInfo a -> CompileInfo ()
forall (m :: * -> *) a. CompileErrorM m => CompileInfo a -> m ()
check CompileInfo a
parsed
where
check :: CompileInfo a -> m ()
check CompileInfo a
c
| CompileInfo a -> Bool
forall a. CompileInfo a -> Bool
isCompileError CompileInfo a
c = String -> m ()
forall (m :: * -> *) a. CompileErrorM m => String -> m a
compileErrorM (String -> m ()) -> String -> m ()
forall a b. (a -> b) -> a -> b
$ String
"Parse " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
f String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
":\n" String -> String -> String
forall a. [a] -> [a] -> [a]
++ CompileMessage -> String
forall a. Show a => a -> String
show (CompileInfo a -> CompileMessage
forall a. CompileInfo a -> CompileMessage
getCompileError CompileInfo a
c)
| Bool
otherwise = () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()