2022-02-15 16:12:53 +03:00
|
|
|
module Scope.Negative (allTests) where
|
|
|
|
|
|
|
|
import Base
|
2022-04-07 19:10:53 +03:00
|
|
|
import MiniJuvix.Pipeline
|
2022-02-18 15:01:42 +03:00
|
|
|
import MiniJuvix.Syntax.Concrete.Scoped.Error
|
2022-02-15 16:12:53 +03:00
|
|
|
|
|
|
|
type FailMsg = String
|
|
|
|
|
2022-04-05 20:57:21 +03:00
|
|
|
data NegTest = NegTest
|
2022-04-07 19:10:53 +03:00
|
|
|
{ _name :: String,
|
|
|
|
_relDir :: FilePath,
|
|
|
|
_file :: FilePath,
|
2022-05-26 18:52:08 +03:00
|
|
|
_checkErr :: ScoperError -> Maybe FailMsg
|
2022-02-15 16:12:53 +03:00
|
|
|
}
|
|
|
|
|
2022-04-07 19:10:53 +03:00
|
|
|
root :: FilePath
|
|
|
|
root = "tests/negative"
|
|
|
|
|
2022-02-18 15:01:42 +03:00
|
|
|
testDescr :: NegTest -> TestDescr
|
2022-04-05 20:57:21 +03:00
|
|
|
testDescr NegTest {..} =
|
2022-04-07 19:10:53 +03:00
|
|
|
let tRoot = root </> _relDir
|
|
|
|
in TestDescr
|
|
|
|
{ _testName = _name,
|
|
|
|
_testRoot = tRoot,
|
|
|
|
_testAssertion = Single $ do
|
2022-05-30 14:40:52 +03:00
|
|
|
let entryPoint = defaultEntryPoint _file
|
2022-06-14 09:56:48 +03:00
|
|
|
res <- runIOEither (upToAbstract entryPoint)
|
2022-05-26 18:52:08 +03:00
|
|
|
case mapLeft fromMiniJuvixError res of
|
2022-04-07 19:10:53 +03:00
|
|
|
Left (Just err) -> whenJust (_checkErr err) assertFailure
|
2022-05-06 12:48:07 +03:00
|
|
|
Left Nothing -> assertFailure "The scope checker did not find an error."
|
|
|
|
Right _ -> assertFailure "An error ocurred but it was not in the scoper."
|
2022-04-07 19:10:53 +03:00
|
|
|
}
|
2022-02-15 16:12:53 +03:00
|
|
|
|
2022-02-18 15:01:42 +03:00
|
|
|
allTests :: TestTree
|
2022-04-05 20:57:21 +03:00
|
|
|
allTests =
|
|
|
|
testGroup
|
|
|
|
"Scope negative tests"
|
|
|
|
(map (mkTest . testDescr) tests)
|
2022-02-16 22:15:14 +03:00
|
|
|
|
2022-02-16 17:18:08 +03:00
|
|
|
wrongError :: Maybe FailMsg
|
2022-02-15 16:12:53 +03:00
|
|
|
wrongError = Just "Incorrect error"
|
|
|
|
|
|
|
|
tests :: [NegTest]
|
2022-04-05 20:57:21 +03:00
|
|
|
tests =
|
|
|
|
[ NegTest
|
|
|
|
"Not in scope"
|
|
|
|
"."
|
|
|
|
"NotInScope.mjuvix"
|
|
|
|
$ \case
|
|
|
|
ErrSymNotInScope {} -> Nothing
|
|
|
|
_ -> wrongError,
|
2022-05-18 18:10:10 +03:00
|
|
|
NegTest
|
|
|
|
"Qualified not in scope"
|
|
|
|
"."
|
|
|
|
"QualSymNotInScope.mjuvix"
|
|
|
|
$ \case
|
|
|
|
ErrQualSymNotInScope {} -> Nothing
|
|
|
|
_ -> wrongError,
|
2022-04-05 20:57:21 +03:00
|
|
|
NegTest
|
|
|
|
"Multiple declarations"
|
|
|
|
"."
|
|
|
|
"MultipleDeclarations.mjuvix"
|
|
|
|
$ \case
|
|
|
|
ErrMultipleDeclarations {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Import cycle"
|
|
|
|
"ImportCycle"
|
|
|
|
"A.mjuvix"
|
|
|
|
$ \case
|
|
|
|
ErrImportCycle {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Binding group conflict (function clause)"
|
|
|
|
"BindGroupConflict"
|
|
|
|
"Clause.mjuvix"
|
|
|
|
$ \case
|
|
|
|
ErrBindGroup {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Binding group conflict (lambda clause)"
|
|
|
|
"BindGroupConflict"
|
|
|
|
"Lambda.mjuvix"
|
|
|
|
$ \case
|
|
|
|
ErrBindGroup {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Infix error (expression)"
|
|
|
|
"."
|
|
|
|
"InfixError.mjuvix"
|
|
|
|
$ \case
|
|
|
|
ErrInfixParser {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Infix error (pattern)"
|
|
|
|
"."
|
|
|
|
"InfixErrorP.mjuvix"
|
|
|
|
$ \case
|
|
|
|
ErrInfixPattern {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Duplicate fixity declaration"
|
|
|
|
"."
|
|
|
|
"DuplicateFixity.mjuvix"
|
|
|
|
$ \case
|
|
|
|
ErrDuplicateFixity {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Multiple export conflict"
|
|
|
|
"."
|
|
|
|
"MultipleExportConflict.mjuvix"
|
|
|
|
$ \case
|
|
|
|
ErrMultipleExport {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Module not in scope"
|
|
|
|
"."
|
|
|
|
"ModuleNotInScope.mjuvix"
|
|
|
|
$ \case
|
|
|
|
ErrModuleNotInScope {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Unused operator syntax definition"
|
|
|
|
"."
|
|
|
|
"UnusedOperatorDef.mjuvix"
|
|
|
|
$ \case
|
|
|
|
ErrUnusedOperatorDef {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Ambiguous symbol"
|
|
|
|
"."
|
|
|
|
"AmbiguousSymbol.mjuvix"
|
|
|
|
$ \case
|
|
|
|
ErrAmbiguousSym {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Lacks function clause"
|
|
|
|
"."
|
|
|
|
"LacksFunctionClause.mjuvix"
|
|
|
|
$ \case
|
|
|
|
ErrLacksFunctionClause {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Incorrect top module path"
|
|
|
|
"."
|
|
|
|
"WrongModuleName.mjuvix"
|
|
|
|
$ \case
|
|
|
|
ErrWrongTopModuleName {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Ambiguous export"
|
|
|
|
"."
|
|
|
|
"AmbiguousExport.mjuvix"
|
|
|
|
$ \case
|
|
|
|
ErrMultipleExport {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Ambiguous nested modules"
|
|
|
|
"."
|
|
|
|
"AmbiguousModule.mjuvix"
|
|
|
|
$ \case
|
|
|
|
ErrAmbiguousModuleSym {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Ambiguous nested constructors"
|
|
|
|
"."
|
|
|
|
"AmbiguousConstructor.mjuvix"
|
|
|
|
$ \case
|
|
|
|
ErrAmbiguousSym {} -> Nothing
|
2022-04-28 18:42:15 +03:00
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Wrong location of a compile block"
|
|
|
|
"CompileBlocks"
|
|
|
|
"WrongLocationCompileBlock.mjuvix"
|
|
|
|
$ \case
|
|
|
|
ErrWrongLocationCompileBlock {} -> Nothing
|
|
|
|
_ -> wrongError,
|
2022-06-14 09:56:48 +03:00
|
|
|
NegTest
|
|
|
|
"Implicit argument on the left of an application"
|
|
|
|
"."
|
|
|
|
"AppLeftImplicit.mjuvix"
|
|
|
|
$ \case
|
|
|
|
ErrAppLeftImplicit {} -> Nothing
|
|
|
|
_ -> wrongError,
|
2022-04-28 18:42:15 +03:00
|
|
|
NegTest
|
|
|
|
"Multiple compile blocks for the same name"
|
|
|
|
"CompileBlocks"
|
|
|
|
"MultipleCompileBlockSameName.mjuvix"
|
|
|
|
$ \case
|
|
|
|
ErrMultipleCompileBlockSameName {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Multiple rules for a backend inside a compile block"
|
|
|
|
"CompileBlocks"
|
|
|
|
"MultipleCompileRuleSameBackend.mjuvix"
|
|
|
|
$ \case
|
|
|
|
ErrMultipleCompileRuleSameBackend {} -> Nothing
|
|
|
|
_ -> wrongError,
|
2022-07-04 17:40:10 +03:00
|
|
|
NegTest
|
|
|
|
"issue 230"
|
|
|
|
"230"
|
|
|
|
"Prod.mjuvix"
|
|
|
|
$ \case
|
|
|
|
ErrQualSymNotInScope {} -> Nothing
|
|
|
|
_ -> wrongError,
|
2022-04-28 18:42:15 +03:00
|
|
|
NegTest
|
|
|
|
"Compile block for a unsupported kind of expression"
|
|
|
|
"CompileBlocks"
|
|
|
|
"WrongKindExpressionCompileBlock.mjuvix"
|
|
|
|
$ \case
|
|
|
|
ErrWrongKindExpressionCompileBlock {} -> Nothing
|
2022-04-05 20:57:21 +03:00
|
|
|
_ -> wrongError
|
2022-02-16 22:15:14 +03:00
|
|
|
]
|