2022-09-07 14:59:41 +03:00
|
|
|
module Parsing.Negative where
|
|
|
|
|
|
|
|
import Base
|
|
|
|
import Juvix.Parser.Error
|
|
|
|
|
2022-12-20 15:05:40 +03:00
|
|
|
root :: Path Abs Dir
|
|
|
|
root = relToProject $(mkRelDir "tests/negative")
|
2022-09-07 14:59:41 +03:00
|
|
|
|
2023-01-27 15:24:28 +03:00
|
|
|
type FailMsg = String
|
|
|
|
|
2022-09-07 14:59:41 +03:00
|
|
|
data NegTest = NegTest
|
|
|
|
{ _name :: String,
|
2023-01-27 15:24:28 +03:00
|
|
|
_dir :: Path Abs Dir,
|
|
|
|
_file :: Path Abs File,
|
|
|
|
_checkErr :: ParserError -> Maybe FailMsg
|
2022-09-07 14:59:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
testDescr :: NegTest -> TestDescr
|
|
|
|
testDescr NegTest {..} =
|
2023-01-27 15:24:28 +03:00
|
|
|
let tRoot = _dir
|
2022-09-07 14:59:41 +03:00
|
|
|
in TestDescr
|
|
|
|
{ _testName = _name,
|
|
|
|
_testRoot = tRoot,
|
|
|
|
_testAssertion = Single $ do
|
2023-12-06 20:24:59 +03:00
|
|
|
entryPoint <- testDefaultEntryPointIO tRoot _file
|
2023-12-30 22:15:35 +03:00
|
|
|
res <- testRunIOEither entryPoint upToParsedSource
|
2022-09-07 14:59:41 +03:00
|
|
|
case mapLeft fromJuvixError res of
|
2023-01-27 15:24:28 +03:00
|
|
|
Left (Just parErr) -> whenJust (_checkErr parErr) assertFailure
|
2024-01-08 15:27:18 +03:00
|
|
|
Left Nothing -> assertFailure "An error occurred but it was not in the parser."
|
2023-01-27 15:24:28 +03:00
|
|
|
Right _ -> assertFailure "The parser did not find an error."
|
2022-09-07 14:59:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
allTests :: TestTree
|
|
|
|
allTests =
|
|
|
|
testGroup
|
|
|
|
"Parsing negative tests"
|
2023-01-27 15:24:28 +03:00
|
|
|
( map (mkTest . testDescr) (parserErrorTests <> filesErrorTests)
|
2022-09-07 14:59:41 +03:00
|
|
|
)
|
|
|
|
|
2023-01-27 15:24:28 +03:00
|
|
|
wrongError :: Maybe FailMsg
|
|
|
|
wrongError = Just "Incorrect error"
|
|
|
|
|
|
|
|
negTest :: String -> Path Rel Dir -> Path Rel File -> (ParserError -> Maybe FailMsg) -> NegTest
|
2023-11-17 18:10:38 +03:00
|
|
|
negTest _name d f _checkErr = negTestAbsDir _name (root <//> d) f _checkErr
|
|
|
|
|
|
|
|
negTestAbsDir :: String -> Path Abs Dir -> Path Rel File -> (ParserError -> Maybe FailMsg) -> NegTest
|
|
|
|
negTestAbsDir _name _dir f _checkErr =
|
|
|
|
NegTest
|
|
|
|
{ _file = _dir <//> f,
|
|
|
|
_dir,
|
|
|
|
_name,
|
|
|
|
_checkErr
|
|
|
|
}
|
2023-01-27 15:24:28 +03:00
|
|
|
|
|
|
|
parserErrorTests :: [NegTest]
|
|
|
|
parserErrorTests =
|
|
|
|
[ negTest
|
2022-09-07 14:59:41 +03:00
|
|
|
"Tab character"
|
2022-12-20 15:05:40 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "Tab.juvix")
|
2023-04-26 16:26:13 +03:00
|
|
|
$ \case
|
|
|
|
ErrMegaparsec {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
negTest
|
|
|
|
"Pragmas YAML error"
|
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "PragmasYAML.juvix")
|
|
|
|
$ \case
|
|
|
|
ErrMegaparsec {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
negTest
|
|
|
|
"Pragmas format error"
|
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "PragmasFormat.juvix")
|
2023-08-11 11:22:22 +03:00
|
|
|
$ \case
|
|
|
|
ErrMegaparsec {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
negTest
|
|
|
|
"Pragmas duplicate keys error"
|
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "PragmasDuplicateKeys.juvix")
|
2023-09-21 12:34:28 +03:00
|
|
|
$ \case
|
|
|
|
ErrMegaparsec {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
negTest
|
|
|
|
"Error on local instances"
|
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "ErrorOnLocalInstances.juvix")
|
2023-01-27 15:24:28 +03:00
|
|
|
$ \case
|
|
|
|
ErrMegaparsec {} -> Nothing
|
|
|
|
_ -> wrongError
|
|
|
|
]
|
|
|
|
|
|
|
|
filesErrorTests :: [NegTest]
|
|
|
|
filesErrorTests =
|
|
|
|
[ negTest
|
|
|
|
"Incorrect top module path"
|
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "WrongModuleName.juvix")
|
|
|
|
$ \case
|
|
|
|
ErrWrongTopModuleName {} -> Nothing
|
2023-04-22 20:15:38 +03:00
|
|
|
_ -> wrongError,
|
2023-11-17 18:10:38 +03:00
|
|
|
negTestAbsDir
|
|
|
|
"Incorrect top module path of an orphan file."
|
|
|
|
(relToProject $(mkRelDir "tests/WithoutPackageFile"))
|
|
|
|
$(mkRelFile "NoGood.juvix")
|
|
|
|
$ \case
|
|
|
|
ErrWrongTopModuleNameOrphan {} -> Nothing
|
|
|
|
_ -> wrongError,
|
2023-05-16 16:39:43 +03:00
|
|
|
negTest
|
|
|
|
"Dangling Judoc comment"
|
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "DanglingJudoc.juvix")
|
|
|
|
$ \case
|
|
|
|
ErrDanglingJudoc
|
|
|
|
DanglingJudoc {} -> Nothing
|
2023-01-27 15:24:28 +03:00
|
|
|
_ -> wrongError
|
2022-09-07 14:59:41 +03:00
|
|
|
]
|