1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-15 01:52:11 +03:00
juvix/test/Scope/Negative.hs

260 lines
6.6 KiB
Haskell
Raw Normal View History

2022-02-15 16:12:53 +03:00
module Scope.Negative (allTests) where
import Base
import Juvix.Pipeline
import Juvix.Syntax.Concrete.Scoped.Error
2022-02-15 16:12:53 +03:00
type FailMsg = String
data NegTest a = NegTest
2022-04-07 19:10:53 +03:00
{ _name :: String,
_relDir :: FilePath,
_file :: FilePath,
_checkErr :: a -> Maybe FailMsg
2022-02-15 16:12:53 +03:00
}
2022-04-07 19:10:53 +03:00
root :: FilePath
root = "tests/negative"
testDescr :: Typeable a => NegTest a -> 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
let entryPoint = defaultEntryPoint _file
res <- runIOEither (upToAbstract entryPoint)
case mapLeft fromJuvixError res of
2022-04-07 19:10:53 +03:00
Left (Just err) -> whenJust (_checkErr err) assertFailure
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) scoperErrorTests
<> map (mkTest . testDescr) filesErrorTests
)
2022-02-16 22:15:14 +03:00
wrongError :: Maybe FailMsg
2022-02-15 16:12:53 +03:00
wrongError = Just "Incorrect error"
scoperErrorTests :: [NegTest ScoperError]
scoperErrorTests =
2022-04-05 20:57:21 +03:00
[ NegTest
"Not in scope"
"."
"NotInScope.juvix"
2022-04-05 20:57:21 +03:00
$ \case
ErrSymNotInScope {} -> Nothing
_ -> wrongError,
NegTest
"Qualified not in scope"
"."
"QualSymNotInScope.juvix"
$ \case
ErrQualSymNotInScope {} -> Nothing
_ -> wrongError,
2022-04-05 20:57:21 +03:00
NegTest
"Multiple declarations"
"."
"MultipleDeclarations.juvix"
2022-04-05 20:57:21 +03:00
$ \case
ErrMultipleDeclarations {} -> Nothing
_ -> wrongError,
NegTest
"Import cycle"
"ImportCycle"
"A.juvix"
2022-04-05 20:57:21 +03:00
$ \case
ErrImportCycle {} -> Nothing
_ -> wrongError,
NegTest
"Binding group conflict (function clause)"
"BindGroupConflict"
"Clause.juvix"
2022-04-05 20:57:21 +03:00
$ \case
ErrBindGroup {} -> Nothing
_ -> wrongError,
NegTest
"Binding group conflict (lambda clause)"
"BindGroupConflict"
"Lambda.juvix"
2022-04-05 20:57:21 +03:00
$ \case
ErrBindGroup {} -> Nothing
_ -> wrongError,
NegTest
"Infix error (expression)"
"."
"InfixError.juvix"
2022-04-05 20:57:21 +03:00
$ \case
ErrInfixParser {} -> Nothing
_ -> wrongError,
NegTest
"Infix error (pattern)"
"."
"InfixErrorP.juvix"
2022-04-05 20:57:21 +03:00
$ \case
ErrInfixPattern {} -> Nothing
_ -> wrongError,
NegTest
"Duplicate fixity declaration"
"."
"DuplicateFixity.juvix"
2022-04-05 20:57:21 +03:00
$ \case
ErrDuplicateFixity {} -> Nothing
_ -> wrongError,
NegTest
"Multiple export conflict"
"."
"MultipleExportConflict.juvix"
2022-04-05 20:57:21 +03:00
$ \case
ErrMultipleExport {} -> Nothing
_ -> wrongError,
NegTest
"Module not in scope"
"."
"ModuleNotInScope.juvix"
2022-04-05 20:57:21 +03:00
$ \case
ErrModuleNotInScope {} -> Nothing
_ -> wrongError,
NegTest
"Unused operator syntax definition"
"."
"UnusedOperatorDef.juvix"
2022-04-05 20:57:21 +03:00
$ \case
ErrUnusedOperatorDef {} -> Nothing
_ -> wrongError,
NegTest
"Ambiguous symbol"
"."
"AmbiguousSymbol.juvix"
2022-04-05 20:57:21 +03:00
$ \case
ErrAmbiguousSym {} -> Nothing
_ -> wrongError,
NegTest
"Lacks function clause"
"."
"LacksFunctionClause.juvix"
2022-04-05 20:57:21 +03:00
$ \case
ErrLacksFunctionClause {} -> Nothing
_ -> wrongError,
NegTest
"Incorrect top module path"
"."
"WrongModuleName.juvix"
2022-04-05 20:57:21 +03:00
$ \case
ErrWrongTopModuleName {} -> Nothing
_ -> wrongError,
NegTest
"Ambiguous export"
"."
"AmbiguousExport.juvix"
2022-04-05 20:57:21 +03:00
$ \case
ErrMultipleExport {} -> Nothing
_ -> wrongError,
NegTest
"Ambiguous nested modules"
"."
"AmbiguousModule.juvix"
2022-04-05 20:57:21 +03:00
$ \case
ErrAmbiguousModuleSym {} -> Nothing
_ -> wrongError,
NegTest
"Ambiguous nested constructors"
"."
"AmbiguousConstructor.juvix"
2022-04-05 20:57:21 +03:00
$ \case
ErrAmbiguousSym {} -> Nothing
_ -> wrongError,
NegTest
"Wrong location of a compile block"
"CompileBlocks"
"WrongLocationCompileBlock.juvix"
$ \case
ErrWrongLocationCompileBlock {} -> Nothing
_ -> wrongError,
NegTest
"Implicit argument on the left of an application"
"."
"AppLeftImplicit.juvix"
$ \case
ErrAppLeftImplicit {} -> Nothing
_ -> wrongError,
NegTest
"Multiple compile blocks for the same name"
"CompileBlocks"
"MultipleCompileBlockSameName.juvix"
$ \case
ErrMultipleCompileBlockSameName {} -> Nothing
_ -> wrongError,
NegTest
"Multiple rules for a backend inside a compile block"
"CompileBlocks"
"MultipleCompileRuleSameBackend.juvix"
$ \case
ErrMultipleCompileRuleSameBackend {} -> Nothing
_ -> wrongError,
NegTest
"issue 230"
"230"
"Prod.juvix"
$ \case
ErrQualSymNotInScope {} -> Nothing
_ -> wrongError,
NegTest
"Double braces in pattern"
"."
"NestedPatternBraces.juvix"
$ \case
ErrDoubleBracesPattern {} -> Nothing
_ -> wrongError,
NegTest
"Pattern matching an implicit argument on the left of an application"
"."
"ImplicitPatternLeftApplication.juvix"
$ \case
ErrImplicitPatternLeftApplication {} -> Nothing
_ -> wrongError,
NegTest
"Constructor expected on the left of a pattern application"
"."
"ConstructorExpectedLeftApplication.juvix"
$ \case
ErrConstructorExpectedLeftApplication {} -> Nothing
_ -> wrongError,
NegTest
"Compile block for a unsupported kind of expression"
"CompileBlocks"
"WrongKindExpressionCompileBlock.juvix"
$ \case
ErrWrongKindExpressionCompileBlock {} -> Nothing
_ -> wrongError,
NegTest
"A type parameter name occurs twice when declaring an inductive type"
"."
"DuplicateInductiveParameterName.juvix"
$ \case
ErrDuplicateInductiveParameterName {} -> Nothing
2022-04-05 20:57:21 +03:00
_ -> wrongError
2022-02-16 22:15:14 +03:00
]
filesErrorTests :: [NegTest FilesError]
filesErrorTests =
[ NegTest
"A module that conflicts with a module in the stdlib"
"StdlibConflict"
"Stdlib/Data/Bool.juvix"
$ \case
FilesError {} -> Nothing,
NegTest
"Importing a module that conflicts with a module in the stdlib"
"StdlibConflict"
"Input.juvix"
$ \case
FilesError {} -> Nothing
]