{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE Safe #-}
module Parser.IntegrationTest (
) where
import Text.Parsec
import Parser.Common
import Parser.DefinedCategory
import Parser.Procedure ()
import Parser.TypeCategory ()
import Types.IntegrationTest
instance ParseFromSource (IntegrationTestHeader SourcePos) where
sourceParser = labeled "testcase" $ do
c <- getPosition
sepAfter kwTestcase
string_ "\""
name <- manyTill stringChar (string_ "\"")
optionalSpace
sepAfter (string_ "{")
result <- resultError <|> resultCrash <|> resultSuccess
sepAfter (string_ "}")
return $ IntegrationTestHeader [c] name result where
resultError = labeled "error expectation" $ do
c <- getPosition
sepAfter (keyword "error")
(req,exc) <- requireOrExclude
return $ ExpectCompileError [c] req exc
resultCrash = labeled "crash expectation" $ do
c <- getPosition
sepAfter (keyword "crash")
e <- labeled "test expression" sourceParser
(req,exc) <- requireOrExclude
return $ ExpectRuntimeError [c] e req exc
resultSuccess = labeled "success expectation" $ do
c <- getPosition
sepAfter (keyword "success")
e <- labeled "test expression" sourceParser
(req,exc) <- requireOrExclude
return $ ExpectRuntimeSuccess [c] e req exc
requireOrExclude = parsed >>= return . foldr merge empty where
empty = ([],[])
merge (cs1,ds1) (cs2,ds2) = (cs1++cs2,ds1++ds2)
parsed = sepBy anyType optionalSpace
anyType = require <|> exclude where
require = do
sepAfter (keyword "require")
s <- outputScope
string_ "\""
r <- fmap concat $ manyTill regexChar (string_ "\"")
optionalSpace
return ([OutputPattern s r],[])
exclude = do
sepAfter (keyword "exclude")
s <- outputScope
string_ "\""
e <- fmap concat $ manyTill regexChar (string_ "\"")
optionalSpace
return ([],[OutputPattern s e])
outputScope = try anyScope <|>
try compilerScope <|>
try stderrScope <|>
try stdoutScope <|>
return OutputAny
anyScope = sepAfter (keyword "any") >> return OutputAny
compilerScope = sepAfter (keyword "compiler") >> return OutputCompiler
stderrScope = sepAfter (keyword "stderr") >> return OutputStderr
stdoutScope = sepAfter (keyword "stdout") >> return OutputStdout
instance ParseFromSource (IntegrationTest SourcePos) where
sourceParser = labeled "integration test" $ do
h <- sourceParser
(cs,ds) <- parseAnySource
return $ IntegrationTest h cs ds